- logger(DEBUG_ALWAYS, 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;
- }
-}
-
-RETSIGTYPE sigalrm_handler(int a)
-{
- logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got ALRM signal"));
- sigalrm = 1;
-}
-
-RETSIGTYPE sigusr1_handler(int a)
-{
- dump_connections();
-}
-
-RETSIGTYPE sigusr2_handler(int a)
-{
- dump_device_stats();
- dump_nodes();
- dump_edges();
- dump_subnets();
-}
-
-RETSIGTYPE sigwinch_handler(int a)
-{
- extern int do_purge;
- do_purge = 1;
-}
-
-RETSIGTYPE unexpected_signal_handler(int a)
-{
- logger(DEBUG_ALWAYS, LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
- cp_trace();
-}
-
-RETSIGTYPE ignore_signal_handler(int a)
-{
- logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
-}
-
-struct {
- int signal;
- void (*handler)(int);
-} sighandlers[] = {
- {
- SIGHUP, sighup_handler}, {
- 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}
-};
-
-void setup_signals(void)
-{
- int i;
- struct sigaction act;
-
- sigemptyset(&emptysigset);
- act.sa_handler = NULL;
- act.sa_mask = emptysigset;
- act.sa_flags = 0;
-
- /* Set a default signal handler for every signal, errors will be
- ignored. */
- for(i = 0; i < NSIG; i++) {
- if(!do_detach)
- act.sa_handler = SIG_DFL;
- else
- act.sa_handler = unexpected_signal_handler;
- sigaction(i, &act, NULL);
- }
-
- /* If we didn't detach, allow coredumps */
- if(!do_detach)
- sighandlers[3].handler = SIG_DFL;
-
- /* Then, for each known signal that we want to catch, assign a
- handler to the signal, with error checking this time. */
- for(i = 0; sighandlers[i].signal; i++) {
- act.sa_handler = sighandlers[i].handler;
- if(sigaction(sighandlers[i].signal, &act, NULL) < 0)
- fprintf(stderr, _("Installing signal handler for signal %d (%s) failed: %s\n"),
- sighandlers[i].signal, strsignal(sighandlers[i].signal),
- strerror(errno));