diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-10-09 09:34:06 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-10-09 09:34:06 +0000 |
commit | a0c4be0a94cdf9948971a4fbce5efd01a98678ef (patch) | |
tree | a4c0b0550090690d402d6a859f21748783ae945a /usr.bin | |
parent | 24a140c5b16f0c376c21724937c211d9cc53f266 (diff) |
just-in-time signal handling: do not setup the handlers until we need them.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/job.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index d53fe717825..913989d9cfe 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: job.c,v 1.93 2007/10/09 09:32:03 espie Exp $ */ +/* $OpenBSD: job.c,v 1.94 2007/10/09 09:34:05 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* @@ -284,6 +284,7 @@ static void DBPRINTF(Job *, const char *, ...); static void debug_printf(const char *, ...); static FILE *new_command_file(void); static void setup_signal(int); +static void setup_all_signals(void); static volatile sig_atomic_t got_signal; @@ -420,7 +421,7 @@ pass_signal_to_job(void *jobp, /* Job to biff */ /*- *----------------------------------------------------------------------- - * JobPassSig -- + * handle_signal -- * Pass a signal to all local jobs if USE_PGRP is defined, * then die ourselves. * @@ -925,6 +926,7 @@ static void JobExec(Job *job, char **argv) { pid_t cpid; /* ID of new child */ + static int signals_caught = 0; if (DEBUG(JOB)) { int i; @@ -949,6 +951,11 @@ JobExec(Job *job, char **argv) lastNode = job->node; } + if (!signals_caught) { + signals_caught = 1; + setup_all_signals(); + } + if ((cpid = fork()) == -1) { Punt("Cannot fork"); } else if (cpid == 0) { @@ -1703,6 +1710,31 @@ setup_signal(int sig) } } +static void +setup_all_signals() +{ + /* + * Catch the four signals that POSIX specifies if they aren't ignored. + * handle_signal will take care of calling JobInterrupt if appropriate. + */ + setup_signal(SIGINT); + setup_signal(SIGHUP); + setup_signal(SIGQUIT); + setup_signal(SIGTERM); + /* + * There are additional signals that need to be caught and passed if + * either the export system wants to be told directly of signals or if + * we're giving each job its own process group (since then it won't get + * signals from the terminal driver as we own the terminal) + */ +#if defined(USE_PGRP) + setup_signal(SIGTSTP); + setup_signal(SIGTTOU); + setup_signal(SIGTTIN); + setup_signal(SIGWINCH); +#endif +} + /*- *----------------------------------------------------------------------- * Job_Init -- @@ -1736,27 +1768,6 @@ Job_Init(int maxproc) targFmt = TARG_FMT; } - /* - * Catch the four signals that POSIX specifies if they aren't ignored. - * JobPassSig will take care of calling JobInterrupt if appropriate. - */ - setup_signal(SIGINT); - setup_signal(SIGHUP); - setup_signal(SIGQUIT); - setup_signal(SIGTERM); - /* - * There are additional signals that need to be caught and passed if - * either the export system wants to be told directly of signals or if - * we're giving each job its own process group (since then it won't get - * signals from the terminal driver as we own the terminal) - */ -#if defined(USE_PGRP) - setup_signal(SIGTSTP); - setup_signal(SIGTTOU); - setup_signal(SIGTTIN); - setup_signal(SIGWINCH); -#endif - if ((begin_node->type & OP_DUMMY) == 0) { JobStart(begin_node, JOB_SPECIAL); while (nJobs) { |