sighandler.c 1.65 KB
Newer Older
1 2 3 4 5
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
6
 * Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
7 8 9 10
 *                      Michael Smith <msmith@xiph.org>,
 *                      oddsock <oddsock@xiph.org>,
 *                      Karl Heyes <karl@xiph.org>
 *                      and others (see AUTHORS for details).
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>

20 21 22
#include "common/thread/thread.h"
#include "common/avl/avl.h"
#include "common/httpp/httpp.h"
Jack Moffitt's avatar
Jack Moffitt committed
23 24 25 26 27 28 29 30 31 32 33 34

#include "global.h"
#include "connection.h"
#include "refbuf.h"
#include "client.h"
#include "logging.h"

#define CATMODULE "sighandler"

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

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

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

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

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

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

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

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

#endif