Source-Changes-HG archive

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

[src/netbsd-9]: src/bin/sh Pull up following revision(s) (requested by kre in...



details:   https://anonhg.NetBSD.org/src/rev/4f28dccd7793
branches:  netbsd-9
changeset: 843662:4f28dccd7793
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Dec 11 14:52:50 2019 +0000

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

 bin/sh/eval.c |  23 ++++++++++++++---------
 bin/sh/trap.c |  10 ++++++++--
 2 files changed, 22 insertions(+), 11 deletions(-)

diffs (75 lines):

diff -r b8cc27fea2c7 -r 4f28dccd7793 bin/sh/eval.c
--- a/bin/sh/eval.c     Wed Dec 11 14:48:31 2019 +0000
+++ b/bin/sh/eval.c     Wed Dec 11 14:52:50 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.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 @@
                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 -r b8cc27fea2c7 -r 4f28dccd7793 bin/sh/trap.c
--- a/bin/sh/trap.c     Wed Dec 11 14:48:31 2019 +0000
+++ b/bin/sh/trap.c     Wed Dec 11 14:52:50 2019 +0000
@@ -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 @@
        }
        exitstatus = exiting_status;
 
+       if (pendingsigs && !setjmp(loc.loc)) {
+               handler = &loc;
+
+               dotrap();
+       }
+
        if (!setjmp(loc.loc)) {
                handler = &loc;
 



Home | Main Index | Thread Index | Old Index