use new signal calls instead of compatibility routines.
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 1 Sep 1984 00:32:45 +0000 (16:32 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 1 Sep 1984 00:32:45 +0000 (16:32 -0800)
SCCS-vsn: bin/csh/csh.c 4.18
SCCS-vsn: bin/csh/exec.c 4.9
SCCS-vsn: bin/csh/hist.c 4.7
SCCS-vsn: bin/csh/proc.c 4.13
SCCS-vsn: bin/csh/misc.c 4.3
SCCS-vsn: bin/csh/sem.c 4.4
SCCS-vsn: bin/csh/set.c 4.3
SCCS-vsn: bin/csh/glob.c 4.6
SCCS-vsn: bin/csh/func.c 4.12
SCCS-vsn: bin/csh/file.c 1.3
SCCS-vsn: bin/csh/csh.h 4.11

usr/src/bin/csh/csh.c
usr/src/bin/csh/csh.h
usr/src/bin/csh/exec.c
usr/src/bin/csh/file.c
usr/src/bin/csh/func.c
usr/src/bin/csh/glob.c
usr/src/bin/csh/hist.c
usr/src/bin/csh/misc.c
usr/src/bin/csh/proc.c
usr/src/bin/csh/sem.c
usr/src/bin/csh/set.c

index bdf1e2d..7db93cf 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)csh.c 4.17 %G%";
+static char *sccsid = "@(#)csh.c 4.18 %G%";
 
 #include "sh.h"
 #include <sys/ioctl.h>
 
 #include "sh.h"
 #include <sys/ioctl.h>
@@ -32,13 +32,14 @@ main(c, av)
 {
        register char **v, *cp;
        register int f;
 {
        register char **v, *cp;
        register int f;
+       struct sigvec osv;
 
        settimes();                     /* Immed. estab. timing base */
        v = av;
        if (eq(v[0], "a.out"))          /* A.out's are quittable */
                quitit = 1;
        uid = getuid();
 
        settimes();                     /* Immed. estab. timing base */
        v = av;
        if (eq(v[0], "a.out"))          /* A.out's are quittable */
                quitit = 1;
        uid = getuid();
-       loginsh = **v == '-';
+       loginsh = **v == '-' && c == 1;
        if (loginsh)
                time(&chktim);
 
        if (loginsh)
                time(&chktim);
 
@@ -110,10 +111,10 @@ main(c, av)
         * Our children inherit termination from our parent.
         * We catch it only if we are the login shell.
         */
         * Our children inherit termination from our parent.
         * We catch it only if we are the login shell.
         */
-       parintr = signal(SIGINT, SIG_IGN);      /* parents interruptibility */
-       sigset(SIGINT, parintr);                        /* ... restore */
-       parterm = signal(SIGTERM, SIG_IGN);     /* parents terminability */
-       signal(SIGTERM, parterm);                       /* ... restore */
+       sigvec(SIGINT, 0, &osv);                /* parents interruptibility */
+       parintr = osv.sv_handler;
+       sigvec(SIGTERM, 0, &osv);               /* parents terminability */
+       parterm = osv.sv_handler;
        if (loginsh) {
                signal(SIGHUP, phup);           /* exit processing on HUP */
                signal(SIGXCPU, phup);          /* ...and on XCPU */
        if (loginsh) {
                signal(SIGHUP, phup);           /* exit processing on HUP */
                signal(SIGXCPU, phup);          /* ...and on XCPU */
@@ -132,14 +133,9 @@ main(c, av)
         */
        c--, v++;
        while (c > 0 && (cp = v[0])[0] == '-') {
         */
        c--, v++;
        while (c > 0 && (cp = v[0])[0] == '-') {
+               cp++;
                do switch (*cp++) {
 
                do switch (*cp++) {
 
-               case 0:                 /* -    Interruptible, no prompt */
-                       prompt = 0;
-                       setintr++;
-                       nofile++;
-                       break;
-
                case 'c':               /* -c   Command input from arg */
                        if (c == 1)
                                exit(0);
                case 'c':               /* -c   Command input from arg */
                        if (c == 1)
                                exit(0);
@@ -258,8 +254,8 @@ main(c, av)
                **av = '-';
                if (!quitit)            /* Wary! */
                        signal(SIGQUIT, SIG_IGN);
                **av = '-';
                if (!quitit)            /* Wary! */
                        signal(SIGQUIT, SIG_IGN);
-               sigset(SIGINT, pintr);
-               sighold(SIGINT);
+               signal(SIGINT, pintr);
+               sigblock(sigmask(SIGINT));
                signal(SIGTERM, SIG_IGN);
                if (quitit == 0 && arginp == 0) {
                        signal(SIGTSTP, SIG_IGN);
                signal(SIGTERM, SIG_IGN);
                if (quitit == 0 && arginp == 0) {
                        signal(SIGTSTP, SIG_IGN);
@@ -283,9 +279,9 @@ retry:
                        if (ioctl(f, TIOCGPGRP, &tpgrp) == 0 && tpgrp != -1) {
                                int ldisc;
                                if (tpgrp != shpgrp) {
                        if (ioctl(f, TIOCGPGRP, &tpgrp) == 0 && tpgrp != -1) {
                                int ldisc;
                                if (tpgrp != shpgrp) {
-                                       int (*old)() = sigsys(SIGTTIN, SIG_DFL);
+                                       int (*old)() = signal(SIGTTIN, SIG_DFL);
                                        kill(0, SIGTTIN);
                                        kill(0, SIGTTIN);
-                                       sigsys(SIGTTIN, old);
+                                       signal(SIGTTIN, old);
                                        goto retry;
                                }
                                if (ioctl(f, TIOCGETD, &oldisc) != 0) 
                                        goto retry;
                                }
                                if (ioctl(f, TIOCGETD, &oldisc) != 0) 
@@ -314,7 +310,7 @@ notty:
        }
        if (setintr == 0 && parintr == SIG_DFL)
                setintr++;
        }
        if (setintr == 0 && parintr == SIG_DFL)
                setintr++;
-       sigset(SIGCHLD, pchild);                /* while signals not ready */
+       signal(SIGCHLD, pchild);        /* while signals not ready */
 
        /*
         * Set an exit here in case of an interrupt or error reading
 
        /*
         * Set an exit here in case of an interrupt or error reading
@@ -458,7 +454,7 @@ srcunit(unit, onlyown, hflg)
 
        /* The (few) real local variables */
        jmp_buf oldexit;
 
        /* The (few) real local variables */
        jmp_buf oldexit;
-       int reenter;
+       int reenter, omask;
 
        if (unit < 0)
                return;
 
        if (unit < 0)
                return;
@@ -488,7 +484,7 @@ srcunit(unit, onlyown, hflg)
        getexit(oldexit);
        reenter = 0;
        if (setintr)
        getexit(oldexit);
        reenter = 0;
        if (setintr)
-               sighold(SIGINT);
+               omask = sigblock(sigmask(SIGINT));
        setexit();
        reenter++;
        if (reenter == 1) {
        setexit();
        reenter++;
        if (reenter == 1) {
@@ -507,14 +503,14 @@ srcunit(unit, onlyown, hflg)
                 * we let ourselves be interrupted.
                 */
                if (setintr)
                 * we let ourselves be interrupted.
                 */
                if (setintr)
-                       sigrelse(SIGINT);
+                       sigsetmask(omask);
 #ifdef TELL
                settell();
 #endif
                process(0);             /* 0 -> blow away on errors */
        }
        if (setintr)
 #ifdef TELL
                settell();
 #endif
                process(0);             /* 0 -> blow away on errors */
        }
        if (setintr)
-               sigrelse(SIGINT);
+               sigsetmask(omask);
        if (oSHIN >= 0) {
                register int i;
 
        if (oSHIN >= 0) {
                register int i;
 
@@ -578,7 +574,7 @@ goodbye()
 {
        if (loginsh) {
                signal(SIGQUIT, SIG_IGN);
 {
        if (loginsh) {
                signal(SIGQUIT, SIG_IGN);
-               sigset(SIGINT, SIG_IGN);
+               signal(SIGINT, SIG_IGN);
                signal(SIGTERM, SIG_IGN);
                setintr = 0;            /* No interrupts after "logout" */
                if (adrof("home"))
                signal(SIGTERM, SIG_IGN);
                setintr = 0;            /* No interrupts after "logout" */
                if (adrof("home"))
@@ -626,9 +622,11 @@ pintr1(wantnl)
        bool wantnl;
 {
        register char **v;
        bool wantnl;
 {
        register char **v;
+       int omask;
 
 
+       omask = sigblock(0);
        if (setintr) {
        if (setintr) {
-               sigrelse(SIGINT);
+               sigsetmask(omask & ~sigmask(SIGINT));
                if (pjobs) {
                        pjobs = 0;
                        printf("\n");
                if (pjobs) {
                        pjobs = 0;
                        printf("\n");
@@ -636,9 +634,7 @@ pintr1(wantnl)
                        bferr("Interrupted");
                }
        }
                        bferr("Interrupted");
                }
        }
-       if (setintr)
-               sighold(SIGINT);
-       sigrelse(SIGCHLD);
+       sigsetmask(omask & ~sigmask(SIGCHLD));
        draino();
 
        /*
        draino();
 
        /*
@@ -693,7 +689,7 @@ process(catch)
                 * Interruptible during interactive reads
                 */
                if (setintr)
                 * Interruptible during interactive reads
                 */
                if (setintr)
-                       sigrelse(SIGINT);
+                       sigsetmask(sigblock(0) & ~sigmask(SIGINT));
 
                /*
                 * For the sake of reset()
 
                /*
                 * For the sake of reset()
@@ -757,7 +753,7 @@ process(catch)
                 * The parser may lose space if interrupted.
                 */
                if (setintr)
                 * The parser may lose space if interrupted.
                 */
                if (setintr)
-                       sighold(SIGINT);
+                       sigblock(sigmask(SIGINT));
 
                /*
                 * Save input text on the history list if 
 
                /*
                 * Save input text on the history list if 
index 90a019a..b2df042 100644 (file)
@@ -1,4 +1,4 @@
-/* csh.h 4.10 83/07/01 */
+/* csh.h 4.11 84/08/31 */
 
 #include "sh.local.h"
 #include <sys/time.h>
 
 #include "sh.local.h"
 #include <sys/time.h>
@@ -27,13 +27,6 @@ typedef      char    bool;
 
 #define        eq(a, b)        (strcmp(a, b) == 0)
 
 
 #define        eq(a, b)        (strcmp(a, b) == 0)
 
-/*
- * For 4.2bsd signals.
- */
-#define        mask(s)         (1 << ((s)-1))
-#define        sigsys(s, a)    signal(s, a)
-#define        sighold(s)      sigblock(mask(s))
-
 /*
  * Global flags
  */
 /*
  * Global flags
  */
index 0ffb744..c15bb07 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)exec.c 4.8 %G%";
+static char *sccsid = "@(#)exec.c 4.9 %G%";
 
 #include "sh.h"
 #include <sys/dir.h>
 
 #include "sh.h"
 #include <sys/dir.h>
index 4f83184..b263c7e 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)file.c 1.2 (Berkeley from Hp Labs) %G%";
+static char *sccsid = "@(#)file.c 1.3 (Berkeley from Hp Labs) %G%";
 
 /*
  * Tenex style file name recognition, .. and more.
 
 /*
  * Tenex style file name recognition, .. and more.
@@ -14,15 +14,6 @@ static       char *sccsid = "@(#)file.c 1.2 (Berkeley from Hp Labs) %G%";
 #include <signal.h>
 #include <pwd.h>
 
 #include <signal.h>
 #include <pwd.h>
 
-/*
- * For 4.2bsd signals.
- *
- * (can't include sh.h)
- */
-#define        mask(s)         (1 << ((s)-1))
-#define        sigsys(s, a)    signal(s, a)
-#define        sighold(s)      sigblock(mask(s))
-
 extern short SHIN, SHOUT;
 
 #define TRUE   1
 extern short SHIN, SHOUT;
 
 #define TRUE   1
@@ -42,7 +33,9 @@ static struct tchars  tchars;         /* INT, QUIT, XON, XOFF, EOF, BRK */
 static
 setup_tty (on)
 {
 static
 setup_tty (on)
 {
-    sigignore (SIGINT);
+    int omask;
+
+    omask = sigblock(sigmask(SIGINT));
     if (on)
     {
        struct sgttyb sgtty;
     if (on)
     {
        struct sgttyb sgtty;
@@ -68,7 +61,7 @@ setup_tty (on)
        tchars.t_brkc = -1;
        ioctl (SHIN, TIOCSETC, &tchars);
     }
        tchars.t_brkc = -1;
        ioctl (SHIN, TIOCSETC, &tchars);
     }
-    sigrelse (SIGINT);
+    sigsetmask (omask);
 }
 
 /*
 }
 
 /*
@@ -78,14 +71,16 @@ static
 back_to_col_1 ()
 {
     struct sgttyb tty, tty_normal;
 back_to_col_1 ()
 {
     struct sgttyb tty, tty_normal;
-    sigignore (SIGINT);
+    int omask;
+
+    omask = sigblock (sigmask(SIGINT));
     ioctl (SHIN, TIOCGETP, &tty);
     tty_normal = tty;
     tty.sg_flags &= ~CRMOD;
     ioctl (SHIN, TIOCSETN, &tty);
     (void) write (SHOUT, "\r", 1);
     ioctl (SHIN, TIOCSETN, &tty_normal);
     ioctl (SHIN, TIOCGETP, &tty);
     tty_normal = tty;
     tty.sg_flags &= ~CRMOD;
     ioctl (SHIN, TIOCSETN, &tty);
     (void) write (SHOUT, "\r", 1);
     ioctl (SHIN, TIOCSETN, &tty_normal);
-    sigrelse (SIGINT);
+    sigsetmask (omask);
 }
 
 /*
 }
 
 /*
@@ -97,8 +92,9 @@ char  *string;
 {
     register char  *p;
     struct sgttyb   tty, tty_normal;
 {
     register char  *p;
     struct sgttyb   tty, tty_normal;
+    int omask;
 
 
-    sigignore (SIGINT);
+    omask = sigblock (sigmask(SIGINT));
     ioctl (SHOUT, TIOCGETP, &tty);
     tty_normal = tty;
     tty.sg_flags &= ~ECHO;
     ioctl (SHOUT, TIOCGETP, &tty);
     tty_normal = tty;
     tty.sg_flags &= ~ECHO;
@@ -107,7 +103,7 @@ char  *string;
     for (p = string; *p; p++)
        ioctl (SHOUT, TIOCSTI, p);
     ioctl (SHOUT, TIOCSETN, &tty_normal);
     for (p = string; *p; p++)
        ioctl (SHOUT, TIOCSTI, p);
     ioctl (SHOUT, TIOCSETN, &tty_normal);
-    sigrelse (SIGINT);
+    sigsetmask (omask);
 }
 
 /*
 }
 
 /*
@@ -348,11 +344,11 @@ register char **items;
 }
 
 #define FREE_ITEMS(items)\
 }
 
 #define FREE_ITEMS(items)\
-{\
-    sighold (SIGINT);\
+{   int omask;\
+    omask = sigblock (sigmask(SIGINT));\
     free_items (items);\
     items = NULL;\
     free_items (items);\
     items = NULL;\
-    sigrelse (SIGINT);\
+    sigsetmask (omask);\
 }
 
 /*
 }
 
 /*
index 0ff5365..ff33004 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)func.c 4.11 84/07/03";
+static char *sccsid = "@(#)func.c 4.12 84/08/31";
 
 #include "sh.h"
 #include <sys/ioctl.h>
 
 #include "sh.h"
 #include <sys/ioctl.h>
@@ -75,16 +75,16 @@ doonintr(v)
        cp = gointr, gointr = 0, xfree(cp);
        if (vv == 0) {
                if (setintr)
        cp = gointr, gointr = 0, xfree(cp);
        if (vv == 0) {
                if (setintr)
-                       sighold(SIGINT);
+                       sigblock(sigmask(SIGINT));
                else
                else
-                       sigset(SIGINT, SIG_DFL);
+                       signal(SIGINT, SIG_DFL);
                gointr = 0;
        } else if (eq((vv = strip(vv)), "-")) {
                gointr = 0;
        } else if (eq((vv = strip(vv)), "-")) {
-               sigset(SIGINT, SIG_IGN);
+               signal(SIGINT, SIG_IGN);
                gointr = "-";
        } else {
                gointr = savestr(vv);
                gointr = "-";
        } else {
                gointr = savestr(vv);
-               sigset(SIGINT, pintr);
+               signal(SIGINT, pintr);
        }
 }
 
        }
 }
 
@@ -400,10 +400,10 @@ preread()
 
        whyles->w_end = -1;
        if (setintr)
 
        whyles->w_end = -1;
        if (setintr)
-               sigrelse(SIGINT);
+               sigsetmask(sigblock(0) & ~sigmask(SIGINT));
        search(ZBREAK, 0);
        if (setintr)
        search(ZBREAK, 0);
        if (setintr)
-               sighold(SIGINT);
+               sigblock(sigmask(SIGINT));
        whyles->w_end = btell();
 }
 
        whyles->w_end = btell();
 }
 
@@ -449,21 +449,21 @@ dorepeat(v, kp)
        char **v;
        struct command *kp;
 {
        char **v;
        struct command *kp;
 {
-       register int i;
+       register int i, omask;
 
        i = getn(v[1]);
        if (setintr)
 
        i = getn(v[1]);
        if (setintr)
-               sighold(SIGINT);
+               omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
        lshift(v, 2);
        while (i > 0) {
                if (setintr)
        lshift(v, 2);
        while (i > 0) {
                if (setintr)
-                       sigrelse(SIGINT);
+                       sigsetmask(omask);
                reexecute(kp);
                --i;
        }
        donefds();
        if (setintr)
                reexecute(kp);
                --i;
        }
        donefds();
        if (setintr)
-               sigrelse(SIGINT);
+               sigsetmask(omask);
 }
 
 doswbrk()
 }
 
 doswbrk()
@@ -699,7 +699,7 @@ echo(sep, v)
        int nonl = 0;
 
        if (setintr)
        int nonl = 0;
 
        if (setintr)
-               sigrelse(SIGINT);
+               sigsetmask(sigblock(0) & ~sigmask(SIGINT));
        v++;
        if (*v == 0)
                return;
        v++;
        if (*v == 0)
                return;
@@ -725,7 +725,7 @@ echo(sep, v)
        else
                flush();
        if (setintr)
        else
                flush();
        if (setintr)
-               sighold(SIGINT);
+               sigblock(sigmask(SIGINT));
        if (gargv)
                blkfree(gargv), gargv = 0;
 }
        if (gargv)
                blkfree(gargv), gargv = 0;
 }
@@ -1005,23 +1005,23 @@ setlim(lp, limit)
 
 dosuspend()
 {
 
 dosuspend()
 {
-       int (*old)(), ldisc;
-       int ctpgrp;
+       int ldisc, ctpgrp;
+       int (*old)();
 
        if (loginsh)
                error("Can't suspend a login shell (yet)");
        untty();
 
        if (loginsh)
                error("Can't suspend a login shell (yet)");
        untty();
-       old = sigsys(SIGTSTP, SIG_DFL);
+       old = signal(SIGTSTP, SIG_DFL);
        kill(0, SIGTSTP);
        /* the shell stops here */
        kill(0, SIGTSTP);
        /* the shell stops here */
-       sigsys(SIGTSTP, old);
+       signal(SIGTSTP, old);
        if (tpgrp != -1) {
 retry:
                ioctl(FSHTTY, TIOCGPGRP, &ctpgrp);
                if (ctpgrp != opgrp) {
        if (tpgrp != -1) {
 retry:
                ioctl(FSHTTY, TIOCGPGRP, &ctpgrp);
                if (ctpgrp != opgrp) {
-                       old = sigsys(SIGTTIN, SIG_DFL);
+                       old = signal(SIGTTIN, SIG_DFL);
                        kill(0, SIGTTIN);
                        kill(0, SIGTTIN);
-                       sigsys(SIGTTIN, old);
+                       signal(SIGTTIN, old);
                        goto retry;
                }
                ioctl(FSHTTY, TIOCSPGRP, &shpgrp);
                        goto retry;
                }
                ioctl(FSHTTY, TIOCSPGRP, &shpgrp);
index b2d90c9..4e87ad7 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)glob.c 4.5 %G%";
+static char *sccsid = "@(#)glob.c 4.6 %G%";
 
 #include "sh.h"
 #include <sys/dir.h>
 
 #include "sh.h"
 #include <sys/dir.h>
@@ -354,7 +354,7 @@ amatch(s, p)
                        return (scc == 0);
 
                default:
                        return (scc == 0);
 
                default:
-                       if (c != scc)
+                       if ((c & TRIM) != scc)
                                return (0);
                        continue;
 
                                return (0);
                        continue;
 
@@ -666,9 +666,9 @@ backeval(cp, literal)
                        error(err);
                if (t)
                        t->t_dflg |= FPAR;
                        error(err);
                if (t)
                        t->t_dflg |= FPAR;
-               sigignore(SIGTSTP);
-               sigignore(SIGTTIN);
-               sigignore(SIGTTOU);
+               signal(SIGTSTP, SIG_IGN);
+               signal(SIGTTIN, SIG_IGN);
+               signal(SIGTTOU, SIG_IGN);
                execute(t, -1);
                exitstat();
        }
                execute(t, -1);
                exitstat();
        }
index 64ed6ae..626c794 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)hist.c 4.6 %G%";
+static char *sccsid = "@(#)hist.c 4.7 %G%";
 
 #include "sh.h"
 
 
 #include "sh.h"
 
@@ -73,7 +73,7 @@ dohist(vp)
        if (getn(value("history")) == 0)
                return;
        if (setintr)
        if (getn(value("history")) == 0)
                return;
        if (setintr)
-               sigrelse(SIGINT);
+               sigsetmask(sigblock(0) & ~sigmask(SIGINT));
        vp++;
        while (*vp && *vp[0] == '-') {
                if (*vp && eq(*vp, "-h")) {
        vp++;
        while (*vp && *vp[0] == '-') {
                if (*vp && eq(*vp, "-h")) {
index 687e3ac..b60f27f 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)misc.c 4.2 %G%";
+static char *sccsid = "@(#)misc.c 4.3 %G%";
 
 #include "sh.h"
 
 
 #include "sh.h"
 
@@ -69,13 +69,6 @@ calloc(i, j)
        return (cp);
 }
 
        return (cp);
 }
 
-cfree(p)
-       char *p;
-{
-
-       free(p);
-}
-
 char **
 blkend(up)
        register char **up;
 char **
 blkend(up)
        register char **up;
index ee9735d..f47083f 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)proc.c      4.12 (Berkeley) 83/07/01";
+static char *sccsid = "@(#)proc.c      4.13 (Berkeley) 84/08/31";
 
 #include "sh.h"
 #include "sh.dir.h"
 
 #include "sh.h"
 #include "sh.dir.h"
@@ -139,17 +139,17 @@ found:
 pnote()
 {
        register struct process *pp;
 pnote()
 {
        register struct process *pp;
-       int flags;
+       int flags, omask;
 
        neednote = 0;
        for (pp = proclist.p_next; pp != PNULL; pp = pp->p_next) {
                if (pp->p_flags & PNEEDNOTE) {
 
        neednote = 0;
        for (pp = proclist.p_next; pp != PNULL; pp = pp->p_next) {
                if (pp->p_flags & PNEEDNOTE) {
-                       sighold(SIGCHLD);
+                       omask = sigblock(sigmask(SIGCHLD));
                        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);
-                       sigrelse(SIGCHLD);
+                       sigsetmask(omask);
                }
        }
 }
                }
        }
 }
@@ -161,11 +161,12 @@ pnote()
 pwait()
 {
        register struct process *fp, *pp;
 pwait()
 {
        register struct process *fp, *pp;
+       int omask;
 
        /*
         * Here's where dead procs get flushed.
         */
 
        /*
         * Here's where dead procs get flushed.
         */
-       sighold(SIGCHLD);
+       omask = sigblock(sigmask(SIGCHLD));
        for (pp = (fp = &proclist)->p_next; pp != PNULL; pp = (fp = pp)->p_next)
                if (pp->p_pid == 0) {
                        fp->p_next = pp->p_next;
        for (pp = (fp = &proclist)->p_next; pp != PNULL; pp = (fp = pp)->p_next)
                if (pp->p_pid == 0) {
                        fp->p_next = pp->p_next;
@@ -176,9 +177,7 @@ pwait()
                        xfree((char *)pp);
                        pp = fp;
                }
                        xfree((char *)pp);
                        pp = fp;
                }
-       sigrelse(SIGCHLD);
-       if (setintr)
-               sigignore(SIGINT);
+       sigsetmask(omask);
        pjwait(pcurrjob);
 }
 
        pjwait(pcurrjob);
 }
 
@@ -190,7 +189,11 @@ pjwait(pp)
        register struct process *pp;
 {
        register struct process *fp;
        register struct process *pp;
 {
        register struct process *fp;
-       int jobflags, reason;
+       int jobflags, reason, omask;
+       int (*old)();
+
+       if (setintr)
+               old = signal(SIGINT, SIG_IGN);
 
        while (pp->p_pid != pp->p_jobid)
                pp = pp->p_friends;
 
        while (pp->p_pid != pp->p_jobid)
                pp = pp->p_friends;
@@ -204,17 +207,17 @@ pjwait(pp)
         * and the target process, or any of its friends, are running
         */
        fp = pp;
         * and the target process, or any of its friends, are running
         */
        fp = pp;
+       omask = sigblock(sigmask(SIGCHLD));
        for (;;) {
        for (;;) {
-               sighold(SIGCHLD);
                jobflags = 0;
                do
                        jobflags |= fp->p_flags;
                jobflags = 0;
                do
                        jobflags |= fp->p_flags;
-               while((fp = (fp->p_friends)) != pp);
+               while ((fp = (fp->p_friends)) != pp);
                if ((jobflags & PRUNNING) == 0)
                        break;
                if ((jobflags & PRUNNING) == 0)
                        break;
-               sigpause(sigblock(0) &~ mask(SIGCHLD));
+               sigpause(0);
        }
        }
-       sigrelse(SIGCHLD);
+       sigsetmask(omask);
        if (tpgrp > 0)
                ioctl(FSHTTY, TIOCSPGRP, &tpgrp);       /* get tty back */
        if ((jobflags&(PSIGNALED|PSTOPPED|PTIME)) ||
        if (tpgrp > 0)
                ioctl(FSHTTY, TIOCSPGRP, &tpgrp);       /* get tty back */
        if ((jobflags&(PSIGNALED|PSTOPPED|PTIME)) ||
@@ -241,6 +244,8 @@ pjwait(pp)
        if (reason && exiterr)
                exitstat();
        pflush(pp);
        if (reason && exiterr)
                exitstat();
        pflush(pp);
+       if (setintr)
+               signal(SIGINT, old);
 }
 
 /*
 }
 
 /*
@@ -249,19 +254,18 @@ pjwait(pp)
 dowait()
 {
        register struct process *pp;
 dowait()
 {
        register struct process *pp;
+       int omask;
 
        pjobs++;
 
        pjobs++;
-       if (setintr)
-               sigrelse(SIGINT);
+       omask = sigblock(sigmask(SIGCHLD));
 loop:
 loop:
-       sighold(SIGCHLD);
        for (pp = proclist.p_next; pp; pp = pp->p_next)
                if (pp->p_pid && /* pp->p_pid == pp->p_jobid && */
                    pp->p_flags&PRUNNING) {
        for (pp = proclist.p_next; pp; pp = pp->p_next)
                if (pp->p_pid && /* pp->p_pid == pp->p_jobid && */
                    pp->p_flags&PRUNNING) {
-                       sigpause(sigblock(0) &~ mask(SIGCHLD));
+                       sigpause(0);
                        goto loop;
                }
                        goto loop;
                }
-       sigrelse(SIGCHLD);
+       sigsetmask(omask);
        pjobs = 0;
 }
 
        pjobs = 0;
 }
 
@@ -705,8 +709,6 @@ dofg(v)
        do {
                pp = pfind(*v);
                pstart(pp, 1);
        do {
                pp = pfind(*v);
                pstart(pp, 1);
-               if (setintr)
-                       sigignore(SIGINT);
                pjwait(pp);
        } while (*v && *++v);
 }
                pjwait(pp);
        } while (*v && *++v);
 }
@@ -722,8 +724,6 @@ dofg1(v)
        okpcntl();
        pp = pfind(v[0]);
        pstart(pp, 1);
        okpcntl();
        pp = pfind(v[0]);
        pstart(pp, 1);
-       if (setintr)
-               sigignore(SIGINT);
        pjwait(pp);
 }
 
        pjwait(pp);
 }
 
@@ -812,14 +812,14 @@ pkill(v, signum)
 {
        register struct process *pp, *np;
        register int jobflags = 0;
 {
        register struct process *pp, *np;
        register int jobflags = 0;
-       int pid;
+       int omask, pid, err = 0;
        char *cp;
        extern char *sys_errlist[];
        char *cp;
        extern char *sys_errlist[];
-       int err = 0;
 
 
+       omask = sigmask(SIGCHLD);
        if (setintr)
        if (setintr)
-               sighold(SIGINT);
-       sighold(SIGCHLD);
+               omask |= sigmask(SIGINT);
+       omask = sigblock(omask) & ~omask;
        while (*v) {
                cp = globone(*v);
                if (*cp == '%') {
        while (*v) {
                cp = globone(*v);
                if (*cp == '%') {
@@ -859,9 +859,7 @@ cont:
                xfree(cp);
                v++;
        }
                xfree(cp);
                v++;
        }
-       sigrelse(SIGCHLD);
-       if (setintr)
-               sigrelse(SIGINT);
+       sigsetmask(omask);
        if (err)
                error(NOSTR);
 }
        if (err)
                error(NOSTR);
 }
@@ -874,9 +872,9 @@ pstart(pp, foregnd)
        int foregnd;
 {
        register struct process *np;
        int foregnd;
 {
        register struct process *np;
-       int jobflags = 0;
+       int omask, jobflags = 0;
 
 
-       sighold(SIGCHLD);
+       omask = sigblock(sigmask(SIGCHLD));
        np = pp;
        do {
                jobflags |= np->p_flags;
        np = pp;
        do {
                jobflags |= np->p_flags;
@@ -896,7 +894,7 @@ pstart(pp, foregnd)
                ioctl(FSHTTY, TIOCSPGRP, &pp->p_jobid);
        if (jobflags&PSTOPPED)
                killpg(pp->p_jobid, SIGCONT);
                ioctl(FSHTTY, TIOCSPGRP, &pp->p_jobid);
        if (jobflags&PSTOPPED)
                killpg(pp->p_jobid, SIGCONT);
-       sigrelse(SIGCHLD);
+       sigsetmask(omask);
 }
 
 panystop(neednl)
 }
 
 panystop(neednl)
@@ -1008,7 +1006,7 @@ pfork(t, wanttty)
 {
        register int pid;
        bool ignint = 0;
 {
        register int pid;
        bool ignint = 0;
-       int pgrp;
+       int pgrp, omask;
 
        /*
         * A child will be uninterruptible only under very special
 
        /*
         * A child will be uninterruptible only under very special
@@ -1025,13 +1023,12 @@ 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.
         */
-       sighold(SIGCHLD);
+       omask = sigblock(sigmask(SIGCHLD));
        while ((pid = fork()) < 0)
                if (setintr == 0)
                        sleep(FORKSLEEP);
                else {
        while ((pid = fork()) < 0)
                if (setintr == 0)
                        sleep(FORKSLEEP);
                else {
-                       sigrelse(SIGINT);
-                       sigrelse(SIGCHLD);
+                       sigsetmask(omask);
                        error("No more processes");
                }
        if (pid == 0) {
                        error("No more processes");
                }
        if (pid == 0) {
@@ -1043,7 +1040,6 @@ pfork(t, wanttty)
                child++;
                if (setintr) {
                        setintr = 0;            /* until I think otherwise */
                child++;
                if (setintr) {
                        setintr = 0;            /* until I think otherwise */
-                       sigrelse(SIGCHLD);
                        /*
                         * Children just get blown away on SIGINT, SIGQUIT
                         * unless "onintr -" seen.
                        /*
                         * Children just get blown away on SIGINT, SIGQUIT
                         * unless "onintr -" seen.
@@ -1074,17 +1070,11 @@ pfork(t, wanttty)
                 */
                if (t->t_dflg & FNOHUP)
                        signal(SIGHUP, SIG_IGN);
                 */
                if (t->t_dflg & FNOHUP)
                        signal(SIGHUP, SIG_IGN);
-               if (t->t_dflg & FNICE) {
-/* sigh...
-                       nice(20);
-                       nice(-10);
-*/
-                       nice(t->t_nice);
-               }
-
+               if (t->t_dflg & FNICE)
+                       setpriority(PRIO_PROCESS, 0, t->t_nice);
        } else {
                palloc(pid, t);
        } else {
                palloc(pid, t);
-               sigrelse(SIGCHLD);
+               sigsetmask(omask);
        }
 
        return (pid);
        }
 
        return (pid);
index 53b77f2..88b475b 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)sem.c 4.3 %G%";
+static char *sccsid = "@(#)sem.c 4.4 %G%";
 
 #include "sh.h"
 #include "sh.proc.h"
 
 #include "sh.h"
 #include "sh.proc.h"
@@ -113,8 +113,9 @@ execute(t, wanttty, pipein, pipeout)
                        int vffree();
                        int ochild, osetintr, ohaderr, odidfds, odidcch;
                        int oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
                        int vffree();
                        int ochild, osetintr, ohaderr, odidfds, odidcch;
                        int oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
+                       int omask;
 
 
-                       sighold(SIGCHLD);
+                       omask = sigblock(sigmask(SIGCHLD));
                        ochild = child; osetintr = setintr;
                        ohaderr = haderr; odidfds = didfds; odidcch = didcch;
                        oSHIN = SHIN; oSHOUT = SHOUT;
                        ochild = child; osetintr = setintr;
                        ohaderr = haderr; odidfds = didfds; odidcch = didcch;
                        oSHIN = SHIN; oSHOUT = SHOUT;
@@ -122,7 +123,7 @@ execute(t, wanttty, pipein, pipeout)
                        Vsav = Vdp = 0; Vav = 0;
                        pid = vfork();
                        if (pid < 0) {
                        Vsav = Vdp = 0; Vav = 0;
                        pid = vfork();
                        if (pid < 0) {
-                               sigrelse(SIGCHLD);
+                               sigsetmask(omask);
                                error("No more processes");
                        }
                        forked++;
                                error("No more processes");
                        }
                        forked++;
@@ -137,7 +138,7 @@ execute(t, wanttty, pipein, pipeout)
                                xfree(Vav); Vav = 0;
                                /* this is from pfork() */
                                palloc(pid, t);
                                xfree(Vav); Vav = 0;
                                /* this is from pfork() */
                                palloc(pid, t);
-                               sigrelse(SIGCHLD);
+                               sigsetmask(omask);
                        } else {
                                /* this is from pfork() */
                                int pgrp;
                        } else {
                                /* this is from pfork() */
                                int pgrp;
@@ -152,21 +153,21 @@ execute(t, wanttty, pipein, pipeout)
                                if (setintr) {
                                        setintr = 0;
 #ifdef notdef
                                if (setintr) {
                                        setintr = 0;
 #ifdef notdef
-                                       sigsys(SIGCHLD, SIG_DFL);
+                                       signal(SIGCHLD, SIG_DFL);
 #endif
 #endif
-                                       sigsys(SIGINT,
-                                           ignint ? SIG_IGN : vffree);
-                                       sigsys(SIGQUIT,
-                                           ignint ? SIG_IGN : SIG_DFL);
+                                       signal(SIGINT, ignint ?
+                                               SIG_IGN : vffree);
+                                       signal(SIGQUIT, ignint ?
+                                               SIG_IGN : SIG_DFL);
                                        if (wanttty >= 0) {
                                        if (wanttty >= 0) {
-                                               sigsys(SIGTSTP, SIG_DFL);
-                                               sigsys(SIGTTIN, SIG_DFL);
-                                               sigsys(SIGTTOU, SIG_DFL);
+                                               signal(SIGTSTP, SIG_DFL);
+                                               signal(SIGTTIN, SIG_DFL);
+                                               signal(SIGTTOU, SIG_DFL);
                                        }
                                        }
-                                       sigsys(SIGTERM, parterm);
+                                       signal(SIGTERM, parterm);
                                } else if (tpgrp == -1 && (t->t_dflg&FINT)) {
                                } else if (tpgrp == -1 && (t->t_dflg&FINT)) {
-                                       sigsys(SIGINT, SIG_IGN);
-                                       sigsys(SIGQUIT, SIG_IGN);
+                                       signal(SIGINT, SIG_IGN);
+                                       signal(SIGQUIT, SIG_IGN);
                                }
                                if (wanttty > 0)
                                        ioctl(FSHTTY, TIOCSPGRP, &pgrp);
                                }
                                if (wanttty > 0)
                                        ioctl(FSHTTY, TIOCSPGRP, &pgrp);
@@ -175,12 +176,12 @@ execute(t, wanttty, pipein, pipeout)
                                if (tpgrp > 0)
                                        tpgrp = 0;
                                if (t->t_dflg & FNOHUP)
                                if (tpgrp > 0)
                                        tpgrp = 0;
                                if (t->t_dflg & FNOHUP)
-                                       sigsys(SIGHUP, SIG_IGN);
+                                       signal(SIGHUP, SIG_IGN);
                                if (t->t_dflg & FNICE)
                                if (t->t_dflg & FNICE)
-                                       nice(t->t_nice);
+                                       setpriority(PRIO_PROCESS, 0, t->t_nice);
                        }
 
                        }
 
-               }
+                   }
 #endif
                if (pid != 0) {
                        /*
 #endif
                if (pid != 0) {
                        /*
index 4a3f6b5..6d6c48c 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)set.c 4.2 %G%";
+static char *sccsid = "@(#)set.c 4.3 %G%";
 
 #include "sh.h"
 
 
 #include "sh.h"
 
@@ -259,7 +259,7 @@ xfree(cp)
        extern char end[];
 
        if (cp >= end && cp < (char *) &cp)
        extern char end[];
 
        if (cp >= end && cp < (char *) &cp)
-               cfree(cp);
+               free(cp);
 }
 
 char *
 }
 
 char *