-struct {
- int signal;
- void (*handler)(int, siginfo_t *, void *);
-} sighandlers[] = {
- { SIGHUP, sighup_handler },
- { SIGTERM, sigterm_handler },
- { SIGQUIT, sigquit_handler },
- { SIGSEGV, sigsegv_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 = SA_SIGINFO;
-
- /* Set a default signal handler for every signal, errors will be
- ignored. */
- for(i = 0; i < NSIG; i++)
- {
- if(!do_detach)
- act.sa_sigaction = (void(*)(int, siginfo_t *, void *))SIG_DFL;
- else
- act.sa_sigaction = unexpected_signal_handler;
- sigaction(i, &act, NULL);
- }
-
- /* If we didn't detach, allow coredumps */
- if(!do_detach)
- sighandlers[3].handler = (void(*)(int, siginfo_t *, void *))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_sigaction = 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));
- }
-}