signalHandling.c 706 Bytes
#include <signal.h>     /* for signal() and signal names */

#include "include/monitor.h"

volatile int doShutdown;

void terminate(int signum)
{
    signal(signum, SIG_IGN);
    syslogMonitor(LOG_INFO, MON_CRITICAL, "signals",
                  "caugth deadly signal %d", signum);
    syslogMonitor(LOG_INFO, MON_FAILURE, "signals",
                  "caugth deadly signal %d - service terminated", signum);
    doShutdown = 1;
}

void init_signals(void)
{
    signal(SIGTERM, terminate);
    signal(SIGHUP, SIG_IGN);
    signal(SIGINT, terminate);
    signal(SIGQUIT, terminate);
    signal(SIGABRT, terminate);
    signal(SIGALRM, SIG_IGN);
    signal(SIGURG, SIG_IGN);

    signal(SIGPIPE, SIG_IGN);
}