Use sigaction(2) instead of signal(3) to avoid the signal handler being

re-entered.
This commit is contained in:
tjr 2002-07-26 05:25:12 +00:00
parent 501a9e51e5
commit 32b632dfec

View File

@ -94,6 +94,7 @@ int doclean; /* Should cleanup() remove output? */
int
main(int argc, char *argv[])
{
struct sigaction sa;
long i;
int ch;
const char *expr;
@ -145,9 +146,15 @@ main(int argc, char *argv[])
if (!kflag) {
doclean = 1;
atexit(cleanup);
signal(SIGHUP, handlesig);
signal(SIGINT, handlesig);
signal(SIGTERM, handlesig);
sa.sa_flags = 0;
sa.sa_handler = handlesig;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGHUP);
sigaddset(&sa.sa_mask, SIGINT);
sigaddset(&sa.sa_mask, SIGTERM);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
}
lineno = 0;