summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormartin <martin@NetBSD.org>2019-12-11 14:52:50 +0000
committermartin <martin@NetBSD.org>2019-12-11 14:52:50 +0000
commit09e1365f7deda2f3e4ae7bbaf7c13a924f86a6b7 (patch)
tree8cbb405b533f6feed9a0a6e0c31db33a49eb86fa /bin
parent40751531d6d9516afd64ee25d3327ef5dfba535c (diff)
Pull up following revision(s) (requested by kre in ticket #542):
bin/sh/eval.c: revision 1.176 bin/sh/trap.c: revision 1.53 PR bin/54743 Having traps set should not enforce a fork for the next command, whatever that command happens to be, only for commands which would normally fork if they weren't the last command expected to be executed (ie: builtins and functions shouldn't be exexuted in a sub-shell merely because a trap is set). As it was (for example) trap 'whatever' SIGANY; wait $anypid was guaranteed to fail the wait, as the subshell it was executed in could not have any children. XXX pullup -9 PR bin/54743 If a builtin command or function is the final command intended to be executed, and is interrupted by a caught signal, the trap handler for that signal was not executed - the shell simply exited (an exit trap handler would still have been run - if there was one the handler for the signal may have been invoked during the execution of the exit trap handler, which, if it happened, is incorrect sequencing). Now, if we're exiting, and there are pending signals, run their handlers just before running the EXIT trap handler, if any. There are almost certainly plenty more issues with traps that need solving. Later, XXX pullup -9 (-8 is too different in this area, and this problem suitably obscure, that we won't bother) (the -7 sh is simply obsolete).
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/eval.c23
-rw-r--r--bin/sh/trap.c10
2 files changed, 22 insertions, 11 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index e5b7b340c0d..0ce1e79b040 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.175 2019/05/04 02:52:55 kre Exp $ */
+/* $NetBSD: eval.c,v 1.175.2.1 2019/12/11 14:52:50 martin Exp $ */
/*-
* Copyright (c) 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
-__RCSID("$NetBSD: eval.c,v 1.175 2019/05/04 02:52:55 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.175.2.1 2019/12/11 14:52:50 martin Exp $");
#endif
#endif /* not lint */
@@ -1061,13 +1061,18 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
free_traps();
/* Fork off a child process if necessary. */
- if (cmd->ncmd.backgnd || (have_traps() && (flags & EV_EXIT) != 0)
- || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
- && (flags & EV_EXIT) == 0)
- || ((flags & EV_BACKCMD) != 0 &&
- ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN)
- || cmdentry.u.bltin == dotcmd
- || cmdentry.u.bltin == evalcmd))) {
+ if (cmd->ncmd.backgnd
+ || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
+ && (have_traps() || (flags & EV_EXIT) == 0))
+#ifdef notyet /* EV_BACKCMD is never set currently */
+ /* this will need more work if/when it gets used */
+ || ((flags & EV_BACKCMD) != 0
+ && (cmdentry.cmdtype != CMDBUILTIN
+ && cmdentry.cmdtype != CMDSPLBLTIN)
+ || cmdentry.u.bltin == dotcmd
+ || cmdentry.u.bltin == evalcmd)
+#endif
+ ) {
INTOFF;
jp = makejob(cmd, 1);
mode = cmd->ncmd.backgnd;
diff --git a/bin/sh/trap.c b/bin/sh/trap.c
index 6a98f9a8bc2..d7fbdfbae21 100644
--- a/bin/sh/trap.c
+++ b/bin/sh/trap.c
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.52 2019/04/25 03:54:10 kre Exp $ */
+/* $NetBSD: trap.c,v 1.52.2.1 2019/12/11 14:52:50 martin Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
#else
-__RCSID("$NetBSD: trap.c,v 1.52 2019/04/25 03:54:10 kre Exp $");
+__RCSID("$NetBSD: trap.c,v 1.52.2.1 2019/12/11 14:52:50 martin Exp $");
#endif
#endif /* not lint */
@@ -854,6 +854,12 @@ exitshell_savedstatus(void)
}
exitstatus = exiting_status;
+ if (pendingsigs && !setjmp(loc.loc)) {
+ handler = &loc;
+
+ dotrap();
+ }
+
if (!setjmp(loc.loc)) {
handler = &loc;