exit 0 on success
[unix-history] / usr / src / bin / sh / trap.c
index e480791..69b7fad 100644 (file)
@@ -9,13 +9,9 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)trap.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)trap.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-/*
- * Routines for dealing with signals.
- */
-
 #include "shell.h"
 #include "main.h"
 #include "nodes.h"     /* for other headers */
 #include "shell.h"
 #include "main.h"
 #include "nodes.h"     /* for other headers */
@@ -49,8 +45,7 @@ extern char nullstr[1];               /* null string */
 char *trap[MAXSIG+1];          /* trap handler commands */
 MKINIT char sigmode[MAXSIG];   /* current value of signal */
 char gotsig[MAXSIG];           /* indicates specified signal received */
 char *trap[MAXSIG+1];          /* trap handler commands */
 MKINIT char sigmode[MAXSIG];   /* current value of signal */
 char gotsig[MAXSIG];           /* indicates specified signal received */
-int pendingsigs;               /* indicates some signal received */
-
+int pendingsigs;                       /* indicates some signal received */
 
 /*
  * The trap builtin.
 
 /*
  * The trap builtin.
@@ -138,9 +133,16 @@ setsignal(signo) {
                        if (iflag)
                                action = S_CATCH;
                        break;
                        if (iflag)
                                action = S_CATCH;
                        break;
-#ifndef DEBUG
                case SIGQUIT:
                case SIGQUIT:
+#ifdef DEBUG
+                       {
+                       extern int debug;
+
+                       if (debug)
+                               break;
+                       }
 #endif
 #endif
+                       /* FALLTHROUGH */
                case SIGTERM:
                        if (iflag)
                                action = S_IGN;
                case SIGTERM:
                        if (iflag)
                                action = S_IGN;
@@ -171,16 +173,15 @@ setsignal(signo) {
        if (*t == S_HARD_IGN || *t == action)
                return 0;
        switch (action) {
        if (*t == S_HARD_IGN || *t == action)
                return 0;
        switch (action) {
-               case S_DFL:        sigact = SIG_DFL;            break;
-               case S_CATCH:      sigact = onsig;              break;
-               case S_IGN:        sigact = SIG_IGN;            break;
+               case S_DFL:     sigact = SIG_DFL;       break;
+               case S_CATCH:   sigact = onsig;         break;
+               case S_IGN:     sigact = SIG_IGN;       break;
        }
        *t = action;
        return (int)signal(signo, sigact);
 }
 
 
        }
        *t = action;
        return (int)signal(signo, sigact);
 }
 
 
-
 /*
  * Ignore a signal.
  */
 /*
  * Ignore a signal.
  */
@@ -236,6 +237,7 @@ onsig(signo) {
 void
 dotrap() {
        int i;
 void
 dotrap() {
        int i;
+       int savestatus;
 
        for (;;) {
                for (i = 1 ; ; i++) {
 
        for (;;) {
                for (i = 1 ; ; i++) {
@@ -245,7 +247,9 @@ dotrap() {
                                goto done;
                }
                gotsig[i - 1] = 0;
                                goto done;
                }
                gotsig[i - 1] = 0;
+               savestatus=exitstatus;
                evalstring(trap[i]);
                evalstring(trap[i]);
+               exitstatus=savestatus;
        }
 done:
        pendingsigs = 0;
        }
 done:
        pendingsigs = 0;