diff options
author | jilles <jilles@FreeBSD.org> | 2009-06-13 21:10:41 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2009-06-13 21:10:41 +0000 |
commit | 7decb9c312312e3869ccb7439115644dc95ed665 (patch) | |
tree | 4f076f4b21a2e29a81466aef9594ef539a2c56ed /bin | |
parent | 595149bf9031d68f18bb15236b09e76d0d4abf10 (diff) | |
download | FreeBSD-src-7decb9c312312e3869ccb7439115644dc95ed665.zip FreeBSD-src-7decb9c312312e3869ccb7439115644dc95ed665.tar.gz |
Don't skip forking for an external command if any traps are active.
Example:
sh -c '(trap "echo trapped" EXIT; sleep 3)'
now correctly prints "trapped".
With this check, it is no longer necessary to check for -T
explicitly in that case.
This is a useful bugfix by itself and also important because I plan to
skip forking more often.
PR: bin/113860 (part of)
PR: bin/74404 (part of)
Reviewed by: stefanf
Approved by: ed (mentor)
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/eval.c | 2 | ||||
-rw-r--r-- | bin/sh/trap.c | 15 | ||||
-rw-r--r-- | bin/sh/trap.h | 1 |
3 files changed, 17 insertions, 1 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 82e74b8..8554943 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -731,7 +731,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) /* Fork off a child process if necessary. */ if (cmd->ncmd.backgnd || (cmdentry.cmdtype == CMDNORMAL - && ((flags & EV_EXIT) == 0 || Tflag)) + && ((flags & EV_EXIT) == 0 || have_traps())) || ((flags & EV_BACKCMD) != 0 && (cmdentry.cmdtype != CMDBUILTIN || cmdentry.u.index == CDCMD diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 099dc11..a0cd0ba 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -222,6 +222,21 @@ clear_traps(void) /* + * Check if we have any traps enabled. + */ +int +have_traps(void) +{ + char *volatile *tp; + + for (tp = trap ; tp <= &trap[NSIG - 1] ; tp++) { + if (*tp && **tp) /* trap not NULL or SIG_IGN */ + return 1; + } + return 0; +} + +/* * Set the signal handler for the specified signal. The routine figures * out what it should be set to. */ diff --git a/bin/sh/trap.h b/bin/sh/trap.h index ccc1ffd..672ad08 100644 --- a/bin/sh/trap.h +++ b/bin/sh/trap.h @@ -39,6 +39,7 @@ extern volatile sig_atomic_t gotwinch; int trapcmd(int, char **); void clear_traps(void); +int have_traps(void); void setsignal(int); void ignoresig(int); void onsig(int); |