#include "subnet.h"
#include "xalloc.h"
-bool do_purge = false;
volatile bool running = false;
time_t now = 0;
{
}
-void sighup_handler(int signal, short events, void *data) {
+static void sigterm_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ running = false;
+ event_loopexit(NULL);
+}
+
+static void sigint_handler(int signal, short events, void *data) {
+ static int saved_debug_level = -1;
+
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+
+ if(saved_debug_level != -1) {
+ logger(LOG_NOTICE, _("Reverting to old debug level (%d)"),
+ saved_debug_level);
+ debug_level = saved_debug_level;
+ saved_debug_level = -1;
+ } else {
+ logger(LOG_NOTICE,
+ _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
+ debug_level);
+ saved_debug_level = debug_level;
+ debug_level = 5;
+ }
+}
+
+static void sigusr1_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ dump_connections();
+}
+
+static void sigusr2_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ dump_device_stats();
+ dump_nodes();
+ dump_edges();
+ dump_subnets();
+}
+
+static void sigwinch_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ purge();
+}
+
+static void sighup_handler(int signal, short events, void *data) {
connection_t *c;
avl_node_t *node;
char *fname;
struct stat s;
static time_t last_config_check = 0;
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+
/* Reread our own configuration file */
exit_configuration(&config_tree);
time_t last_ping_check;
struct event timeout;
struct event sighup_event;
+ struct event sigint_event;
+ struct event sigterm_event;
+ struct event sigquit_event;
+ struct event sigusr1_event;
+ struct event sigusr2_event;
+ struct event sigwinch_event;
cp();
signal_set(&sighup_event, SIGHUP, sighup_handler, NULL);
signal_add(&sighup_event, NULL);
+ signal_set(&sigint_event, SIGINT, sigint_handler, NULL);
+ signal_add(&sigint_event, NULL);
+ signal_set(&sigterm_event, SIGTERM, sigterm_handler, NULL);
+ signal_add(&sigterm_event, NULL);
+ signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL);
+ signal_add(&sigquit_event, NULL);
+ signal_set(&sigusr1_event, SIGUSR1, sigusr1_handler, NULL);
+ signal_add(&sigusr1_event, NULL);
+ signal_set(&sigusr2_event, SIGUSR2, sigusr2_handler, NULL);
+ signal_add(&sigusr2_event, NULL);
+ signal_set(&sigwinch_event, SIGWINCH, sigwinch_handler, NULL);
+ signal_add(&sigwinch_event, NULL);
last_ping_check = now;
/* XXX: more libevent transition */
timeout_del(&timeout);
- if(do_purge) {
- purge();
- do_purge = false;
- }
-
/* Let's check if everybody is still alive */
if(last_ping_check + pingtimeout < now) {
}
signal_del(&sighup_event);
+ signal_del(&sigint_event);
+ signal_del(&sigterm_event);
+ signal_del(&sigquit_event);
+ signal_del(&sigusr1_event);
+ signal_del(&sigusr2_event);
+ signal_del(&sigwinch_event);
return 0;
}
*/
#ifndef HAVE_MINGW
-static RETSIGTYPE sigterm_handler(int a)
-{
- logger(LOG_NOTICE, _("Got %s signal"), "TERM");
- if(running)
- running = false;
- else
- exit(1);
-}
-
-static RETSIGTYPE sigquit_handler(int a)
-{
- logger(LOG_NOTICE, _("Got %s signal"), "QUIT");
- if(running)
- running = false;
- else
- exit(1);
-}
-
static RETSIGTYPE fatal_signal_square(int a)
{
logger(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
}
}
-static RETSIGTYPE sigint_handler(int a)
-{
- logger(LOG_NOTICE, _("Got %s signal"), "INT");
-
- if(saved_debug_level != -1) {
- logger(LOG_NOTICE, _("Reverting to old debug level (%d)"),
- saved_debug_level);
- debug_level = saved_debug_level;
- saved_debug_level = -1;
- } else {
- logger(LOG_NOTICE,
- _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
- debug_level);
- saved_debug_level = debug_level;
- debug_level = 5;
- }
-}
-
-static RETSIGTYPE sigalrm_handler(int a)
-{
- logger(LOG_NOTICE, _("Got %s signal"), "ALRM");
- sigalrm = true;
-}
-
-static RETSIGTYPE sigusr1_handler(int a)
-{
- dump_connections();
-}
-
-static RETSIGTYPE sigusr2_handler(int a)
-{
- dump_device_stats();
- dump_nodes();
- dump_edges();
- dump_subnets();
-}
-
-static RETSIGTYPE sigwinch_handler(int a)
-{
- do_purge = true;
-}
-
static RETSIGTYPE unexpected_signal_handler(int a)
{
logger(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
int signal;
void (*handler)(int);
} sighandlers[] = {
- {SIGTERM, sigterm_handler},
- {SIGQUIT, sigquit_handler},
{SIGSEGV, fatal_signal_handler},
{SIGBUS, fatal_signal_handler},
{SIGILL, fatal_signal_handler},
{SIGPIPE, ignore_signal_handler},
- {SIGINT, sigint_handler},
- {SIGUSR1, sigusr1_handler},
- {SIGUSR2, sigusr2_handler},
{SIGCHLD, ignore_signal_handler},
- {SIGALRM, sigalrm_handler},
- {SIGWINCH, sigwinch_handler},
{0, NULL}
};
#endif
/* If we didn't detach, allow coredumps */
if(!do_detach)
- sighandlers[2].handler = SIG_DFL;
+ sighandlers[0].handler = SIG_DFL;
/* Then, for each known signal that we want to catch, assign a
handler to the signal, with error checking this time. */