Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Don't hard ignore signals that were ignored by our en...



details:   https://anonhg.NetBSD.org/src/rev/4f245c60085d
branches:  trunk
changeset: 582910:4f245c60085d
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jul 11 02:37:05 2005 +0000

description:
Don't hard ignore signals that were ignored by our environment, because
when we try to set a trap on them it will not work. Also while I am here:
1. don't change the action status if the signal system call failed.
2. don't try to sigignore it if signal failed.
3. clear the signal mask in case our parent blocked it for us.

diffstat:

 bin/sh/trap.c |  40 +++++++++++++++++++++++++++-------------
 1 files changed, 27 insertions(+), 13 deletions(-)

diffs (78 lines):

diff -r 0157e66904b0 -r 4f245c60085d bin/sh/trap.c
--- a/bin/sh/trap.c     Mon Jul 11 00:25:08 2005 +0000
+++ b/bin/sh/trap.c     Mon Jul 11 02:37:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.31 2005/01/11 19:38:57 christos Exp $       */
+/*     $NetBSD: trap.c,v 1.32 2005/07/11 02:37:05 christos 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.31 2005/01/11 19:38:57 christos Exp $");
+__RCSID("$NetBSD: trap.c,v 1.32 2005/07/11 02:37:05 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -229,11 +229,11 @@
  * out what it should be set to.
  */
 
-long
+sig_t
 setsignal(int signo, int vforked)
 {
        int action;
-       sig_t sigact = SIG_DFL;
+       sig_t sigact = SIG_DFL, sig;
        char *t, tsig;
 
        if ((t = trap[signo]) == NULL)
@@ -283,11 +283,13 @@
                        return 0;
                }
                if (sigact == SIG_IGN) {
-                       if (mflag && (signo == SIGTSTP ||
-                            signo == SIGTTIN || signo == SIGTTOU)) {
-                               tsig = S_IGN;   /* don't hard ignore these */
-                       } else
-                               tsig = S_HARD_IGN;
+                       /*
+                        * When we set a trap handler we want it to work,
+                        * even when our parent called us ignoring the
+                        * signal. This is what other shells do, so we
+                        * do not set S_HARD_IGN here.
+                        */
+                       tsig = S_IGN;
                } else {
                        tsig = S_RESET; /* force to be set */
                }
@@ -299,10 +301,22 @@
                case S_CATCH:   sigact = onsig;         break;
                case S_IGN:     sigact = SIG_IGN;       break;
        }
-       if (!vforked)
-               *t = action;
-       siginterrupt(signo, 1);
-       return (long)signal(signo, sigact);
+       sig = signal(signo, sigact);
+       if (sig != SIG_ERR) {
+               sigset_t ss;
+               if (!vforked)
+                       *t = action;
+               if (action == S_CATCH)
+                       (void)siginterrupt(signo, 1);
+               /*
+                * If our parent accidentally blocked signals for
+                * us make sure we unblock them
+                */
+               (void)sigemptyset(&ss);
+               (void)sigaddset(&ss, signo);
+               (void)sigprocmask(SIG_UNBLOCK, &ss, NULL);
+       }
+       return sig;
 }
 
 /*



Home | Main Index | Thread Index | Old Index