missing error return
[unix-history] / usr / src / sys / kern / kern_sig.c
index fa02ea3..614642a 100644 (file)
-/*     kern_sig.c      5.11    82/10/31        */
-
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/reg.h"
-#include "../h/inode.h"
-#include "../h/proc.h"
-#include "../h/timeb.h"
-#include "../h/times.h"
-#include "../h/conf.h"
-#include "../h/buf.h"
-#include "../h/mount.h"
-#include "../h/text.h"
-#include "../h/seg.h"
-#include "../h/pte.h"
-#include "../h/psl.h"
-#include "../h/vm.h"
-#include "../h/acct.h"
-#include "../h/uio.h"
-#include "../h/kernel.h"
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)kern_sig.c  6.21 (Berkeley) %G%
+ */
 
 
-/* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */
+#include "../machine/reg.h"
+#include "../machine/pte.h"
+#include "../machine/psl.h"
+
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "inode.h"
+#include "proc.h"
+#include "timeb.h"
+#include "times.h"
+#include "buf.h"
+#include "mount.h"
+#include "text.h"
+#include "seg.h"
+#include "vm.h"
+#include "acct.h"
+#include "uio.h"
+#include "kernel.h"
+
+#define        cantmask        (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP))
+#define        stopsigmask     (sigmask(SIGSTOP)|sigmask(SIGTSTP)| \
+                       sigmask(SIGTTIN)|sigmask(SIGTTOU))
 
 
+/*
+ * Generalized interface signal handler.
+ */
 sigvec()
 {
 sigvec()
 {
+       register struct a {
+               int     signo;
+               struct  sigvec *nsv;
+               struct  sigvec *osv;
+       } *uap = (struct a  *)u.u_ap;
+       struct sigvec vec;
+       register struct sigvec *sv;
+       register int sig;
+       int bit;
 
 
+       sig = uap->signo;
+       if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) {
+               u.u_error = EINVAL;
+               return;
+       }
+       sv = &vec;
+       if (uap->osv) {
+               sv->sv_handler = u.u_signal[sig];
+               sv->sv_mask = u.u_sigmask[sig];
+               bit = sigmask(sig);
+               sv->sv_flags = 0;
+               if ((u.u_sigonstack & bit) != 0)
+                       sv->sv_flags |= SV_ONSTACK;
+               if ((u.u_sigintr & bit) != 0)
+                       sv->sv_flags |= SV_INTERRUPT;
+               u.u_error =
+                   copyout((caddr_t)sv, (caddr_t)uap->osv, sizeof (vec));
+               if (u.u_error)
+                       return;
+       }
+       if (uap->nsv) {
+               u.u_error =
+                   copyin((caddr_t)uap->nsv, (caddr_t)sv, sizeof (vec));
+               if (u.u_error)
+                       return;
+               if (sig == SIGCONT && sv->sv_handler == SIG_IGN) {
+                       u.u_error = EINVAL;
+                       return;
+               }
+               setsigvec(sig, sv);
+       }
+}
+
+setsigvec(sig, sv)
+       int sig;
+       register struct sigvec *sv;
+{
+       register struct proc *p;
+       register int bit;
+
+       bit = sigmask(sig);
+       p = u.u_procp;
+       /*
+        * Change setting atomically.
+        */
+       (void) splhigh();
+       u.u_signal[sig] = sv->sv_handler;
+       u.u_sigmask[sig] = sv->sv_mask &~ cantmask;
+       if (sv->sv_flags & SV_INTERRUPT)
+               u.u_sigintr |= bit;
+       else
+               u.u_sigintr &= ~bit;
+       if (sv->sv_flags & SV_ONSTACK)
+               u.u_sigonstack |= bit;
+       else
+               u.u_sigonstack &= ~bit;
+       if (sv->sv_handler == SIG_IGN) {
+               p->p_sig &= ~bit;               /* never to be seen again */
+               p->p_sigignore |= bit;
+               p->p_sigcatch &= ~bit;
+       } else {
+               p->p_sigignore &= ~bit;
+               if (sv->sv_handler == SIG_DFL)
+                       p->p_sigcatch &= ~bit;
+               else
+                       p->p_sigcatch |= bit;
+       }
+       (void) spl0();
 }
 
 sigblock()
 {
 }
 
 sigblock()
 {
+       struct a {
+               int     mask;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p = u.u_procp;
 
 
+       (void) splhigh();
+       u.u_r.r_val1 = p->p_sigmask;
+       p->p_sigmask |= uap->mask &~ cantmask;
+       (void) spl0();
 }
 
 sigsetmask()
 {
 }
 
 sigsetmask()
 {
+       struct a {
+               int     mask;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p = u.u_procp;
 
 
+       (void) splhigh();
+       u.u_r.r_val1 = p->p_sigmask;
+       p->p_sigmask = uap->mask &~ cantmask;
+       (void) spl0();
 }
 
 sigpause()
 {
 }
 
 sigpause()
 {
+       struct a {
+               int     mask;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p = u.u_procp;
 
 
+       /*
+        * When returning from sigpause, we want
+        * the old mask to be restored after the
+        * signal handler has finished.  Thus, we
+        * save it here and mark the proc structure
+        * to indicate this (should be in u.).
+        */
+       u.u_oldmask = p->p_sigmask;
+       p->p_flag |= SOMASK;
+       p->p_sigmask = uap->mask &~ cantmask;
+       for (;;)
+               sleep((caddr_t)&u, PSLEP);
+       /*NOTREACHED*/
 }
 }
+#undef cantmask
 
 sigstack()
 {
 
 sigstack()
 {
-
+       register struct a {
+               struct  sigstack *nss;
+               struct  sigstack *oss;
+       } *uap = (struct a *)u.u_ap;
+       struct sigstack ss;
+
+       if (uap->oss) {
+               u.u_error = copyout((caddr_t)&u.u_sigstack, (caddr_t)uap->oss, 
+                   sizeof (struct sigstack));
+               if (u.u_error)
+                       return;
+       }
+       if (uap->nss) {
+               u.u_error =
+                   copyin((caddr_t)uap->nss, (caddr_t)&ss, sizeof (ss));
+               if (u.u_error == 0)
+                       u.u_sigstack = ss;
+       }
 }
 
 }
 
-#ifdef notdef
 kill()
 {
 kill()
 {
-
-}
-#endif
-
-killpg()
-{
-
-}
-
-/* BEGIN DEFUNCT */
-okill()
-{
-       register struct proc *p;
-       register a, sig;
        register struct a {
                int     pid;
                int     signo;
        register struct a {
                int     pid;
                int     signo;
-       } *uap;
-       int f, priv;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p;
 
 
-       uap = (struct a *)u.u_ap;
-       f = 0;
-       a = uap->pid;
-       priv = 0;
-       sig = uap->signo;
-       if (sig < 0)
-               /*
-                * A negative signal means send to process group.
-                */
-               uap->signo = -uap->signo;
-       if (uap->signo == 0 || uap->signo > NSIG) {
+       if (uap->signo < 0 || uap->signo > NSIG) {
                u.u_error = EINVAL;
                return;
        }
                u.u_error = EINVAL;
                return;
        }
-       if (a > 0 && sig > 0) {
-               p = pfind(a);
-               if (p == 0 || u.u_uid && u.u_uid != p->p_uid) {
+       if (uap->pid > 0) {
+               /* kill single process */
+               p = pfind(uap->pid);
+               if (p == 0) {
                        u.u_error = ESRCH;
                        return;
                }
                        u.u_error = ESRCH;
                        return;
                }
-               psignal(p, uap->signo);
+               if (u.u_uid && u.u_uid != p->p_uid)
+                       u.u_error = EPERM;
+               else if (uap->signo)
+                       psignal(p, uap->signo);
                return;
        }
                return;
        }
-       if (a==-1 && u.u_uid==0) {
-               priv++;
-               a = 0;
-               sig = -1;               /* like sending to pgrp */
-       } else if (a==0) {
-               /*
-                * Zero process id means send to my process group.
-                */
-               sig = -1;
-               a = u.u_procp->p_pgrp;
-               if (a == 0) {
-                       u.u_error = EINVAL;
-                       return;
-               }
+       switch (uap->pid) {
+       case -1:                /* broadcast signal */
+               u.u_error = killpg1(uap->signo, 0, 1);
+               break;
+       case 0:                 /* signal own process group */
+               u.u_error = killpg1(uap->signo, 0, 0);
+               break;
+       default:                /* negative explicit process group */
+               u.u_error = killpg1(uap->signo, -uap->pid, 0);
+               break;
        }
        }
-       for(p = proc; p < procNPROC; p++) {
-               if (p->p_stat == NULL)
-                       continue;
-               if (sig > 0) {
-                       if (p->p_pid != a)
-                               continue;
-               } else if (p->p_pgrp!=a && priv==0 || p->p_ppid==0 ||
-                   (p->p_flag&SSYS) || (priv && p==u.u_procp))
-                       continue;
-               if (u.u_uid != 0 && u.u_uid != p->p_uid &&
-                   (uap->signo != SIGCONT || !inferior(p)))
-                       continue;
-               f++;
-               psignal(p, uap->signo);
-       }
-       if (f == 0)
-               u.u_error = ESRCH;
+       return;
 }
 
 }
 
-ossig()
+killpg()
 {
 {
-       register int (*f)();
-       struct a {
+       register struct a {
+               int     pgrp;
                int     signo;
                int     signo;
-               int     (*fun)();
-       } *uap;
-       register struct proc *p = u.u_procp;
-       register a;
-       long sigmask;
-
-       uap = (struct a *)u.u_ap;
-       a = uap->signo & SIGNUMMASK;
-       f = uap->fun;
-       if (a<=0 || a>=NSIG || a==SIGKILL || a==SIGSTOP ||
-           a==SIGCONT && (f == SIG_IGN || f == SIG_HOLD)) {
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->signo < 0 || uap->signo > NSIG) {
                u.u_error = EINVAL;
                return;
        }
                u.u_error = EINVAL;
                return;
        }
-       if ((uap->signo &~ SIGNUMMASK) || (f != SIG_DFL && f != SIG_IGN &&
-           SIGISDEFER(f)))
-               u.u_procp->p_flag |= SNUSIG;
-       /* 
-        * Don't clobber registers if we are to simulate
-        * a ret+rti.
-        */
-       if ((uap->signo&SIGDORTI) == 0)
-               u.u_r.r_val1 = (int)u.u_signal[a];
-       /*
-        * Change setting atomically.
-        */
-       (void) spl6();
-       sigmask = 1L << (a-1);
-       if (u.u_signal[a] == SIG_IGN)
-               p->p_sig &= ~sigmask;           /* never to be seen again */
-       u.u_signal[a] = f;
-       if (f != SIG_DFL && f != SIG_IGN && f != SIG_HOLD)
-               f = SIG_CATCH;
-       if ((int)f & 1)
-               p->p_siga0 |= sigmask;
-       else
-               p->p_siga0 &= ~sigmask;
-       if ((int)f & 2)
-               p->p_siga1 |= sigmask;
-       else
-               p->p_siga1 &= ~sigmask;
-       (void) spl0();
-       /*
-        * Now handle options.
-        */
-       if (uap->signo & SIGDOPAUSE) {
+       u.u_error = killpg1(uap->signo, uap->pgrp, 0);
+}
+
+/* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */
+
+killpg1(signo, pgrp, all)
+       int signo, pgrp, all;
+{
+       register struct proc *p;
+       int f, error = 0;
+
+       if (!all && pgrp == 0) {
                /*
                /*
-                * Simulate a PDP11 style wait instrution which
-                * atomically lowers priority, enables interrupts
-                * and hangs.
+                * Zero process id means send to my process group.
                 */
                 */
-               opause();
-               /*NOTREACHED*/
+               pgrp = u.u_procp->p_pgrp;
+               if (pgrp == 0)
+                       return (ESRCH);
+       }
+       for (f = 0, p = allproc; p != NULL; p = p->p_nxt) {
+               if ((p->p_pgrp != pgrp && !all) || p->p_ppid == 0 ||
+                   (p->p_flag&SSYS) || (all && p == u.u_procp))
+                       continue;
+               if (u.u_uid != 0 && u.u_uid != p->p_uid &&
+                   (signo != SIGCONT || !inferior(p))) {
+                       if (!all)
+                               error = EPERM;
+                       continue;
+               }
+               f++;
+               if (signo)
+                       psignal(p, signo);
        }
        }
-       if (uap->signo & SIGDORTI)
-               u.u_eosys = SIMULATERTI;
+       return (error ? error : (f == 0 ? ESRCH : 0));
 }
 
 /*
  * Send the specified signal to
  * all processes with 'pgrp' as
  * process group.
 }
 
 /*
  * Send the specified signal to
  * all processes with 'pgrp' as
  * process group.
- * Called by tty.c for quits and
- * interrupts.
  */
 gsignal(pgrp, sig)
        register int pgrp;
  */
 gsignal(pgrp, sig)
        register int pgrp;
@@ -205,7 +285,7 @@ gsignal(pgrp, sig)
 
        if (pgrp == 0)
                return;
 
        if (pgrp == 0)
                return;
-       for(p = proc; p < procNPROC; p++)
+       for (p = allproc; p != NULL; p = p->p_nxt)
                if (p->p_pgrp == pgrp)
                        psignal(p, sig);
 }
                if (p->p_pgrp == pgrp)
                        psignal(p, sig);
 }
@@ -220,37 +300,37 @@ psignal(p, sig)
 {
        register int s;
        register int (*action)();
 {
        register int s;
        register int (*action)();
-       long sigmask;
+       int mask;
 
        if ((unsigned)sig >= NSIG)
                return;
 
        if ((unsigned)sig >= NSIG)
                return;
-       sigmask = (1L << (sig-1));
+       mask = sigmask(sig);
 
        /*
         * If proc is traced, always give parent a chance.
 
        /*
         * If proc is traced, always give parent a chance.
-        * Otherwise get the signal action from the bits in the proc table.
         */
        if (p->p_flag & STRC)
                action = SIG_DFL;
        else {
         */
        if (p->p_flag & STRC)
                action = SIG_DFL;
        else {
-               s = (p->p_siga1&sigmask) != 0;
-               s <<= 1;
-               s |= (p->p_siga0&sigmask) != 0;
-               action = (int(*)())s;
                /*
                /*
-                * If the signal is ignored, we forget about it immediately.
+                * If the signal is being ignored,
+                * then we forget about it immediately.
                 */
                 */
-               if (action == SIG_IGN)
+               if (p->p_sigignore & mask)
                        return;
                        return;
+               if (p->p_sigmask & mask)
+                       action = SIG_HOLD;
+               else if (p->p_sigcatch & mask)
+                       action = SIG_CATCH;
+               else
+                       action = SIG_DFL;
        }
        }
-#define mask(sig)      (1<<(sig-1))
-#define        stops   (mask(SIGSTOP)|mask(SIGTSTP)|mask(SIGTTIN)|mask(SIGTTOU))
        if (sig) {
        if (sig) {
-               p->p_sig |= sigmask;
+               p->p_sig |= mask;
                switch (sig) {
 
                case SIGTERM:
                switch (sig) {
 
                case SIGTERM:
-                       if ((p->p_flag&STRC) != 0 || action != SIG_DFL)
+                       if ((p->p_flag&STRC) || action != SIG_DFL)
                                break;
                        /* fall into ... */
 
                                break;
                        /* fall into ... */
 
@@ -260,25 +340,23 @@ psignal(p, sig)
                        break;
 
                case SIGCONT:
                        break;
 
                case SIGCONT:
-                       p->p_sig &= ~stops;
+                       p->p_sig &= ~stopsigmask;
                        break;
 
                case SIGSTOP:
                case SIGTSTP:
                case SIGTTIN:
                case SIGTTOU:
                        break;
 
                case SIGSTOP:
                case SIGTSTP:
                case SIGTTIN:
                case SIGTTOU:
-                       p->p_sig &= ~mask(SIGCONT);
+                       p->p_sig &= ~sigmask(SIGCONT);
                        break;
                }
        }
                        break;
                }
        }
-#undef mask
-#undef stops
        /*
         * Defer further processing for signals which are held.
         */
        if (action == SIG_HOLD)
                return;
        /*
         * Defer further processing for signals which are held.
         */
        if (action == SIG_HOLD)
                return;
-       s = spl6();
+       s = splhigh();
        switch (p->p_stat) {
 
        case SSLEEP:
        switch (p->p_stat) {
 
        case SSLEEP:
@@ -315,7 +393,7 @@ psignal(p, sig)
                         */
                        if (sig != SIGSTOP && p->p_pptr == &proc[1]) {
                                psignal(p, SIGKILL);
                         */
                        if (sig != SIGSTOP && p->p_pptr == &proc[1]) {
                                psignal(p, SIGKILL);
-                               p->p_sig &= ~sigmask;
+                               p->p_sig &= ~mask;
                                splx(s);
                                return;
                        }
                                splx(s);
                                return;
                        }
@@ -325,14 +403,16 @@ psignal(p, sig)
                         */
                        if (p->p_flag&SVFORK)
                                goto out;
                         */
                        if (p->p_flag&SVFORK)
                                goto out;
-                       p->p_sig &= ~sigmask;
+                       p->p_sig &= ~mask;
                        p->p_cursig = sig;
                        p->p_cursig = sig;
+                       psignal(p->p_pptr, SIGCHLD);
                        stop(p);
                        goto out;
 
                case SIGIO:
                case SIGURG:
                case SIGCHLD:
                        stop(p);
                        goto out;
 
                case SIGIO:
                case SIGURG:
                case SIGCHLD:
+               case SIGWINCH:
                        /*
                         * These signals are special in that they
                         * don't get propogated... if the process
                        /*
                         * These signals are special in that they
                         * don't get propogated... if the process
@@ -340,7 +420,7 @@ psignal(p, sig)
                         */
                        if (action != SIG_DFL)
                                goto run;
                         */
                        if (action != SIG_DFL)
                                goto run;
-                       p->p_sig &= ~sigmask;           /* take it away */
+                       p->p_sig &= ~mask;              /* take it away */
                        goto out;
 
                default:
                        goto out;
 
                default:
@@ -386,7 +466,7 @@ psignal(p, sig)
                         * Already stopped, don't need to stop again.
                         * (If we did the shell could get confused.)
                         */
                         * Already stopped, don't need to stop again.
                         * (If we did the shell could get confused.)
                         */
-                       p->p_sig &= ~sigmask;           /* take it away */
+                       p->p_sig &= ~mask;              /* take it away */
                        goto out;
 
                default:
                        goto out;
 
                default:
@@ -420,13 +500,7 @@ run:
         * Raise priority to at least PUSER.
         */
        if (p->p_pri > PUSER)
         * Raise priority to at least PUSER.
         */
        if (p->p_pri > PUSER)
-               if ((p != u.u_procp || noproc) && p->p_stat == SRUN &&
-                   (p->p_flag & SLOAD)) {
-                       remrq(p);
-                       p->p_pri = PUSER;
-                       setrq(p);
-               } else
-                       p->p_pri = PUSER;
+               p->p_pri = PUSER;
        setrun(p);
 out:
        splx(s);
        setrun(p);
 out:
        splx(s);
@@ -448,28 +522,27 @@ issig()
 {
        register struct proc *p;
        register int sig;
 {
        register struct proc *p;
        register int sig;
-       long sigbits;
-       long sigmask;
+       int sigbits, mask;
 
        p = u.u_procp;
        for (;;) {
 
        p = u.u_procp;
        for (;;) {
-               sigbits = p->p_sig;
+               sigbits = p->p_sig &~ p->p_sigmask;
                if ((p->p_flag&STRC) == 0)
                if ((p->p_flag&STRC) == 0)
-                       sigbits &= ~p->p_ignsig;
+                       sigbits &= ~p->p_sigignore;
                if (p->p_flag&SVFORK)
                if (p->p_flag&SVFORK)
-#define bit(a) (1<<(a-1))
-                       sigbits &= ~(bit(SIGSTOP)|bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU));
+                       sigbits &= ~stopsigmask;
                if (sigbits == 0)
                        break;
                if (sigbits == 0)
                        break;
-               sig = ffs((int)sigbits);
-               sigmask = 1L << (sig-1);
-               p->p_sig &= ~sigmask;           /* take the signal! */
+               sig = ffs((long)sigbits);
+               mask = sigmask(sig);
+               p->p_sig &= ~mask;              /* take the signal! */
                p->p_cursig = sig;
                p->p_cursig = sig;
-               if (p->p_flag&STRC && (p->p_flag&SVFORK)==0) {
+               if (p->p_flag&STRC && (p->p_flag&SVFORK) == 0) {
                        /*
                         * If traced, always stop, and stay
                         * stopped until released by the parent.
                         */
                        /*
                         * If traced, always stop, and stay
                         * stopped until released by the parent.
                         */
+                       psignal(p->p_pptr, SIGCHLD);
                        do {
                                stop(p);
                                swtch();
                        do {
                                stop(p);
                                swtch();
@@ -479,10 +552,10 @@ issig()
                         * If the traced bit got turned off,
                         * then put the signal taken above back into p_sig
                         * and go back up to the top to rescan signals.
                         * If the traced bit got turned off,
                         * then put the signal taken above back into p_sig
                         * and go back up to the top to rescan signals.
-                        * This ensures that siga0 and u_signal are consistent.
+                        * This ensures that p_sig* and u_signal are consistent.
                         */
                        if ((p->p_flag&STRC) == 0) {
                         */
                        if ((p->p_flag&STRC) == 0) {
-                               p->p_sig |= sigmask;
+                               p->p_sig |= mask;
                                continue;
                        }
 
                                continue;
                        }
 
@@ -494,8 +567,18 @@ issig()
                        sig = p->p_cursig;
                        if (sig == 0)
                                continue;
                        sig = p->p_cursig;
                        if (sig == 0)
                                continue;
+
+                       /*
+                        * If signal is being masked put it back
+                        * into p_sig and look for other signals.
+                        */
+                       mask = sigmask(sig);
+                       if (p->p_sigmask & mask) {
+                               p->p_sig |= mask;
+                               continue;
+                       }
                }
                }
-               switch (u.u_signal[sig]) {
+               switch ((int)u.u_signal[sig]) {
 
                case SIG_DFL:
                        /*
 
                case SIG_DFL:
                        /*
@@ -521,12 +604,16 @@ issig()
                        case SIGSTOP:
                                if (p->p_flag&STRC)
                                        continue;
                        case SIGSTOP:
                                if (p->p_flag&STRC)
                                        continue;
+                               psignal(p->p_pptr, SIGCHLD);
                                stop(p);
                                swtch();
                                continue;
 
                        case SIGCONT:
                        case SIGCHLD:
                                stop(p);
                                swtch();
                                continue;
 
                        case SIGCONT:
                        case SIGCHLD:
+                       case SIGURG:
+                       case SIGIO:
+                       case SIGWINCH:
                                /*
                                 * These signals are normally not
                                 * sent if the action is the default.
                                /*
                                 * These signals are normally not
                                 * sent if the action is the default.
@@ -573,7 +660,8 @@ send:
 
 /*
  * Put the argument process into the stopped
 
 /*
  * Put the argument process into the stopped
- * state and notify the parent via wakeup and/or signal.
+ * state and notify the parent via wakeup.
+ * Signals are handled elsewhere.
  */
 stop(p)
        register struct proc *p;
  */
 stop(p)
        register struct proc *p;
@@ -582,12 +670,6 @@ stop(p)
        p->p_stat = SSTOP;
        p->p_flag &= ~SWTED;
        wakeup((caddr_t)p->p_pptr);
        p->p_stat = SSTOP;
        p->p_flag &= ~SWTED;
        wakeup((caddr_t)p->p_pptr);
-       /*
-        * Avoid sending signal to parent if process is traced
-        */
-       if (p->p_flag&STRC)
-               return;
-       psignal(p->p_pptr, SIGCHLD);
 }
 
 /*
 }
 
 /*
@@ -601,45 +683,50 @@ stop(p)
  */
 psig()
 {
  */
 psig()
 {
-       register struct proc *rp = u.u_procp;
-       register int n = rp->p_cursig;
-       long sigmask = 1L << (n-1);
+       register struct proc *p = u.u_procp;
+       register int sig = p->p_cursig;
+       int mask = sigmask(sig), returnmask;
        register int (*action)();
 
        register int (*action)();
 
-       if (rp->p_cursig == 0)
+       if (sig == 0)
                panic("psig");
                panic("psig");
-       action = u.u_signal[n];
+       action = u.u_signal[sig];
        if (action != SIG_DFL) {
        if (action != SIG_DFL) {
-               if (action == SIG_IGN || action == SIG_HOLD)
+               if (action == SIG_IGN || (p->p_sigmask & mask))
                        panic("psig action");
                u.u_error = 0;
                        panic("psig action");
                u.u_error = 0;
-               if (n != SIGILL && n != SIGTRAP)
-                       u.u_signal[n] = 0;
                /*
                /*
-                * If this catch value indicates automatic holding of
-                * subsequent signals, set the hold value.
+                * Set the new mask value and also defer further
+                * occurences of this signal (unless we're simulating
+                * the old signal facilities). 
+                *
+                * Special case: user has done a sigpause.  Here the
+                * current mask is not of interest, but rather the
+                * mask from before the sigpause is what we want restored
+                * after the signal processing is completed.
                 */
                 */
-               if (SIGISDEFER(action)) {
-                       (void) spl6();
-                       if ((int)SIG_HOLD & 1)
-                               rp->p_siga0 |= sigmask;
-                       else
-                               rp->p_siga0 &= ~sigmask;
-                       if ((int)SIG_HOLD & 2)
-                               rp->p_siga1 |= sigmask;
-                       else
-                               rp->p_siga1 &= ~sigmask;
-                       u.u_signal[n] = SIG_HOLD;
-                       (void) spl0();
-                       action = SIGUNDEFER(action);
+               (void) splhigh();
+               if (p->p_flag & SOUSIG) {
+                       if (sig != SIGILL && sig != SIGTRAP) {
+                               u.u_signal[sig] = SIG_DFL;
+                               p->p_sigcatch &= ~mask;
+                       }
+                       mask = 0;
                }
                }
+               if (p->p_flag & SOMASK) {
+                       returnmask = u.u_oldmask;
+                       p->p_flag &= ~SOMASK;
+               } else
+                       returnmask = p->p_sigmask;
+               p->p_sigmask |= u.u_sigmask[sig] | mask;
+               (void) spl0();
                u.u_ru.ru_nsignals++;
                u.u_ru.ru_nsignals++;
-               sendsig(action, n);
-               rp->p_cursig = 0;
+               sendsig(action, sig, returnmask);
+               p->p_cursig = 0;
                return;
        }
        u.u_acflag |= AXSIG;
                return;
        }
        u.u_acflag |= AXSIG;
-       switch (n) {
+       switch (sig) {
 
        case SIGILL:
        case SIGIOT:
 
        case SIGILL:
        case SIGIOT:
@@ -650,16 +737,13 @@ psig()
        case SIGFPE:
        case SIGSEGV:
        case SIGSYS:
        case SIGFPE:
        case SIGSEGV:
        case SIGSYS:
-               u.u_arg[0] = n;
+               u.u_arg[0] = sig;
                if (core())
                if (core())
-                       n += 0200;
+                       sig += 0200;
        }
        }
-       exit(n);
+       exit(sig);
 }
 
 }
 
-#ifdef unneeded
-int    corestop = 0;
-#endif
 /*
  * Create a core image on the file "core"
  * If you are looking for protection glitches,
 /*
  * Create a core image on the file "core"
  * If you are looking for protection glitches,
@@ -673,31 +757,24 @@ int       corestop = 0;
 core()
 {
        register struct inode *ip;
 core()
 {
        register struct inode *ip;
-       extern schar();
-
-#ifdef unneeded
-       if (corestop) {
-               int i;
-               for (i = 0; i < 10; i++)
-                       if (u.u_comm[i])
-                               putchar(u.u_comm[i], 0);
-               printf(", uid %d\n", u.u_uid);
-               if (corestop&2)
-                       asm("halt");
-       }
-#endif
-       if (u.u_uid != u.u_ruid)
+       register struct nameidata *ndp = &u.u_nd;
+
+       if (u.u_uid != u.u_ruid || u.u_gid != u.u_rgid)
                return (0);
        if (ctob(UPAGES+u.u_dsize+u.u_ssize) >=
            u.u_rlimit[RLIMIT_CORE].rlim_cur)
                return (0);
                return (0);
        if (ctob(UPAGES+u.u_dsize+u.u_ssize) >=
            u.u_rlimit[RLIMIT_CORE].rlim_cur)
                return (0);
+       if (u.u_procp->p_textp && access(u.u_procp->p_textp->x_iptr, IREAD))
+               return (0);
        u.u_error = 0;
        u.u_error = 0;
-       u.u_dirp = "core";
-       ip = namei(schar, 1, 1);
+       ndp->ni_nameiop = CREATE | FOLLOW;
+       ndp->ni_segflg = UIO_SYSSPACE;
+       ndp->ni_dirp = "core";
+       ip = namei(ndp);
        if (ip == NULL) {
                if (u.u_error)
                        return (0);
        if (ip == NULL) {
                if (u.u_error)
                        return (0);
-               ip = maknode(0666);
+               ip = maknode(0644, ndp);
                if (ip==NULL)
                        return (0);
        }
                if (ip==NULL)
                        return (0);
        }
@@ -707,23 +784,22 @@ core()
                u.u_error = EFAULT;
                goto out;
        }
                u.u_error = EFAULT;
                goto out;
        }
-       itrunc(ip, 0);
+       itrunc(ip, (u_long)0);
        u.u_acflag |= ACORE;
        u.u_acflag |= ACORE;
-       /* if (u.u_error == 0) */
-               u.u_error = rdwri(UIO_WRITE, ip,
-                   (caddr_t)&u,
-                   ctob(UPAGES),
-                   0, 1, (int *)0);
+       u.u_error = rdwri(UIO_WRITE, ip,
+           (caddr_t)&u,
+           ctob(UPAGES),
+           (off_t)0, 1, (int *)0);
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(dptov(u.u_procp, 0)),
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(dptov(u.u_procp, 0)),
-                   ctob(u.u_dsize),
-                   ctob(UPAGES), 0, (int *)0);
+                   (int)ctob(u.u_dsize),
+                   (off_t)ctob(UPAGES), 0, (int *)0);
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(sptov(u.u_procp, u.u_ssize - 1)),
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(sptov(u.u_procp, u.u_ssize - 1)),
-                   ctob(u.u_ssize),
-                   ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0);
+                   (int)ctob(u.u_ssize),
+                   (off_t)ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0);
 out:
        iput(ip);
        return (u.u_error == 0);
 out:
        iput(ip);
        return (u.u_error == 0);