sighandler.c 1.23 KB
Newer Older
Jack Moffitt's avatar
Jack Moffitt committed
1 2 3 4 5 6 7 8 9 10 11 12
#include <signal.h>

#include "thread.h"
#include "avl.h"
#include "log.h"
#include "httpp.h"

#include "global.h"
#include "connection.h"
#include "refbuf.h"
#include "client.h"
#include "logging.h"
Michael Smith's avatar
Michael Smith committed
13
#include "event.h"
Jack Moffitt's avatar
Jack Moffitt committed
14 15 16 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

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

#ifndef _WIN32

void _sig_hup(int signo)
{
Michael Smith's avatar
Michael Smith committed
38 39 40 41 42
    /* We do this elsewhere because it's a bad idea to hang around for too
     * long re-reading an entire config file inside a signal handler. Bad
     * practice.
     */

43
    INFO1("Caught signal %d, scheduling config reread ...", 
Michael Smith's avatar
Michael Smith committed
44
            signo);
Jack Moffitt's avatar
Jack Moffitt committed
45

46
    /* reread config file */
Jack Moffitt's avatar
Jack Moffitt committed
47

Michael Smith's avatar
Michael Smith committed
48 49
    connection_inject_event(EVENT_CONFIG_READ, NULL);
    
50
    /* reopen logfiles (TODO: We don't do this currently) */
Jack Moffitt's avatar
Jack Moffitt committed
51

52 53
    /* some OSes require us to reattach the signal handler */
    signal(SIGHUP, _sig_hup);
Jack Moffitt's avatar
Jack Moffitt committed
54 55 56 57
}

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

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

#endif