Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh PR bin/54743



details:   https://anonhg.NetBSD.org/src/rev/73e6644be837
branches:  trunk
changeset: 847073:73e6644be837
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Dec 09 00:14:24 2019 +0000

description:
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

diffstat:

 bin/sh/eval.c |  23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diffs (44 lines):

diff -r bab37297b865 -r 73e6644be837 bin/sh/eval.c
--- a/bin/sh/eval.c     Mon Dec 09 00:11:32 2019 +0000
+++ b/bin/sh/eval.c     Mon Dec 09 00:14:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.175 2019/05/04 02:52:55 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.176 2019/12/09 00:14:24 kre 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.176 2019/12/09 00:14:24 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1061,13 +1061,18 @@
                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;



Home | Main Index | Thread Index | Old Index