sighandler.c 1.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/* 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).
 */

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

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

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

#include "global.h"
#include "connection.h"
#include "refbuf.h"
#include "client.h"
#include "logging.h"
28
#include "event.h"
Jack Moffitt's avatar
Jack Moffitt committed
29 30 31 32 33 34 35 36 37 38 39

#define CATMODULE "sighandler"

#ifndef _WIN32
void _sig_hup(int signo);
void _sig_die(int signo);
#endif

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

#ifndef _WIN32

void _sig_hup(int signo)
{
52
    global . schedule_config_reread = 1;
53 54
    /* some OSes require us to reattach the signal handler */
    signal(SIGHUP, _sig_hup);
Jack Moffitt's avatar
Jack Moffitt committed
55 56 57 58
}

void _sig_die(int signo)
{
59
    INFO1("Caught signal %d, shutting down...", signo);
Jack Moffitt's avatar
Jack Moffitt committed
60

61 62
    /* inform the server to start shutting down */
    global.running = ICE_HALTING;
Jack Moffitt's avatar
Jack Moffitt committed
63 64 65
}

#endif