Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Finish (hopefully) the second half of 1.47 ... make sure



details:   https://anonhg.NetBSD.org/src/rev/533061950374
branches:  trunk
changeset: 447598:533061950374
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Jan 18 06:28:09 2019 +0000

description:
Finish (hopefully) the second half of 1.47 ... make sure
that when traps are marked as invalid, we never use them
for anything except output from the trap command.

Fixes issues where sub-shells of shells which use traps
(eg: to trap SIGPIPE) can end up looping forever if the
signal occurs in a sub-shell (where the trap is supposed
to be reset to its default).   Reported, and mostly
analyzed by Martijn Dekker.

diffstat:

 bin/sh/trap.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r 85892aedd84e -r 533061950374 bin/sh/trap.c
--- a/bin/sh/trap.c     Fri Jan 18 06:04:10 2019 +0000
+++ b/bin/sh/trap.c     Fri Jan 18 06:28:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.50 2018/12/12 20:22:43 kre Exp $    */
+/*     $NetBSD: trap.c,v 1.51 2019/01/18 06:28:09 kre 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.50 2018/12/12 20:22:43 kre Exp $");
+__RCSID("$NetBSD: trap.c,v 1.51 2019/01/18 06:28:09 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -452,7 +452,7 @@
        sig_t sigact = SIG_DFL, sig;
        char *t, tsig;
 
-       if ((t = trap[signo]) == NULL)
+       if (traps_invalid || (t = trap[signo]) == NULL)
                action = S_DFL;
        else if (*t != '\0')
                action = S_CATCH;
@@ -609,7 +609,7 @@
 
        p = trap[SIGCHLD];
 
-       if (p != NULL && *p == '\0')
+       if (traps_invalid || (p != NULL && *p == '\0'))
                p = NULL;
 
        return p;
@@ -654,7 +654,7 @@
        signal(signo, onsig);
        */
 
-       if (signo == SIGINT && trap[SIGINT] == NULL) {
+       if (signo == SIGINT && (traps_invalid || trap[SIGINT] == NULL)) {
                onint();
                return;
        }
@@ -662,7 +662,7 @@
        /*
         * if the signal will do nothing, no point reporting it
         */
-       if (trap[signo] != NULL && trap[signo][0] != '\0' &&
+       if (!traps_invalid && trap[signo] != NULL && trap[signo][0] != '\0' &&
            signo != SIGCHLD) {
                gotsig[signo] = 1;
                pendingsigs++;



Home | Main Index | Thread Index | Old Index