BSD 4_3_Reno release
[unix-history] / usr / src / sys / kern / kern_sig.c
index 12a9c41..a271cdc 100644 (file)
@@ -2,24 +2,27 @@
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution is only permitted until one year after the first shipment
+ * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
+ * binary forms are permitted provided that: (1) source distributions retain
+ * this entire copyright notice and comment, and (2) distributions including
+ * binaries display the following acknowledgement:  This product includes
+ * software developed by the University of California, Berkeley and its
+ * contributors'' in the documentation or other materials provided with the
+ * distribution and in all advertising materials mentioning features or use
+ * of this software.  Neither the name of the University nor the names of
+ * its contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  *
- *     @(#)kern_sig.c  7.14 (Berkeley) %G%
+ *     @(#)kern_sig.c  7.23 (Berkeley) 6/28/90
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "syscontext.h"        /* XXX */
+#include "user.h"
 #include "vnode.h"
 #include "proc.h"
 #include "timeb.h"
 #include "vnode.h"
 #include "proc.h"
 #include "timeb.h"
 #include "machine/psl.h"
 #include "machine/mtpr.h"
 
 #include "machine/psl.h"
 #include "machine/mtpr.h"
 
-#define        stopsigmask     (sigmask(SIGSTOP)|sigmask(SIGTSTP)| \
-                       sigmask(SIGTTIN)|sigmask(SIGTTOU))
+#define        ttystopsigmask  (sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU))
+#define        stopsigmask     (sigmask(SIGSTOP)|ttystopsigmask)
 #define defaultignmask (sigmask(SIGCONT)|sigmask(SIGIO)|sigmask(SIGURG)| \
                        sigmask(SIGCHLD)|sigmask(SIGWINCH)|sigmask(SIGINFO))
 
 /*
 #define defaultignmask (sigmask(SIGCONT)|sigmask(SIGIO)|sigmask(SIGURG)| \
                        sigmask(SIGCHLD)|sigmask(SIGWINCH)|sigmask(SIGINFO))
 
 /*
- * Can the current process (u.u_procp) send the specified signal
- * to the specified process?
+ * Can process p send the signal signo to process q?
  */
  */
-#define CANSIGNAL(p, signo) \
-       (u.u_uid == 0 || \
-           u.u_uid == (p)->p_uid || u.u_uid == (p)->p_ruid || \
-           u.u_procp->p_ruid == (p)->p_uid || \
-           u.u_procp->p_ruid == (p)->p_ruid || \
-           ((signo) == SIGCONT && (p)->p_session == u.u_procp->p_session))
-
-sigaction()
-{
-       register struct a {
+#define CANSIGNAL(p, q, signo) \
+       ((p)->p_uid == 0 || \
+           (p)->p_ruid == (q)->p_ruid || (p)->p_uid == (q)->p_ruid || \
+           (p)->p_ruid == (q)->p_uid || (p)->p_uid == (q)->p_uid || \
+           ((signo) == SIGCONT && (q)->p_session == (p)->p_session))
+
+/* ARGSUSED */
+sigaction(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     signo;
                struct  sigaction *nsa;
                struct  sigaction *osa;
                int     signo;
                struct  sigaction *nsa;
                struct  sigaction *osa;
-       } *uap = (struct a  *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        struct sigaction vec;
        register struct sigaction *sa;
        register int sig;
        struct sigaction vec;
        register struct sigaction *sa;
        register int sig;
@@ -70,7 +74,7 @@ sigaction()
 
        sig = uap->signo;
        if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
 
        sig = uap->signo;
        if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
-               RETURN (EINVAL);
+               return (EINVAL);
        sa = &vec;
        if (uap->osa) {
                sa->sa_handler = u.u_signal[sig];
        sa = &vec;
        if (uap->osa) {
                sa->sa_handler = u.u_signal[sig];
@@ -81,30 +85,29 @@ sigaction()
                        sa->sa_flags |= SA_ONSTACK;
                if ((u.u_sigintr & bit) == 0)
                        sa->sa_flags |= SA_RESTART;
                        sa->sa_flags |= SA_ONSTACK;
                if ((u.u_sigintr & bit) == 0)
                        sa->sa_flags |= SA_RESTART;
-               if (u.u_procp->p_flag & SNOCLDSTOP)
+               if (p->p_flag & SNOCLDSTOP)
                        sa->sa_flags |= SA_NOCLDSTOP;
                if (error = copyout((caddr_t)sa, (caddr_t)uap->osa,
                    sizeof (vec)))
                        sa->sa_flags |= SA_NOCLDSTOP;
                if (error = copyout((caddr_t)sa, (caddr_t)uap->osa,
                    sizeof (vec)))
-                       RETURN (error);
+                       return (error);
        }
        if (uap->nsa) {
                if (error = copyin((caddr_t)uap->nsa, (caddr_t)sa,
                    sizeof (vec)))
        }
        if (uap->nsa) {
                if (error = copyin((caddr_t)uap->nsa, (caddr_t)sa,
                    sizeof (vec)))
-                       RETURN (error);
-               setsigvec(sig, sa);
+                       return (error);
+               setsigvec(p, sig, sa);
        }
        }
-       RETURN (0);
+       return (0);
 }
 
 }
 
-setsigvec(sig, sa)
+setsigvec(p, sig, sa)
+       register struct proc *p;
        int sig;
        register struct sigaction *sa;
 {
        int sig;
        register struct sigaction *sa;
 {
-       register struct proc *p;
        register int bit;
 
        bit = sigmask(sig);
        register int bit;
 
        bit = sigmask(sig);
-       p = u.u_procp;
        /*
         * Change setting atomically.
         */
        /*
         * Change setting atomically.
         */
@@ -197,16 +200,17 @@ execsigs(p)
  * and return old mask as return value;
  * the library stub does the rest.
  */
  * and return old mask as return value;
  * the library stub does the rest.
  */
-sigprocmask()
-{
-       struct a {
+sigprocmask(p, uap, retval)
+       register struct proc *p;
+       struct args {
                int     how;
                sigset_t mask;
                int     how;
                sigset_t mask;
-       } *uap = (struct a *)u.u_ap;
-       register struct proc *p = u.u_procp;
+       } *uap;
+       int *retval;
+{
        int error = 0;
 
        int error = 0;
 
-       u.u_r.r_val1 = p->p_sigmask;
+       *retval = p->p_sigmask;
        (void) splhigh();
 
        switch (uap->how) {
        (void) splhigh();
 
        switch (uap->how) {
@@ -227,27 +231,34 @@ sigprocmask()
                break;
        }
        (void) spl0();
                break;
        }
        (void) spl0();
-       RETURN (error);
+       return (error);
 }
 
 }
 
-sigpending()
+/* ARGSUSED */
+sigpending(p, uap, retval)
+       struct proc *p;
+       void *uap;
+       int *retval;
 {
 
 {
 
-       u.u_r.r_val1 = u.u_procp->p_sig;
-       RETURN (0);
+       *retval = p->p_sig;
+       return (0);
 }
 
 #ifdef COMPAT_43
 /*
  * Generalized interface signal handler, 4.3-compatible.
  */
 }
 
 #ifdef COMPAT_43
 /*
  * Generalized interface signal handler, 4.3-compatible.
  */
-osigvec()
-{
-       register struct a {
+/* ARGSUSED */
+osigvec(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     signo;
                struct  sigvec *nsv;
                struct  sigvec *osv;
                int     signo;
                struct  sigvec *nsv;
                struct  sigvec *osv;
-       } *uap = (struct a  *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        struct sigvec vec;
        register struct sigvec *sv;
        register int sig;
        struct sigvec vec;
        register struct sigvec *sv;
        register int sig;
@@ -255,7 +266,7 @@ osigvec()
 
        sig = uap->signo;
        if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
 
        sig = uap->signo;
        if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
-               RETURN (EINVAL);
+               return (EINVAL);
        sv = &vec;
        if (uap->osv) {
                *(sig_t *)&sv->sv_handler = u.u_signal[sig];
        sv = &vec;
        if (uap->osv) {
                *(sig_t *)&sv->sv_handler = u.u_signal[sig];
@@ -266,48 +277,50 @@ osigvec()
                        sv->sv_flags |= SV_ONSTACK;
                if ((u.u_sigintr & bit) != 0)
                        sv->sv_flags |= SV_INTERRUPT;
                        sv->sv_flags |= SV_ONSTACK;
                if ((u.u_sigintr & bit) != 0)
                        sv->sv_flags |= SV_INTERRUPT;
-               if (u.u_procp->p_flag & SNOCLDSTOP)
+               if (p->p_flag & SNOCLDSTOP)
                        sv->sv_flags |= SA_NOCLDSTOP;
                if (error = copyout((caddr_t)sv, (caddr_t)uap->osv,
                    sizeof (vec)))
                        sv->sv_flags |= SA_NOCLDSTOP;
                if (error = copyout((caddr_t)sv, (caddr_t)uap->osv,
                    sizeof (vec)))
-                       RETURN (error);
+                       return (error);
        }
        if (uap->nsv) {
                if (error = copyin((caddr_t)uap->nsv, (caddr_t)sv,
                    sizeof (vec)))
        }
        if (uap->nsv) {
                if (error = copyin((caddr_t)uap->nsv, (caddr_t)sv,
                    sizeof (vec)))
-                       RETURN (error);
+                       return (error);
                sv->sv_flags ^= SA_RESTART;     /* opposite of SV_INTERRUPT */
                sv->sv_flags ^= SA_RESTART;     /* opposite of SV_INTERRUPT */
-               setsigvec(sig, sv);
+               setsigvec(p, sig, (struct sigaction *)sv);
        }
        }
-       RETURN (0);
+       return (0);
 }
 
 }
 
-osigblock()
-{
-       struct a {
+osigblock(p, uap, retval)
+       register struct proc *p;
+       struct args {
                int     mask;
                int     mask;
-       } *uap = (struct a *)u.u_ap;
-       register struct proc *p = u.u_procp;
+       } *uap;
+       int *retval;
+{
 
        (void) splhigh();
 
        (void) splhigh();
-       u.u_r.r_val1 = p->p_sigmask;
+       *retval = p->p_sigmask;
        p->p_sigmask |= uap->mask &~ sigcantmask;
        (void) spl0();
        p->p_sigmask |= uap->mask &~ sigcantmask;
        (void) spl0();
-       RETURN (0);
+       return (0);
 }
 
 }
 
-osigsetmask()
-{
-       struct a {
+osigsetmask(p, uap, retval)
+       struct proc *p;
+       struct args {
                int     mask;
                int     mask;
-       } *uap = (struct a *)u.u_ap;
-       register struct proc *p = u.u_procp;
+       } *uap;
+       int *retval;
+{
 
        (void) splhigh();
 
        (void) splhigh();
-       u.u_r.r_val1 = p->p_sigmask;
+       *retval = p->p_sigmask;
        p->p_sigmask = uap->mask &~ sigcantmask;
        (void) spl0();
        p->p_sigmask = uap->mask &~ sigcantmask;
        (void) spl0();
-       RETURN (0);
+       return (0);
 }
 #endif
 
 }
 #endif
 
@@ -316,12 +329,14 @@ osigsetmask()
  * in the meantime.  Note nonstandard calling convention:
  * libc stub passes mask, not pointer, to save a copyin.
  */
  * in the meantime.  Note nonstandard calling convention:
  * libc stub passes mask, not pointer, to save a copyin.
  */
-sigsuspend()
-{
-       struct a {
+/* ARGSUSED */
+sigsuspend(p, uap, retval)
+       register struct proc *p;
+       struct args {
                sigset_t mask;
                sigset_t mask;
-       } *uap = (struct a *)u.u_ap;
-       register struct proc *p = u.u_procp;
+       } *uap;
+       int *retval;
+{
 
        /*
         * When returning from sigpause, we want
 
        /*
         * When returning from sigpause, we want
@@ -335,79 +350,93 @@ sigsuspend()
        p->p_sigmask = uap->mask &~ sigcantmask;
        (void) tsleep((caddr_t)&u, PPAUSE | PCATCH, "pause", 0);
        /* always return EINTR rather than ERESTART... */
        p->p_sigmask = uap->mask &~ sigcantmask;
        (void) tsleep((caddr_t)&u, PPAUSE | PCATCH, "pause", 0);
        /* always return EINTR rather than ERESTART... */
-       RETURN (EINTR);
+       return (EINTR);
 }
 
 }
 
-sigstack()
-{
-       register struct a {
+/* ARGSUSED */
+sigstack(p, uap, retval)
+       struct proc *p;
+       register struct args {
                struct  sigstack *nss;
                struct  sigstack *oss;
                struct  sigstack *nss;
                struct  sigstack *oss;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        struct sigstack ss;
        int error = 0;
 
        if (uap->oss && (error = copyout((caddr_t)&u.u_sigstack,
            (caddr_t)uap->oss, sizeof (struct sigstack))))
        struct sigstack ss;
        int error = 0;
 
        if (uap->oss && (error = copyout((caddr_t)&u.u_sigstack,
            (caddr_t)uap->oss, sizeof (struct sigstack))))
-               RETURN (error);
+               return (error);
        if (uap->nss && (error = copyin((caddr_t)uap->nss, (caddr_t)&ss,
            sizeof (ss))) == 0)
                u.u_sigstack = ss;
        if (uap->nss && (error = copyin((caddr_t)uap->nss, (caddr_t)&ss,
            sizeof (ss))) == 0)
                u.u_sigstack = ss;
-       RETURN (error);
+       return (error);
 }
 
 }
 
-kill()
-{
-       register struct a {
+/* ARGSUSED */
+kill(cp, uap, retval)
+       register struct proc *cp;
+       register struct args {
                int     pid;
                int     signo;
                int     pid;
                int     signo;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
        register struct proc *p;
 
        if ((unsigned) uap->signo >= NSIG)
        register struct proc *p;
 
        if ((unsigned) uap->signo >= NSIG)
-               RETURN (EINVAL);
+               return (EINVAL);
        if (uap->pid > 0) {
                /* kill single process */
                p = pfind(uap->pid);
                if (p == 0)
        if (uap->pid > 0) {
                /* kill single process */
                p = pfind(uap->pid);
                if (p == 0)
-                       RETURN (ESRCH);
-               if (!CANSIGNAL(p, uap->signo))
-                       RETURN (EPERM);
+                       return (ESRCH);
+               if (!CANSIGNAL(cp, p, uap->signo))
+                       return (EPERM);
                if (uap->signo)
                        psignal(p, uap->signo);
                if (uap->signo)
                        psignal(p, uap->signo);
-               RETURN (0);
+               return (0);
        }
        switch (uap->pid) {
        case -1:                /* broadcast signal */
        }
        switch (uap->pid) {
        case -1:                /* broadcast signal */
-               RETURN (killpg1(uap->signo, 0, 1));
+               return (killpg1(cp, uap->signo, 0, 1));
        case 0:                 /* signal own process group */
        case 0:                 /* signal own process group */
-               RETURN (killpg1(uap->signo, 0, 0));
+               return (killpg1(cp, uap->signo, 0, 0));
        default:                /* negative explicit process group */
        default:                /* negative explicit process group */
-               RETURN (killpg1(uap->signo, -uap->pid, 0));
+               return (killpg1(cp, uap->signo, -uap->pid, 0));
        }
        /* NOTREACHED */
 }
 
 #ifdef COMPAT_43
        }
        /* NOTREACHED */
 }
 
 #ifdef COMPAT_43
-okillpg()
-{
-       register struct a {
+/* ARGSUSED */
+okillpg(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     pgid;
                int     signo;
                int     pgid;
                int     signo;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
 
        if ((unsigned) uap->signo >= NSIG)
 
        if ((unsigned) uap->signo >= NSIG)
-               RETURN (EINVAL);
-       RETURN (killpg1(uap->signo, uap->pgid, 0));
+               return (EINVAL);
+       return (killpg1(p, uap->signo, uap->pgid, 0));
 }
 #endif
 
 }
 #endif
 
-killpg1(signo, pgid, all)
+/*
+ * Common code for kill process group/broadcast kill.
+ * cp is calling process.
+ */
+killpg1(cp, signo, pgid, all)
+       register struct proc *cp;
        int signo, pgid, all;
 {
        register struct proc *p;
        struct pgrp *pgrp;
        int signo, pgid, all;
 {
        register struct proc *p;
        struct pgrp *pgrp;
-       int f = 0, error = ESRCH;
+       int f = 0;
        
        if (all)        
                /* 
        
        if (all)        
                /* 
@@ -415,7 +444,7 @@ killpg1(signo, pgid, all)
                 */
                for (p = allproc; p != NULL; p = p->p_nxt) {
                        if (p->p_ppid == 0 || p->p_flag&SSYS || 
                 */
                for (p = allproc; p != NULL; p = p->p_nxt) {
                        if (p->p_ppid == 0 || p->p_flag&SSYS || 
-                           p == u.u_procp || !CANSIGNAL(p, signo))
+                           p == u.u_procp || !CANSIGNAL(cp, p, signo))
                                continue;
                        f++;
                        if (signo)
                                continue;
                        f++;
                        if (signo)
@@ -434,17 +463,17 @@ killpg1(signo, pgid, all)
                }
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
                        if (p->p_ppid == 0 || p->p_flag&SSYS ||
                }
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
                        if (p->p_ppid == 0 || p->p_flag&SSYS ||
-                           !CANSIGNAL(p, signo))
+                           !CANSIGNAL(cp, p, signo))
                                continue;
                        f++;
                        if (signo)
                                psignal(p, signo);
                }
        }
                                continue;
                        f++;
                        if (signo)
                                psignal(p, signo);
                }
        }
-       return (f ? 0 : error);
+       return (f ? 0 : ESRCH);
 }
 
 }
 
-/* XXX - to be removed, as soon as sockets are changed to operate on pgrps
+/*
  * Send the specified signal to
  * all processes with 'pgid' as
  * process group.
  * Send the specified signal to
  * all processes with 'pgid' as
  * process group.
@@ -454,19 +483,23 @@ gsignal(pgid, sig)
        struct pgrp *pgrp;
 
        if (pgid && (pgrp = pgfind(pgid)))
        struct pgrp *pgrp;
 
        if (pgid && (pgrp = pgfind(pgid)))
-               pgsignal(pgrp, sig);
+               pgsignal(pgrp, sig, 0);
 }
 }
+
 /*
 /*
- * Send sig to all all members of the process group
+ * Send sig to every member of a process group.
+ * If checktty is 1, limit to members which have a controlling
+ * terminal.
  */
  */
-pgsignal(pgrp, sig)
+pgsignal(pgrp, sig, checkctty)
        struct pgrp *pgrp;
 {
        register struct proc *p;
 
        if (pgrp)
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt)
        struct pgrp *pgrp;
 {
        register struct proc *p;
 
        if (pgrp)
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt)
-                       psignal(p, sig);
+                       if (checkctty == 0 || p->p_flag&SCTTY)
+                               psignal(p, sig);
 }
 
 /*
 }
 
 /*
@@ -478,7 +511,7 @@ trapsignal(sig, code)
        register int sig;
        unsigned code;
 {
        register int sig;
        unsigned code;
 {
-       register struct proc *p = u.u_procp;
+       register struct proc *p = u.u_procp;    /* XXX */
        int mask;
 
        mask = sigmask(sig);
        int mask;
 
        mask = sigmask(sig);
@@ -493,7 +526,7 @@ trapsignal(sig, code)
                sendsig(u.u_signal[sig], sig, p->p_sigmask, code);
                p->p_sigmask |= u.u_sigmask[sig] | mask;
        } else {
                sendsig(u.u_signal[sig], sig, p->p_sigmask, code);
                p->p_sigmask |= u.u_sigmask[sig] | mask;
        } else {
-               u.u_arg[1] = code;      /* XXX for core dump/debugger */
+               u.u_code = code;        /* XXX for core dump/debugger */
                psignal(p, sig);
        }
 }
                psignal(p, sig);
        }
 }
@@ -540,12 +573,8 @@ psignal(p, sig)
                        action = SIG_HOLD;
                else if (p->p_sigcatch & mask)
                        action = SIG_CATCH;
                        action = SIG_HOLD;
                else if (p->p_sigcatch & mask)
                        action = SIG_CATCH;
-               else {
-                       if (p->p_pgrp->pg_jobc == 0 && (sig == SIGTTIN || 
-                           sig == SIGTTOU || sig == SIGTSTP))
-                               return;
+               else
                        action = SIG_DFL;
                        action = SIG_DFL;
-               }
        }
        switch (sig) {
 
        }
        switch (sig) {
 
@@ -613,7 +642,7 @@ psignal(p, sig)
                        if (p->p_flag&SVFORK)
                                goto out;
                        p->p_sig &= ~mask;
                        if (p->p_flag&SVFORK)
                                goto out;
                        p->p_sig &= ~mask;
-                       p->p_cursig = sig;
+                       p->p_xstat = sig;
                        if ((p->p_pptr->p_flag & SNOCLDSTOP) == 0)
                                psignal(p->p_pptr, SIGCHLD);
                        stop(p);
                        if ((p->p_pptr->p_flag & SNOCLDSTOP) == 0)
                                psignal(p->p_pptr, SIGCHLD);
                        stop(p);
@@ -648,7 +677,6 @@ psignal(p, sig)
                         * an event, then it goes back to run state.
                         * Otherwise, process goes back to sleep state.
                         */
                         * an event, then it goes back to run state.
                         * Otherwise, process goes back to sleep state.
                         */
-                       p->p_cursig = 0;        /* ??? XXX */
                        if (action == SIG_DFL)
                                p->p_sig &= ~mask;
                        if (action == SIG_CATCH)
                        if (action == SIG_DFL)
                                p->p_sig &= ~mask;
                        if (action == SIG_CATCH)
@@ -717,10 +745,9 @@ out:
  */
 issig()
 {
  */
 issig()
 {
-       register struct proc *p;
+       register struct proc *p = u.u_procp;            /* XXX */
        register int sig, mask;
 
        register int sig, mask;
 
-       p = u.u_procp;
        for (;;) {
                mask = p->p_sig &~ p->p_sigmask;
                if (p->p_flag&SVFORK)
        for (;;) {
                mask = p->p_sig &~ p->p_sigmask;
                if (p->p_flag&SVFORK)
@@ -742,12 +769,12 @@ issig()
                         * If traced, always stop, and stay
                         * stopped until released by the parent.
                         */
                         * If traced, always stop, and stay
                         * stopped until released by the parent.
                         */
-                       p->p_cursig = sig;
+                       p->p_xstat = sig;
                        psignal(p->p_pptr, SIGCHLD);
                        do {
                                stop(p);
                                swtch();
                        psignal(p->p_pptr, SIGCHLD);
                        do {
                                stop(p);
                                swtch();
-                       } while (!procxmt() && p->p_flag&STRC);
+                       } while (!procxmt(p) && p->p_flag&STRC);
 
                        /*
                         * If the traced bit got turned off,
 
                        /*
                         * If the traced bit got turned off,
@@ -759,11 +786,11 @@ issig()
 
                        /*
                         * If parent wants us to take the signal,
 
                        /*
                         * If parent wants us to take the signal,
-                        * then it will leave it in p->p_cursig;
+                        * then it will leave it in p->p_xstat;
                         * otherwise we just look for signals again.
                         */
                        p->p_sig &= ~mask;      /* clear the old signal */
                         * otherwise we just look for signals again.
                         */
                        p->p_sig &= ~mask;      /* clear the old signal */
-                       sig = p->p_cursig;
+                       sig = p->p_xstat;
                        if (sig == 0)
                                continue;
 
                        if (sig == 0)
                                continue;
 
@@ -794,12 +821,16 @@ issig()
                        /*
                         * If there is a pending stop signal to process
                         * with default action, stop here,
                        /*
                         * If there is a pending stop signal to process
                         * with default action, stop here,
-                        * then clear the signal.
+                        * then clear the signal.  However,
+                        * if process is member of an orphaned
+                        * process group, ignore tty stop signals.
                         */
                        if (mask & stopsigmask) {
                         */
                        if (mask & stopsigmask) {
-                               if (p->p_flag&STRC)
+                               if (p->p_flag&STRC ||
+                                   (p->p_pgrp->pg_jobc == 0 &&
+                                   mask & ttystopsigmask))
                                        break;  /* == ignore */
                                        break;  /* == ignore */
-                               p->p_cursig = sig;
+                               p->p_xstat = sig;
                                stop(p);
                                if ((p->p_pptr->p_flag & SNOCLDSTOP) == 0)
                                        psignal(p->p_pptr, SIGCHLD);
                                stop(p);
                                if ((p->p_pptr->p_flag & SNOCLDSTOP) == 0)
                                        psignal(p->p_pptr, SIGCHLD);
@@ -883,7 +914,6 @@ psig(sig)
                        if (action == SIG_IGN || (p->p_sigmask & mask))
                                panic("psig action");
 #endif
                        if (action == SIG_IGN || (p->p_sigmask & mask))
                                panic("psig action");
 #endif
-                       u.u_error = 0;
                        /*
                         * Set the new mask value and also defer further
                         * occurences of this signal.
                        /*
                         * Set the new mask value and also defer further
                         * occurences of this signal.
@@ -917,11 +947,11 @@ psig(sig)
                case SIGFPE:
                case SIGSEGV:
                case SIGSYS:
                case SIGFPE:
                case SIGSEGV:
                case SIGSYS:
-                       u.u_arg[0] = sig;
+                       u.u_sig = sig;
                        if (core() == 0)
                                sig |= WCOREFLAG;
                }
                        if (core() == 0)
                                sig |= WCOREFLAG;
                }
-               exit(W_EXITCODE(0, sig));
+               exit(p, W_EXITCODE(0, sig));
                /* NOTREACHED */
        } while (sig = CURSIG(p));
 }
                /* NOTREACHED */
        } while (sig = CURSIG(p));
 }
@@ -964,18 +994,26 @@ core()
                vput(vp);
                return (EFAULT);
        }
                vput(vp);
                return (EFAULT);
        }
-#ifdef MMAP
-       { register int fd;
-       /* unmap funky devices in the user's address space */
-       for (fd = 0; fd < u.u_lastfile; fd++)
-               if (u.u_ofile[fd] && (u.u_pofile[fd] & UF_MAPPED))
-                       munmapfd(fd);
+#ifdef MAPMEM
+       if (error = mmcore(p)) {
+               vput(vp);
+               return (error);
        }
 #endif
        VATTR_NULL(&vattr);
        vattr.va_size = 0;
        VOP_SETATTR(vp, &vattr, u.u_cred);
        u.u_acflag |= ACORE;
        }
 #endif
        VATTR_NULL(&vattr);
        vattr.va_size = 0;
        VOP_SETATTR(vp, &vattr, u.u_cred);
        u.u_acflag |= ACORE;
+#ifdef HPUXCOMPAT
+       /*
+        * BLETCH!  If we loaded from an HPUX format binary file
+        * we have to dump an HPUX style user struct so that the
+        * HPUX debuggers can grok it.
+        */
+       if (u.u_pcb.pcb_flags & PCB_HPUXBIN)
+               error = hpuxdumpu(vp, ndp->ni_cred);
+       else
+#endif
        error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&u, ctob(UPAGES), (off_t)0,
            UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, ndp->ni_cred, (int *)0);
        if (error == 0)
        error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&u, ctob(UPAGES), (off_t)0,
            UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, ndp->ni_cred, (int *)0);
        if (error == 0)
@@ -997,9 +1035,13 @@ core()
  * Nonexistent system call-- signal process (may want to handle it).
  * Flag error in case process won't see signal immediately (blocked or ignored).
  */
  * Nonexistent system call-- signal process (may want to handle it).
  * Flag error in case process won't see signal immediately (blocked or ignored).
  */
-nosys()
+/* ARGSUSED */
+nosys(p, args, retval)
+       struct proc *p;
+       void *args;
+       int *retval;
 {
 
 {
 
-       psignal(u.u_procp, SIGSYS);
-       u.u_error = EINVAL;
+       psignal(p, SIGSYS);
+       return (EINVAL);
 }
 }