Ensure all signals keep working after a SIGINT restart.
After setting up signal handlers, unmask the signals we care about (installed handlers for). When handling SIGINT, the kernel adds SIGHUP and SIGINT to the signal mask (as requested in sigaction()); if execve() is called from the signal handler, this change is persistent.
This commit is contained in:
parent
2220472610
commit
f890420014
1 changed files with 10 additions and 0 deletions
|
@ -114,8 +114,10 @@ sigint_handler(int sig)
|
|||
void
|
||||
setup_signals()
|
||||
{
|
||||
sigset_t sigs;
|
||||
struct sigaction act;
|
||||
|
||||
sigemptyset(&sigs);
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
@ -136,30 +138,38 @@ setup_signals()
|
|||
|
||||
act.sa_handler = dummy_handler;
|
||||
sigaction(SIGALRM, &act, 0);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
|
||||
act.sa_handler = sighup_handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGHUP);
|
||||
sigaction(SIGHUP, &act, 0);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
|
||||
act.sa_handler = sigint_handler;
|
||||
sigaddset(&act.sa_mask, SIGINT);
|
||||
sigaction(SIGINT, &act, 0);
|
||||
sigaddset(&sigs, SIGINT);
|
||||
|
||||
act.sa_handler = sigterm_handler;
|
||||
sigaddset(&act.sa_mask, SIGTERM);
|
||||
sigaction(SIGTERM, &act, 0);
|
||||
sigaddset(&sigs, SIGTERM);
|
||||
|
||||
act.sa_handler = sigusr1_handler;
|
||||
sigaddset(&act.sa_mask, SIGUSR1);
|
||||
sigaction(SIGUSR1, &act, 0);
|
||||
sigaddset(&sigs, SIGUSR1);
|
||||
|
||||
act.sa_handler = sigusr2_handler;
|
||||
sigaddset(&act.sa_mask, SIGUSR2);
|
||||
sigaction(SIGUSR2, &act, 0);
|
||||
sigaddset(&sigs, SIGUSR2);
|
||||
|
||||
act.sa_handler = sigchld_handler;
|
||||
sigaddset(&act.sa_mask, SIGCHLD);
|
||||
sigaction(SIGCHLD, &act, 0);
|
||||
sigaddset(&sigs, SIGCHLD);
|
||||
|
||||
sigprocmask(SIG_UNBLOCK, &sigs, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue