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)
This commit is contained in:
parent
53f55a430f
commit
6e28dacfda
@ -731,7 +731,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
|||||||
/* Fork off a child process if necessary. */
|
/* Fork off a child process if necessary. */
|
||||||
if (cmd->ncmd.backgnd
|
if (cmd->ncmd.backgnd
|
||||||
|| (cmdentry.cmdtype == CMDNORMAL
|
|| (cmdentry.cmdtype == CMDNORMAL
|
||||||
&& ((flags & EV_EXIT) == 0 || Tflag))
|
&& ((flags & EV_EXIT) == 0 || have_traps()))
|
||||||
|| ((flags & EV_BACKCMD) != 0
|
|| ((flags & EV_BACKCMD) != 0
|
||||||
&& (cmdentry.cmdtype != CMDBUILTIN
|
&& (cmdentry.cmdtype != CMDBUILTIN
|
||||||
|| cmdentry.u.index == CDCMD
|
|| cmdentry.u.index == CDCMD
|
||||||
|
@ -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
|
* Set the signal handler for the specified signal. The routine figures
|
||||||
* out what it should be set to.
|
* out what it should be set to.
|
||||||
|
@ -39,6 +39,7 @@ extern volatile sig_atomic_t gotwinch;
|
|||||||
|
|
||||||
int trapcmd(int, char **);
|
int trapcmd(int, char **);
|
||||||
void clear_traps(void);
|
void clear_traps(void);
|
||||||
|
int have_traps(void);
|
||||||
void setsignal(int);
|
void setsignal(int);
|
||||||
void ignoresig(int);
|
void ignoresig(int);
|
||||||
void onsig(int);
|
void onsig(int);
|
||||||
|
Loading…
Reference in New Issue
Block a user