1 /* -*- c-basic-offset: 8; -*- */
5 static volatile sig_atomic_t sigflag
;
6 /* set nonzero by signal handler */
7 static sigset_t newmask
, oldmask
, zeromask
;
10 sig_usr(int signo
) /* one signal handler for SIGUSR1 and SIGUSR2 */
19 if (signal(SIGUSR1
, sig_usr
) == SIG_ERR
)
20 err_sys("signal(SIGINT) error");
21 if (signal(SIGUSR2
, sig_usr
) == SIG_ERR
)
22 err_sys("signal(SIGQUIT) error");
24 sigemptyset(&zeromask
);
26 sigemptyset(&newmask
);
27 sigaddset(&newmask
, SIGUSR1
);
28 sigaddset(&newmask
, SIGUSR2
);
29 /* block SIGUSR1 and SIGUSR2, and save current signal mask */
30 if (sigprocmask(SIG_BLOCK
, &newmask
, &oldmask
) < 0)
31 err_sys("SIG_BLOCK error");
35 TELL_PARENT(pid_t pid
)
37 kill(pid
, SIGUSR2
); /* tell parent we're done */
44 sigsuspend(&zeromask
); /* and wait for parent */
47 /* reset signal mask to original value */
48 if (sigprocmask(SIG_SETMASK
, &oldmask
, NULL
) < 0)
49 err_sys("SIG_SETMASK error");
55 kill(pid
, SIGUSR1
); /* tell child we're done */
62 sigsuspend(&zeromask
); /* and wait for child */
65 /* reset signal mask to original value */
66 if (sigprocmask(SIG_SETMASK
, &oldmask
, NULL
) < 0)
67 err_sys("SIG_SETMASK error");