diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 82e74b88bf0..8554943e889 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 099dc11bec6..a0cd0ba14cd 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -221,6 +221,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 ccc1ffd4f4d..672ad08d481 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);