Instead of special casing SIGKILL, pretend that trap
authorChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Tue, 6 Jun 1995 03:20:50 +0000 (19:20 -0800)
committerChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Tue, 6 Jun 1995 03:20:50 +0000 (19:20 -0800)
succeeded every time sigaction failed [suggested by mycroft]

SCCS-vsn: bin/sh/trap.c 8.5
SCCS-vsn: bin/sh/trap.h 8.3

usr/src/bin/sh/trap.c
usr/src/bin/sh/trap.h

index 0a98659..2802cc7 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)trap.c     8.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)trap.c     8.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <signal.h>
 #endif /* not lint */
 
 #include <signal.h>
@@ -51,6 +51,8 @@ MKINIT char sigmode[NSIG];    /* current value of signal */
 char gotsig[NSIG];             /* indicates specified signal received */
 int pendingsigs;                       /* indicates some signal received */
 
 char gotsig[NSIG];             /* indicates specified signal received */
 int pendingsigs;                       /* indicates some signal received */
 
+static int getsigaction __P((int, sig_t *));
+
 /*
  * The trap builtin.
  */
 /*
  * The trap builtin.
  */
@@ -130,7 +132,6 @@ setsignal(signo)
        sig_t sigact = SIG_DFL;
        char *t;
        extern void onsig();
        sig_t sigact = SIG_DFL;
        char *t;
        extern void onsig();
-       extern sig_t getsigaction();
 
        if ((t = trap[signo]) == NULL)
                action = S_DFL;
 
        if ((t = trap[signo]) == NULL)
                action = S_DFL;
@@ -168,16 +169,19 @@ setsignal(signo)
                }
        }
 
                }
        }
 
-       if (signo == SIGKILL) 
-               /* Pretend it worked */
-               return 0;
-
        t = &sigmode[signo - 1];
        if (*t == 0) {  
                /* 
                 * current setting unknown 
                 */
        t = &sigmode[signo - 1];
        if (*t == 0) {  
                /* 
                 * current setting unknown 
                 */
-               sigact = getsigaction(signo);
+               if (!getsigaction(signo, &sigact)) {
+                       /*
+                        * Pretend it worked; maybe we should give a warning
+                        * here, but other shells don't. We don't alter
+                        * sigmode, so that we retry every time.
+                        */
+                       return 0;
+               }
                if (sigact == SIG_IGN) {
                        if (mflag && (signo == SIGTSTP || 
                             signo == SIGTTIN || signo == SIGTTOU)) {
                if (sigact == SIG_IGN) {
                        if (mflag && (signo == SIGTSTP || 
                             signo == SIGTTIN || signo == SIGTTOU)) {
@@ -202,16 +206,17 @@ setsignal(signo)
 /*
  * Return the current setting for sig w/o changing it.
  */
 /*
  * Return the current setting for sig w/o changing it.
  */
-sig_t
-getsigaction(signo) 
+static int
+getsigaction(signo, sigact
        int signo;
        int signo;
+       sig_t *sigact;
 {
        struct sigaction sa;
 
        if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
 {
        struct sigaction sa;
 
        if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
-               error("Sigaction system call failed");
-
-       return (sig_t) sa.sa_handler;
+               return 0;
+       *sigact = (sig_t) sa.sa_handler;
+       return 1;
 }
 
 /*
 }
 
 /*
index 3bbecd9..b840b08 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)trap.h      8.2 (Berkeley) %G%
+ *     @(#)trap.h      8.3 (Berkeley) %G%
  */
 
 extern int pendingsigs;
  */
 
 extern int pendingsigs;
@@ -15,7 +15,6 @@ extern int pendingsigs;
 int trapcmd __P((int, char **));
 void clear_traps __P((void)); 
 long setsignal __P((int)); 
 int trapcmd __P((int, char **));
 void clear_traps __P((void)); 
 long setsignal __P((int)); 
-sig_t getsigaction __P((int));
 void ignoresig __P((int));
 void onsig __P((int));
 void dotrap __P((void));
 void ignoresig __P((int));
 void onsig __P((int));
 void dotrap __P((void));