This commit was manufactured by cvs2svn to create tag 'FreeBSD-release/1.0'.
[unix-history] / bin / sh / trap.c
index 68104ce..f1a4e82 100644 (file)
@@ -35,7 +35,8 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)trap.c     5.2 (Berkeley) 4/12/91";
+/*static char sccsid[] = "from: @(#)trap.c     5.2 (Berkeley) 4/12/91";*/
+static char rcsid[] = "trap.c,v 1.5 1993/08/06 21:50:18 mycroft Exp";
 #endif /* not lint */
 
 #include "shell.h"
 #endif /* not lint */
 
 #include "shell.h"
@@ -45,7 +46,6 @@ static char sccsid[] = "@(#)trap.c    5.2 (Berkeley) 4/12/91";
 #include "jobs.h"
 #include "options.h"
 #include "syntax.h"
 #include "jobs.h"
 #include "options.h"
 #include "syntax.h"
-#include "signames.h"
 #include "output.h"
 #include "memalloc.h"
 #include "error.h"
 #include "output.h"
 #include "memalloc.h"
 #include "error.h"
@@ -68,10 +68,10 @@ static char sccsid[] = "@(#)trap.c  5.2 (Berkeley) 4/12/91";
 
 extern char nullstr[1];                /* null string */
 
 
 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 */
-int pendingsigs;                       /* indicates some signal received */
+char *trap[NSIG];              /* trap handler commands */
+MKINIT char sigmode[NSIG];     /* current value of signal */
+char gotsig[NSIG];             /* indicates specified signal received */
+int pendingsigs;               /* indicates some signal received */
 
 /*
  * The trap builtin.
 
 /*
  * The trap builtin.
@@ -83,7 +83,7 @@ trapcmd(argc, argv)  char **argv; {
        int signo;
 
        if (argc <= 1) {
        int signo;
 
        if (argc <= 1) {
-               for (signo = 0 ; signo <= MAXSIG ; signo++) {
+               for (signo = 0 ; signo < NSIG ; signo++) {
                        if (trap[signo] != NULL)
                                out1fmt("%d: %s\n", signo, trap[signo]);
                }
                        if (trap[signo] != NULL)
                                out1fmt("%d: %s\n", signo, trap[signo]);
                }
@@ -95,7 +95,7 @@ trapcmd(argc, argv)  char **argv; {
        else
                action = *ap++;
        while (*ap) {
        else
                action = *ap++;
        while (*ap) {
-               if ((signo = number(*ap)) < 0 || signo > MAXSIG)
+               if ((signo = number(*ap)) < 0 || signo >= NSIG)
                        error("%s: bad trap", *ap);
                INTOFF;
                if (action)
                        error("%s: bad trap", *ap);
                INTOFF;
                if (action)
@@ -121,7 +121,7 @@ void
 clear_traps() {
        char **tp;
 
 clear_traps() {
        char **tp;
 
-       for (tp = trap ; tp <= &trap[MAXSIG] ; tp++) {
+       for (tp = trap ; tp < &trap[NSIG] ; tp++) {
                if (*tp && **tp) {      /* trap not NULL or SIG_IGN */
                        INTOFF;
                        ckfree(*tp);
                if (*tp && **tp) {      /* trap not NULL or SIG_IGN */
                        INTOFF;
                        ckfree(*tp);
@@ -182,7 +182,7 @@ setsignal(signo) {
 #endif
                }
        }
 #endif
                }
        }
-       t = &sigmode[signo - 1];
+       t = &sigmode[signo];
        if (*t == 0) {  /* current setting unknown */
                /*
                 * There is a race condition here if action is not S_IGN.
        if (*t == 0) {  /* current setting unknown */
                /*
                 * There is a race condition here if action is not S_IGN.
@@ -214,22 +214,22 @@ setsignal(signo) {
 
 void
 ignoresig(signo) {
 
 void
 ignoresig(signo) {
-       if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
+       if (sigmode[signo] != S_IGN && sigmode[signo] != S_HARD_IGN) {
                signal(signo, SIG_IGN);
        }
                signal(signo, SIG_IGN);
        }
-       sigmode[signo - 1] = S_HARD_IGN;
+       sigmode[signo] = S_HARD_IGN;
 }
 
 
 #ifdef mkinit
 }
 
 
 #ifdef mkinit
-INCLUDE "signames.h"
+INCLUDE <sys/signal.h>
 INCLUDE "trap.h"
 
 SHELLPROC {
        char *sm;
 
        clear_traps();
 INCLUDE "trap.h"
 
 SHELLPROC {
        char *sm;
 
        clear_traps();
-       for (sm = sigmode ; sm < sigmode + MAXSIG ; sm++) {
+       for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
                if (*sm == S_IGN)
                        *sm = S_HARD_IGN;
        }
                if (*sm == S_IGN)
                        *sm = S_HARD_IGN;
        }
@@ -249,7 +249,7 @@ onsig(signo) {
                onint();
                return;
        }
                onint();
                return;
        }
-       gotsig[signo - 1] = 1;
+       gotsig[signo] = 1;
        pendingsigs++;
 }
 
        pendingsigs++;
 }
 
@@ -267,12 +267,12 @@ dotrap() {
 
        for (;;) {
                for (i = 1 ; ; i++) {
 
        for (;;) {
                for (i = 1 ; ; i++) {
-                       if (gotsig[i - 1])
-                               break;
-                       if (i >= MAXSIG)
+                       if (i >= NSIG)
                                goto done;
                                goto done;
+                       if (gotsig[i])
+                               break;
                }
                }
-               gotsig[i - 1] = 0;
+               gotsig[i] = 0;
                savestatus=exitstatus;
                evalstring(trap[i]);
                exitstatus=savestatus;
                savestatus=exitstatus;
                evalstring(trap[i]);
                exitstatus=savestatus;