sighandler.c 964 Bytes
Newer Older
1 2 3 4
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

Jack Moffitt's avatar
Jack Moffitt committed
5 6
#include <signal.h>

Karl Heyes's avatar
Karl Heyes committed
7 8 9
#include "thread/thread.h"
#include "avl/avl.h"
#include "httpp/httpp.h"
Jack Moffitt's avatar
Jack Moffitt committed
10 11 12 13 14 15

#include "global.h"
#include "connection.h"
#include "refbuf.h"
#include "client.h"
#include "logging.h"
16
#include "event.h"
Jack Moffitt's avatar
Jack Moffitt committed
17 18 19 20 21 22 23 24 25 26

#include "sighandler.h"

#define CATMODULE "sighandler"

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

27 28
int schedule_config_reread = 0;

Jack Moffitt's avatar
Jack Moffitt committed
29 30 31
void sighandler_initialize(void)
{
#ifndef _WIN32
32 33 34 35
    signal(SIGHUP, _sig_hup);
    signal(SIGINT, _sig_die);
    signal(SIGTERM, _sig_die);
    signal(SIGPIPE, SIG_IGN);
Jack Moffitt's avatar
Jack Moffitt committed
36 37 38 39 40 41 42
#endif
}

#ifndef _WIN32

void _sig_hup(int signo)
{
43
    schedule_config_reread = 1;
44 45
    /* some OSes require us to reattach the signal handler */
    signal(SIGHUP, _sig_hup);
Jack Moffitt's avatar
Jack Moffitt committed
46 47 48 49
}

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

52 53
    /* inform the server to start shutting down */
    global.running = ICE_HALTING;
Jack Moffitt's avatar
Jack Moffitt committed
54 55 56
}

#endif