Module Name:    src
Committed By:   kre
Date:           Mon Dec  9 00:14:24 UTC 2019

Modified Files:
        src/bin/sh: eval.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/bin/sh/eval.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.175 src/bin/sh/eval.c:1.176
--- src/bin/sh/eval.c:1.175	Sat May  4 02:52:55 2019
+++ src/bin/sh/eval.c	Mon Dec  9 00:14:24 2019
@@ -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 @@ evalcommand(union node *cmd, int flgs, s
 		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;

Reply via email to