Changes from Charles Hannum (mycroft@netbsd.org) to use POSIX signals
authorChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Thu, 23 Mar 1995 06:12:40 +0000 (22:12 -0800)
committerChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Thu, 23 Mar 1995 06:12:40 +0000 (22:12 -0800)
SCCS-vsn: bin/csh/Makefile 8.2
SCCS-vsn: bin/csh/set.c 8.2
SCCS-vsn: bin/csh/proc.c 8.2
SCCS-vsn: bin/csh/sem.c 8.2
SCCS-vsn: bin/csh/exec.c 8.2
SCCS-vsn: bin/csh/file.c 8.3
SCCS-vsn: bin/csh/func.c 8.2
SCCS-vsn: bin/csh/hist.c 8.2
SCCS-vsn: bin/csh/csh.c 8.3

usr/src/bin/csh/Makefile
usr/src/bin/csh/csh.c
usr/src/bin/csh/exec.c
usr/src/bin/csh/file.c
usr/src/bin/csh/func.c
usr/src/bin/csh/hist.c
usr/src/bin/csh/proc.c
usr/src/bin/csh/sem.c
usr/src/bin/csh/set.c

index 8088cb3..46ee58a 100644 (file)
@@ -1,4 +1,4 @@
-#      @(#)Makefile    8.1 (Berkeley) %G%
+#      @(#)Makefile    8.2 (Berkeley) %G%
 #
 # C Shell with process control; VM/UNIX VAX Makefile
 # Bill Joy UC Berkeley; Jim Kulp IIASA, Austria
 #
 # C Shell with process control; VM/UNIX VAX Makefile
 # Bill Joy UC Berkeley; Jim Kulp IIASA, Austria
@@ -8,7 +8,7 @@
 PROG=  csh
 DFLAGS=-DBUILTIN -DFILEC -DNLS -DSHORT_STRINGS
 #CFLAGS+=-g
 PROG=  csh
 DFLAGS=-DBUILTIN -DFILEC -DNLS -DSHORT_STRINGS
 #CFLAGS+=-g
-#CFLAGS+=-Wall -ansi -pedantic
+#CFLAGS+=-Wall 
 CFLAGS+=-I${.CURDIR} -I. ${DFLAGS}
 SRCS=  alloc.c char.c const.c csh.c dir.c dol.c err.c exec.c exp.c file.c \
        func.c glob.c hist.c init.c lex.c misc.c parse.c printf.c proc.c \
 CFLAGS+=-I${.CURDIR} -I. ${DFLAGS}
 SRCS=  alloc.c char.c const.c csh.c dir.c dol.c err.c exec.c exp.c file.c \
        func.c glob.c hist.c init.c lex.c misc.c parse.c printf.c proc.c \
index 0025e24..99c0197 100644 (file)
@@ -12,7 +12,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)csh.c      8.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)csh.c      8.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -90,7 +90,8 @@ main(argc, argv)
     register char *tcp;
     register int f;
     register char **tempv;
     register char *tcp;
     register int f;
     register char **tempv;
-    struct sigvec osv;
+    struct sigaction oact;
+    sigset_t sigset;
 
     cshin = stdin;
     cshout = stdout;
 
     cshin = stdin;
     cshout = stdout;
@@ -240,10 +241,10 @@ main(argc, argv)
      * only if we are the login shell.
      */
     /* parents interruptibility */
      * only if we are the login shell.
      */
     /* parents interruptibility */
-    (void) sigvec(SIGINT, NULL, &osv);
-    parintr = (void (*) ()) osv.sv_handler;
-    (void) sigvec(SIGTERM, NULL, &osv);
-    parterm = (void (*) ()) osv.sv_handler;
+    (void) sigaction(SIGINT, NULL, &oact);
+    parintr = oact.sa_handler;
+    (void) sigaction(SIGTERM, NULL, &oact);
+    parterm = oact.sa_handler;
 
     if (loginsh) {
        (void) signal(SIGHUP, phup);    /* exit processing on HUP */
 
     if (loginsh) {
        (void) signal(SIGHUP, phup);    /* exit processing on HUP */
@@ -424,7 +425,9 @@ main(argc, argv)
        if (!quitit)            /* Wary! */
            (void) signal(SIGQUIT, SIG_IGN);
        (void) signal(SIGINT, pintr);
        if (!quitit)            /* Wary! */
            (void) signal(SIGQUIT, SIG_IGN);
        (void) signal(SIGINT, pintr);
-       (void) sigblock(sigmask(SIGINT));
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_BLOCK, &sigset, NULL);
        (void) signal(SIGTERM, SIG_IGN);
        if (quitit == 0 && arginp == 0) {
            (void) signal(SIGTSTP, SIG_IGN);
        (void) signal(SIGTERM, SIG_IGN);
        if (quitit == 0 && arginp == 0) {
            (void) signal(SIGTSTP, SIG_IGN);
@@ -492,7 +495,11 @@ notty:
        {
            int     osetintr = setintr;
            sig_t   oparintr = parintr;
        {
            int     osetintr = setintr;
            sig_t   oparintr = parintr;
-           sigset_t omask = sigblock(sigmask(SIGINT));
+           sigset_t osigset;
+
+           sigemptyset(&sigset);
+           sigaddset(&sigset, SIGINT);
+           sigprocmask(SIG_BLOCK, &sigset, &osigset);
 
            setintr = 0;
            parintr = SIG_IGN;  /* Disable onintr */
 
            setintr = 0;
            parintr = SIG_IGN;  /* Disable onintr */
@@ -505,7 +512,7 @@ notty:
            if (loginsh)
                (void) srcfile(_PATH_DOTLOGIN, 0, 0);
 #endif
            if (loginsh)
                (void) srcfile(_PATH_DOTLOGIN, 0, 0);
 #endif
-           (void) sigsetmask(omask);
+           sigprocmask(SIG_SETMASK, &osigset, NULL);
            setintr = osetintr;
            parintr = oparintr;
        }
            setintr = osetintr;
            parintr = oparintr;
        }
@@ -662,7 +669,7 @@ srcunit(unit, onlyown, hflg)
     bool    otell = cantell;
 
     struct Bin saveB;
     bool    otell = cantell;
 
     struct Bin saveB;
-    volatile sigset_t omask;
+    sigset_t sigset, osigset;
     jmp_buf oldexit;
 
     /* The (few) real local variables */
     jmp_buf oldexit;
 
     /* The (few) real local variables */
@@ -693,10 +700,12 @@ srcunit(unit, onlyown, hflg)
      */
     insource = 1;
     getexit(oldexit);
      */
     insource = 1;
     getexit(oldexit);
-    omask = 0;
 
 
-    if (setintr)
-       omask = sigblock(sigmask(SIGINT));
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_BLOCK, &sigset, &osigset);
+    }
     /* Setup the new values of the state stuff saved above */
     bcopy((char *) &B, (char *) &(saveB), sizeof(B));
     fbuf = NULL;
     /* Setup the new values of the state stuff saved above */
     bcopy((char *) &B, (char *) &(saveB), sizeof(B));
     fbuf = NULL;
@@ -714,14 +723,14 @@ srcunit(unit, onlyown, hflg)
      * interrupted.
      */
     if (setintr)
      * interrupted.
      */
     if (setintr)
-       (void) sigsetmask(omask);
+       sigprocmask(SIG_SETMASK, &osigset, NULL);
     settell();
 
     if ((my_reenter = setexit()) == 0)
        process(0);             /* 0 -> blow away on errors */
 
     if (setintr)
     settell();
 
     if ((my_reenter = setexit()) == 0)
        process(0);             /* 0 -> blow away on errors */
 
     if (setintr)
-       (void) sigsetmask(omask);
+       sigprocmask(SIG_SETMASK, &osigset, NULL);
     if (oSHIN >= 0) {
        register int i;
 
     if (oSHIN >= 0) {
        register int i;
 
@@ -898,11 +907,14 @@ pintr1(wantnl)
     bool    wantnl;
 {
     Char **v;
     bool    wantnl;
 {
     Char **v;
-    sigset_t omask;
+    sigset_t sigset, osigset;
 
 
-    omask = sigblock((sigset_t) 0);
+    sigemptyset(&sigset);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     if (setintr) {
     if (setintr) {
-       (void) sigsetmask(omask & ~sigmask(SIGINT));
+       sigset = osigset;
+       sigdelset(&sigset, SIGINT);
+       sigprocmask(SIG_SETMASK, &sigset, NULL);
        if (pjobs) {
            pjobs = 0;
            (void) fprintf(cshout, "\n");
        if (pjobs) {
            pjobs = 0;
            (void) fprintf(cshout, "\n");
@@ -910,7 +922,8 @@ pintr1(wantnl)
            stderror(ERR_NAME | ERR_INTR);
        }
     }
            stderror(ERR_NAME | ERR_INTR);
        }
     }
-    (void) sigsetmask(omask & ~sigmask(SIGCHLD));
+    sigdelset(&osigset, SIGCHLD);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
     (void) fpurge(cshout);
     (void) endpwent();
 
     (void) fpurge(cshout);
     (void) endpwent();
 
@@ -956,6 +969,7 @@ process(catch)
 {
     jmp_buf osetexit;
     struct command *t = savet;
 {
     jmp_buf osetexit;
     struct command *t = savet;
+    sigset_t sigset;
 
     savet = NULL;
     getexit(osetexit);
 
     savet = NULL;
     getexit(osetexit);
@@ -969,8 +983,11 @@ process(catch)
        /*
         * Interruptible during interactive reads
         */
        /*
         * Interruptible during interactive reads
         */
-       if (setintr)
-           (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+       if (setintr) {
+           sigemptyset(&sigset);
+           sigaddset(&sigset, SIGINT);
+           sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+       }
 
        /*
         * For the sake of reset()
 
        /*
         * For the sake of reset()
@@ -1034,7 +1051,7 @@ process(catch)
         * The parser may lose space if interrupted.
         */
        if (setintr)
         * The parser may lose space if interrupted.
         */
        if (setintr)
-           (void) sigblock(sigmask(SIGINT));
+           sigprocmask(SIG_BLOCK, &sigset, NULL);
 
        /*
         * Save input text on the history list if reading in old history, or it
 
        /*
         * Save input text on the history list if reading in old history, or it
index 61eb259..40bbefb 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)exec.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)exec.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -90,6 +90,7 @@ doexec(v, t)
     register bool slash;
     register int hashval = 0, hashval1, i;
     Char   *blk[2];
     register bool slash;
     register int hashval = 0, hashval1, i;
     Char   *blk[2];
+    sigset_t sigset;
 
     /*
      * Glob the command name. We will search $path even if this does something,
 
     /*
      * Glob the command name. We will search $path even if this does something,
@@ -165,7 +166,8 @@ doexec(v, t)
      * We must do this AFTER any possible forking (like `foo` in glob) so that
      * this shell can still do subprocesses.
      */
      * We must do this AFTER any possible forking (like `foo` in glob) so that
      * this shell can still do subprocesses.
      */
-    (void) sigsetmask((sigset_t) 0);
+    sigemptyset(&sigset);
+    sigprocmask(SIG_SETMASK, &sigset, NULL);
     /*
      * If no path, no words in path, or a / in the filename then restrict the
      * command search.
     /*
      * If no path, no words in path, or a / in the filename then restrict the
      * command search.
index 58fa3c4..2564e78 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)file.c     8.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)file.c     8.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #ifdef FILEC
 #endif /* not lint */
 
 #ifdef FILEC
@@ -112,9 +112,11 @@ static void
 back_to_col_1()
 {
     struct termios tty, tty_normal;
 back_to_col_1()
 {
     struct termios tty, tty_normal;
-    int     omask;
+    sigset_t sigset, osigset;
 
 
-    omask = sigblock(sigmask(SIGINT));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGINT);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     (void) tcgetattr(SHOUT, &tty);
     tty_normal = tty;
     tty.c_iflag &= ~INLCR;
     (void) tcgetattr(SHOUT, &tty);
     tty_normal = tty;
     tty.c_iflag &= ~INLCR;
@@ -122,7 +124,7 @@ back_to_col_1()
     (void) tcsetattr(SHOUT, TCSANOW, &tty);
     (void) write(SHOUT, "\r", 1);
     (void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
     (void) tcsetattr(SHOUT, TCSANOW, &tty);
     (void) write(SHOUT, "\r", 1);
     (void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
 }
 
 /*
 }
 
 /*
@@ -134,10 +136,12 @@ pushback(string)
 {
     register Char *p;
     struct termios tty, tty_normal;
 {
     register Char *p;
     struct termios tty, tty_normal;
-    int     omask;
+    sigset_t sigset, osigset;
     char    c;
 
     char    c;
 
-    omask = sigblock(sigmask(SIGINT));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGINT);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     (void) tcgetattr(SHOUT, &tty);
     tty_normal = tty;
     tty.c_lflag &= ~(ECHOKE | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOCTL);
     (void) tcgetattr(SHOUT, &tty);
     tty_normal = tty;
     tty.c_lflag &= ~(ECHOKE | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOCTL);
@@ -146,7 +150,7 @@ pushback(string)
     for (p = string; (c = *p) != '\0'; p++)
        (void) ioctl(SHOUT, TIOCSTI, (ioctl_t) & c);
     (void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
     for (p = string; (c = *p) != '\0'; p++)
        (void) ioctl(SHOUT, TIOCSTI, (ioctl_t) & c);
     (void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
 }
 
 /*
 }
 
 /*
@@ -390,12 +394,14 @@ free_items(items)
 }
 
 #define FREE_ITEMS(items) { \
 }
 
 #define FREE_ITEMS(items) { \
-       int omask;\
+       sigset_t sigset, osigset;\
 \
 \
-       omask = sigblock(sigmask(SIGINT));\
+       sigemptyset(&sigset);\
+       sigaddset(&sigset, SIGINT);\
+       sigprocmask(SIG_BLOCK, &sigset, &osigset);\
        free_items(items);\
        items = NULL;\
        free_items(items);\
        items = NULL;\
-       (void) sigsetmask(omask);\
+       sigprocmask(SIG_SETMASK, &osigset, NULL);\
 }
 
 /*
 }
 
 /*
index 7755076..0d26455 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)func.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)func.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -107,6 +107,7 @@ doonintr(v, t)
 {
     register Char *cp;
     register Char *vv = v[1];
 {
     register Char *cp;
     register Char *vv = v[1];
+    sigset_t sigset;
 
     if (parintr == SIG_IGN)
        return;
 
     if (parintr == SIG_IGN)
        return;
@@ -116,9 +117,11 @@ doonintr(v, t)
     gointr = 0;
     xfree((ptr_t) cp);
     if (vv == 0) {
     gointr = 0;
     xfree((ptr_t) cp);
     if (vv == 0) {
-       if (setintr)
-           (void) sigblock(sigmask(SIGINT));
-       else
+       if (setintr) {
+           sigemptyset(&sigset);
+           sigaddset(&sigset, SIGINT);
+           sigprocmask(SIG_BLOCK, &sigset, NULL);
+       } else
            (void) signal(SIGINT, SIG_DFL);
        gointr = 0;
     }
            (void) signal(SIGINT, SIG_DFL);
        gointr = 0;
     }
@@ -477,13 +480,18 @@ dowhile(v, t)
 static void
 preread()
 {
 static void
 preread()
 {
+    sigset_t sigset;
+
     whyles->w_end.type = I_SEEK;
     whyles->w_end.type = I_SEEK;
-    if (setintr)
-       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+    }
 
     search(T_BREAK, 0, NULL);          /* read the expression in */
     if (setintr)
 
     search(T_BREAK, 0, NULL);          /* read the expression in */
     if (setintr)
-       (void) sigblock(sigmask(SIGINT));
+       sigprocmask(SIG_BLOCK, &sigset, NULL);
     btell(&whyles->w_end);
 }
 
     btell(&whyles->w_end);
 }
 
@@ -537,21 +545,24 @@ dorepeat(v, kp)
     struct command *kp;
 {
     register int i;
     struct command *kp;
 {
     register int i;
-    register sigset_t omask = 0;
+    sigset_t sigset;
 
     i = getn(v[1]);
 
     i = getn(v[1]);
-    if (setintr)
-       omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_BLOCK, &sigset, NULL);
+    }
     lshift(v, 2);
     while (i > 0) {
        if (setintr)
     lshift(v, 2);
     while (i > 0) {
        if (setintr)
-           (void) sigsetmask(omask);
+           sigprocmask(SIG_UNBLOCK, &sigset, NULL);
        reexecute(kp);
        --i;
     }
     donefds();
     if (setintr)
        reexecute(kp);
        --i;
     }
     donefds();
     if (setintr)
-       (void) sigsetmask(omask);
+       sigprocmask(SIG_UNBLOCK, &sigset, NULL);
 }
 
 void
 }
 
 void
@@ -877,9 +888,13 @@ xecho(sep, v)
 {
     register Char *cp;
     int     nonl = 0;
 {
     register Char *cp;
     int     nonl = 0;
+    sigset_t sigset;
 
 
-    if (setintr)
-       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+    }
     v++;
     if (*v == 0)
        return;
     v++;
     if (*v == 0)
        return;
@@ -909,7 +924,7 @@ xecho(sep, v)
     else
        (void) fflush(cshout);
     if (setintr)
     else
        (void) fflush(cshout);
     if (setintr)
-       (void) sigblock(sigmask(SIGINT));
+       sigprocmask(SIG_BLOCK, &sigset, NULL);
     if (gargv)
        blkfree(gargv), gargv = 0;
 }
     if (gargv)
        blkfree(gargv), gargv = 0;
 }
@@ -921,13 +936,17 @@ dosetenv(v, t)
     struct command *t;
 {
     Char   *vp, *lp;
     struct command *t;
 {
     Char   *vp, *lp;
+    sigset_t sigset;
 
     v++;
     if ((vp = *v++) == 0) {
        register Char **ep;
 
 
     v++;
     if ((vp = *v++) == 0) {
        register Char **ep;
 
-       if (setintr)
-           (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+       if (setintr) {
+           sigemptyset(&sigset);
+           sigaddset(&sigset, SIGINT);
+           sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+       }
        for (ep = STR_environ; *ep; ep++)
            (void) fprintf(cshout, "%s\n", vis_str(*ep));
        return;
        for (ep = STR_environ; *ep; ep++)
            (void) fprintf(cshout, "%s\n", vis_str(*ep));
        return;
index 5f54970..5f5b44d 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)hist.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)hist.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -95,11 +95,15 @@ dohist(v, t)
     struct command *t;
 {
     int     n, rflg = 0, hflg = 0;
     struct command *t;
 {
     int     n, rflg = 0, hflg = 0;
+    sigset_t sigset;
 
     if (getn(value(STRhistory)) == 0)
        return;
 
     if (getn(value(STRhistory)) == 0)
        return;
-    if (setintr)
-       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+    }
     while (*++v && **v == '-') {
        Char   *vp = *v;
 
     while (*++v && **v == '-') {
        Char   *vp = *v;
 
index aae2cb0..768ec69 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)proc.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)proc.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -175,17 +175,19 @@ pnote()
 {
     register struct process *pp;
     int     flags;
 {
     register struct process *pp;
     int     flags;
-    sigset_t omask;
+    sigset_t sigset, osigset;
 
     neednote = 0;
 
     neednote = 0;
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
     for (pp = proclist.p_next; pp != NULL; pp = pp->p_next) {
        if (pp->p_flags & PNEEDNOTE) {
     for (pp = proclist.p_next; pp != NULL; pp = pp->p_next) {
        if (pp->p_flags & PNEEDNOTE) {
-           omask = sigblock(sigmask(SIGCHLD));
+           sigprocmask(SIG_BLOCK, &sigset, &osigset);
            pp->p_flags &= ~PNEEDNOTE;
            flags = pprint(pp, NUMBER | NAME | REASON);
            if ((flags & (PRUNNING | PSTOPPED)) == 0)
                pflush(pp);
            pp->p_flags &= ~PNEEDNOTE;
            flags = pprint(pp, NUMBER | NAME | REASON);
            if ((flags & (PRUNNING | PSTOPPED)) == 0)
                pflush(pp);
-           (void) sigsetmask(omask);
+           sigprocmask(SIG_SETMASK, &osigset, NULL);
        }
     }
 }
        }
     }
 }
@@ -198,12 +200,14 @@ void
 pwait()
 {
     register struct process *fp, *pp;
 pwait()
 {
     register struct process *fp, *pp;
-    sigset_t omask;
+    sigset_t sigset, osigset;
 
     /*
      * Here's where dead procs get flushed.
      */
 
     /*
      * Here's where dead procs get flushed.
      */
-    omask = sigblock(sigmask(SIGCHLD));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     for (pp = (fp = &proclist)->p_next; pp != NULL; pp = (fp = pp)->p_next)
        if (pp->p_pid == 0) {
            fp->p_next = pp->p_next;
     for (pp = (fp = &proclist)->p_next; pp != NULL; pp = (fp = pp)->p_next)
        if (pp->p_pid == 0) {
            fp->p_next = pp->p_next;
@@ -214,7 +218,7 @@ pwait()
            xfree((ptr_t) pp);
            pp = fp;
        }
            xfree((ptr_t) pp);
            pp = fp;
        }
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
     pjwait(pcurrjob);
 }
 
     pjwait(pcurrjob);
 }
 
@@ -229,7 +233,7 @@ pjwait(pp)
 {
     register struct process *fp;
     int     jobflags, reason;
 {
     register struct process *fp;
     int     jobflags, reason;
-    sigset_t omask;
+    sigset_t sigset, osigset;
 
     while (pp->p_pid != pp->p_jobid)
        pp = pp->p_friends;
 
     while (pp->p_pid != pp->p_jobid)
        pp = pp->p_friends;
@@ -244,9 +248,13 @@ pjwait(pp)
      * target process, or any of its friends, are running
      */
     fp = pp;
      * target process, or any of its friends, are running
      */
     fp = pp;
-    omask = sigblock(sigmask(SIGCHLD));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     for (;;) {
     for (;;) {
-       (void) sigblock(sigmask(SIGCHLD));
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGCHLD);
+       sigprocmask(SIG_BLOCK, &sigset, NULL);
        jobflags = 0;
        do
            jobflags |= fp->p_flags;
        jobflags = 0;
        do
            jobflags |= fp->p_flags;
@@ -254,12 +262,14 @@ pjwait(pp)
        if ((jobflags & PRUNNING) == 0)
            break;
 #ifdef JOBDEBUG
        if ((jobflags & PRUNNING) == 0)
            break;
 #ifdef JOBDEBUG
-       (void) fprintf(csherr, "starting to sigpause for  SIGCHLD on %d\n",
+       (void) fprintf(csherr, "starting to sigsuspend for  SIGCHLD on %d\n",
                       fp->p_pid);
 #endif                         /* JOBDEBUG */
                       fp->p_pid);
 #endif                         /* JOBDEBUG */
-       (void) sigpause(omask & ~sigmask(SIGCHLD));
+       sigset = osigset;
+       sigdelset(&sigset, SIGCHLD);
+       sigsuspend(&sigset);
     }
     }
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
     if (tpgrp > 0)             /* get tty back */
        (void) tcsetpgrp(FSHTTY, tpgrp);
     if ((jobflags & (PSIGNALED | PSTOPPED | PTIME)) ||
     if (tpgrp > 0)             /* get tty back */
        (void) tcsetpgrp(FSHTTY, tpgrp);
     if ((jobflags & (PSIGNALED | PSTOPPED | PTIME)) ||
@@ -318,18 +328,21 @@ dowait(v, t)
     struct command *t;
 {
     register struct process *pp;
     struct command *t;
 {
     register struct process *pp;
-    sigset_t omask;
+    sigset_t sigset, osigset;
 
     pjobs++;
 
     pjobs++;
-    omask = sigblock(sigmask(SIGCHLD));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
 loop:
     for (pp = proclist.p_next; pp; pp = pp->p_next)
        if (pp->p_pid &&        /* pp->p_pid == pp->p_jobid && */
            pp->p_flags & PRUNNING) {
 loop:
     for (pp = proclist.p_next; pp; pp = pp->p_next)
        if (pp->p_pid &&        /* pp->p_pid == pp->p_jobid && */
            pp->p_flags & PRUNNING) {
-           (void) sigpause((sigset_t) 0);
+           sigemptyset(&sigset);
+           sigsuspend(&sigset);
            goto loop;
        }
            goto loop;
        }
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
     pjobs = 0;
 }
 
     pjobs = 0;
 }
 
@@ -973,13 +986,14 @@ pkill(v, signum)
     register struct process *pp, *np;
     register int jobflags = 0;
     int     pid, err1 = 0;
     register struct process *pp, *np;
     register int jobflags = 0;
     int     pid, err1 = 0;
-    sigset_t omask;
+    sigset_t sigset;
     Char   *cp;
 
     Char   *cp;
 
-    omask = sigmask(SIGCHLD);
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
     if (setintr)
     if (setintr)
-       omask |= sigmask(SIGINT);
-    omask = sigblock(omask) & ~omask;
+       sigaddset(&sigset, SIGINT);
+    sigprocmask(SIG_BLOCK, &sigset, NULL);
     gflag = 0, tglob(v);
     if (gflag) {
        v = globall(v);
     gflag = 0, tglob(v);
     if (gflag) {
        v = globall(v);
@@ -1043,7 +1057,7 @@ cont:
     }
     if (gargv)
        blkfree(gargv), gargv = 0;
     }
     if (gargv)
        blkfree(gargv), gargv = 0;
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_UNBLOCK, &sigset, NULL);
     if (err1)
        stderror(ERR_SILENT);
 }
     if (err1)
        stderror(ERR_SILENT);
 }
@@ -1057,10 +1071,12 @@ pstart(pp, foregnd)
     int     foregnd;
 {
     register struct process *np;
     int     foregnd;
 {
     register struct process *np;
-    sigset_t omask;
+    sigset_t sigset, osigset;
     long    jobflags = 0;
 
     long    jobflags = 0;
 
-    omask = sigblock(sigmask(SIGCHLD));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     np = pp;
     do {
        jobflags |= np->p_flags;
     np = pp;
     do {
        jobflags |= np->p_flags;
@@ -1080,7 +1096,7 @@ pstart(pp, foregnd)
        (void) tcsetpgrp(FSHTTY, pp->p_jobid);
     if (jobflags & PSTOPPED)
        (void) killpg((pid_t) pp->p_jobid, SIGCONT);
        (void) tcsetpgrp(FSHTTY, pp->p_jobid);
     if (jobflags & PSTOPPED)
        (void) killpg((pid_t) pp->p_jobid, SIGCONT);
-    (void) sigsetmask(omask);
+    sigprocmask(SIG_SETMASK, &osigset, NULL);
 }
 
 void
 }
 
 void
@@ -1203,7 +1219,7 @@ pfork(t, wanttty)
     register int pid;
     bool    ignint = 0;
     int     pgrp;
     register int pid;
     bool    ignint = 0;
     int     pgrp;
-    sigset_t omask;
+    sigset_t sigset, osigset;
 
     /*
      * A child will be uninterruptible only under very special conditions.
 
     /*
      * A child will be uninterruptible only under very special conditions.
@@ -1224,12 +1240,14 @@ pfork(t, wanttty)
     /*
      * Hold SIGCHLD until we have the process installed in our table.
      */
     /*
      * Hold SIGCHLD until we have the process installed in our table.
      */
-    omask = sigblock(sigmask(SIGCHLD));
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGCHLD);
+    sigprocmask(SIG_BLOCK, &sigset, &osigset);
     while ((pid = fork()) < 0)
        if (setintr == 0)
            (void) sleep(FORKSLEEP);
        else {
     while ((pid = fork()) < 0)
        if (setintr == 0)
            (void) sleep(FORKSLEEP);
        else {
-           (void) sigsetmask(omask);
+           sigprocmask(SIG_SETMASK, &osigset, NULL);
            stderror(ERR_NOPROC);
        }
     if (pid == 0) {
            stderror(ERR_NOPROC);
        }
     if (pid == 0) {
@@ -1273,7 +1291,7 @@ pfork(t, wanttty)
        if (wanttty >= 0)
            (void) setpgid(pid, pcurrjob ? pcurrjob->p_jobid : pid);
        palloc(pid, t);
        if (wanttty >= 0)
            (void) setpgid(pid, pcurrjob ? pcurrjob->p_jobid : pid);
        palloc(pid, t);
-       (void) sigsetmask(omask);
+       sigprocmask(SIG_SETMASK, &osigset, NULL);
     }
 
     return (pid);
     }
 
     return (pid);
@@ -1300,14 +1318,19 @@ void
 pgetty(wanttty, pgrp)
     int     wanttty, pgrp;
 {
 pgetty(wanttty, pgrp)
     int     wanttty, pgrp;
 {
-    sigset_t omask = 0;
+    sigset_t sigset, osigset;
 
     /*
      * christos: I am blocking the tty signals till I've set things
      * correctly....
      */
 
     /*
      * christos: I am blocking the tty signals till I've set things
      * correctly....
      */
-    if (wanttty > 0)
-       omask = sigblock(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU));
+    if (wanttty > 0) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGTSTP);
+       sigaddset(&sigset, SIGTTIN);
+       sigaddset(&sigset, SIGTTOU);
+       sigprocmask(SIG_BLOCK, &sigset, &osigset);
+    }
     /*
      * From: Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
      * Don't check for tpgrp >= 0 so even non-interactive shells give
     /*
      * From: Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
      * Don't check for tpgrp >= 0 so even non-interactive shells give
@@ -1322,7 +1345,7 @@ pgetty(wanttty, pgrp)
 
     if (wanttty > 0) {
        (void) tcsetpgrp(FSHTTY, pgrp);
 
     if (wanttty > 0) {
        (void) tcsetpgrp(FSHTTY, pgrp);
-       (void) sigsetmask(omask);
+       sigprocmask(SIG_SETMASK, &osigset, NULL);
     }
 
     if (tpgrp > 0)
     }
 
     if (tpgrp > 0)
index 0a84489..14ab192 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)sem.c      8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)sem.c      8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -41,10 +41,11 @@ execute(t, wanttty, pipein, pipeout)
     struct biltins *bifunc;
     int     pid = 0;
     int     pv[2];
     struct biltins *bifunc;
     int     pid = 0;
     int     pv[2];
+    sigset_t sigset;
 
 
-    static sigset_t csigmask;
+    static sigset_t csigset;
 
 
-    static sigset_t ocsigmask;
+    static sigset_t ocsigset;
     static int onosigchld = 0;
     static int nosigchld = 0;
 
     static int onosigchld = 0;
     static int nosigchld = 0;
 
@@ -182,13 +183,15 @@ execute(t, wanttty, pipein, pipeout)
                 * not die before we can set the process group
                 */
                if (wanttty >= 0 && !nosigchld) {
                 * not die before we can set the process group
                 */
                if (wanttty >= 0 && !nosigchld) {
-                   csigmask = sigblock(sigmask(SIGCHLD));
+                   sigemptyset(&sigset);
+                   sigaddset(&sigset, SIGCHLD);
+                   sigprocmask(SIG_BLOCK, &sigset, &csigset);
                    nosigchld = 1;
                }
 
                pid = pfork(t, wanttty);
                if (pid == 0 && nosigchld) {
                    nosigchld = 1;
                }
 
                pid = pfork(t, wanttty);
                if (pid == 0 && nosigchld) {
-                   (void) sigsetmask(csigmask);
+                   sigprocmask(SIG_SETMASK, &csigset, NULL);
                    nosigchld = 0;
                }
                else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
                    nosigchld = 0;
                }
                else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
@@ -198,21 +201,26 @@ execute(t, wanttty, pipein, pipeout)
            else {
                int     ochild, osetintr, ohaderr, odidfds;
                int     oSHIN, oSHOUT, oSHERR, oOLDSTD, otpgrp;
            else {
                int     ochild, osetintr, ohaderr, odidfds;
                int     oSHIN, oSHOUT, oSHERR, oOLDSTD, otpgrp;
-               sigset_t omask;
+               sigset_t osigset;
 
                /*
                 * Prepare for the vfork by saving everything that the child
                 * corrupts before it exec's. Note that in some signal
                 * implementations which keep the signal info in user space
                 * (e.g. Sun's) it will also be necessary to save and restore
 
                /*
                 * Prepare for the vfork by saving everything that the child
                 * corrupts before it exec's. Note that in some signal
                 * implementations which keep the signal info in user space
                 * (e.g. Sun's) it will also be necessary to save and restore
-                * the current sigvec's for the signals the child touches
+                * the current sigaction's for the signals the child touches
                 * before it exec's.
                 */
                if (wanttty >= 0 && !nosigchld && !noexec) {
                 * before it exec's.
                 */
                if (wanttty >= 0 && !nosigchld && !noexec) {
-                   csigmask = sigblock(sigmask(SIGCHLD));
+                   sigemptyset(&sigset);
+                   sigaddset(&sigset, SIGCHLD);
+                   sigprocmask(SIG_BLOCK, &sigset, &csigset);
                    nosigchld = 1;
                }
                    nosigchld = 1;
                }
-               omask = sigblock(sigmask(SIGCHLD) | sigmask(SIGINT));
+               sigemptyset(&sigset);
+               sigaddset(&sigset, SIGCHLD);
+               sigaddset(&sigset, SIGINT);
+               sigprocmask(SIG_BLOCK, &sigset, &osigset);
                ochild = child;
                osetintr = setintr;
                ohaderr = haderr;
                ochild = child;
                osetintr = setintr;
                ohaderr = haderr;
@@ -222,7 +230,7 @@ execute(t, wanttty, pipein, pipeout)
                oSHERR = SHERR;
                oOLDSTD = OLDSTD;
                otpgrp = tpgrp;
                oSHERR = SHERR;
                oOLDSTD = OLDSTD;
                otpgrp = tpgrp;
-               ocsigmask = csigmask;
+               ocsigset = csigset;
                onosigchld = nosigchld;
                Vsav = Vdp = 0;
                Vexpath = 0;
                onosigchld = nosigchld;
                Vsav = Vdp = 0;
                Vexpath = 0;
@@ -230,7 +238,7 @@ execute(t, wanttty, pipein, pipeout)
                pid = vfork();
 
                if (pid < 0) {
                pid = vfork();
 
                if (pid < 0) {
-                   (void) sigsetmask(omask);
+                   sigprocmask(SIG_SETMASK, &osigset, NULL);
                    stderror(ERR_NOPROC);
                }
                forked++;
                    stderror(ERR_NOPROC);
                }
                forked++;
@@ -244,7 +252,7 @@ execute(t, wanttty, pipein, pipeout)
                    SHERR = oSHERR;
                    OLDSTD = oOLDSTD;
                    tpgrp = otpgrp;
                    SHERR = oSHERR;
                    OLDSTD = oOLDSTD;
                    tpgrp = otpgrp;
-                   csigmask = ocsigmask;
+                   csigset = ocsigset;
                    nosigchld = onosigchld;
 
                    xfree((ptr_t) Vsav);
                    nosigchld = onosigchld;
 
                    xfree((ptr_t) Vsav);
@@ -257,7 +265,7 @@ execute(t, wanttty, pipein, pipeout)
                    Vt = 0;
                    /* this is from pfork() */
                    palloc(pid, t);
                    Vt = 0;
                    /* this is from pfork() */
                    palloc(pid, t);
-                   (void) sigsetmask(omask);
+                   sigprocmask(SIG_SETMASK, &osigset, NULL);
                }
                else {          /* child */
                    /* this is from pfork() */
                }
                else {          /* child */
                    /* this is from pfork() */
@@ -265,7 +273,7 @@ execute(t, wanttty, pipein, pipeout)
                    bool    ignint = 0;
 
                    if (nosigchld) {
                    bool    ignint = 0;
 
                    if (nosigchld) {
-                       (void) sigsetmask(csigmask);
+                       sigprocmask(SIG_SETMASK, &csigset, NULL);
                        nosigchld = 0;
                    }
 
                        nosigchld = 0;
                    }
 
@@ -322,7 +330,7 @@ execute(t, wanttty, pipein, pipeout)
            }
            if ((t->t_dflg & F_PIPEOUT) == 0) {
                if (nosigchld) {
            }
            if ((t->t_dflg & F_PIPEOUT) == 0) {
                if (nosigchld) {
-                   (void) sigsetmask(csigmask);
+                   sigprocmask(SIG_SETMASK, &csigset, NULL);
                    nosigchld = 0;
                }
                if ((t->t_dflg & F_AMPERSAND) == 0)
                    nosigchld = 0;
                }
                if ((t->t_dflg & F_AMPERSAND) == 0)
index c1221ad..aabf05d 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)set.c      8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)set.c      8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -787,9 +787,13 @@ plist(p)
 {
     register struct varent *c;
     register len;
 {
     register struct varent *c;
     register len;
+    sigset_t sigset;
 
 
-    if (setintr)
-       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+    }
 
     for (;;) {
        while (p->v_left)
 
     for (;;) {
        while (p->v_left)