sighandler.c 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2004, Jack Moffitt <jack@xiph.org, 
 *                      Michael Smith <msmith@xiph.org>,
 *                      oddsock <oddsock@xiph.org>,
 *                      Karl Heyes <karl@xiph.org>
 *                      and others (see AUTHORS for details).
Philipp Schafft's avatar
Philipp Schafft committed
11
 * Copyright 2011-2012, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
12 13
 */

14 15 16 17
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

Jack Moffitt's avatar
Jack Moffitt committed
18 19
#include <signal.h>

Karl Heyes's avatar
Karl Heyes committed
20 21 22
#include "thread/thread.h"
#include "avl/avl.h"
#include "httpp/httpp.h"
Jack Moffitt's avatar
Jack Moffitt committed
23 24 25 26 27 28

#include "global.h"
#include "connection.h"
#include "refbuf.h"
#include "client.h"
#include "logging.h"
Michael Smith's avatar
Michael Smith committed
29
#include "event.h"
Jack Moffitt's avatar
Jack Moffitt committed
30 31 32 33 34 35

#define CATMODULE "sighandler"

#ifndef _WIN32
void _sig_hup(int signo);
void _sig_die(int signo);
36
void _sig_ignore(int signo);
Jack Moffitt's avatar
Jack Moffitt committed
37 38 39 40 41
#endif

void sighandler_initialize(void)
{
#ifndef _WIN32
42 43 44 45
    signal(SIGHUP, _sig_hup);
    signal(SIGINT, _sig_die);
    signal(SIGTERM, _sig_die);
    signal(SIGPIPE, SIG_IGN);
46
    signal(SIGCHLD, _sig_ignore);
Jack Moffitt's avatar
Jack Moffitt committed
47 48 49 50
#endif
}

#ifndef _WIN32
51 52 53 54
void _sig_ignore(int signo)
{
    signal(signo, _sig_ignore);
}
Jack Moffitt's avatar
Jack Moffitt committed
55 56 57

void _sig_hup(int signo)
{
58
    LOG_INFO("Caught signal %d, scheduling config re-read...", signo);
59

60
    global_lock();
61
    global . schedule_config_reread = 1;
62 63
    global_unlock();

64 65
    /* some OSes require us to reattach the signal handler */
    signal(SIGHUP, _sig_hup);
Jack Moffitt's avatar
Jack Moffitt committed
66 67 68 69
}

void _sig_die(int signo)
{
70
    LOG_INFO("Caught signal %d, shutting down...", signo);
Jack Moffitt's avatar
Jack Moffitt committed
71

72 73
    /* inform the server to start shutting down */
    global.running = ICE_HALTING;
Jack Moffitt's avatar
Jack Moffitt committed
74 75 76
}

#endif