BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / kern / kern_exit.c
index d015225..03353c7 100644 (file)
@@ -1,6 +1,11 @@
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,7 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)kern_exit.c 8.1 (Berkeley) 6/14/93
+ *     @(#)kern_exit.c 8.7 (Berkeley) 2/12/94
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -94,7 +99,6 @@ exit1(p, rv)
        register struct proc *q, *nq;
        register struct proc **pp;
        register struct vmspace *vm;
        register struct proc *q, *nq;
        register struct proc **pp;
        register struct vmspace *vm;
-       int s;
 
        if (p->p_pid == 1)
                panic("init died (signal %d, exit %d)",
 
        if (p->p_pid == 1)
                panic("init died (signal %d, exit %d)",
@@ -102,18 +106,18 @@ exit1(p, rv)
 #ifdef PGINPROF
        vmsizmon();
 #endif
 #ifdef PGINPROF
        vmsizmon();
 #endif
-       if (p->p_flag & SPROFIL)
+       if (p->p_flag & P_PROFIL)
                stopprofclock(p);
        MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage),
                M_ZOMBIE, M_WAITOK);
        /*
         * If parent is waiting for us to exit or exec,
                stopprofclock(p);
        MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage),
                M_ZOMBIE, M_WAITOK);
        /*
         * If parent is waiting for us to exit or exec,
-        * SPPWAIT is set; we will wakeup the parent below.
+        * P_PPWAIT is set; we will wakeup the parent below.
         */
         */
-       p->p_flag &= ~(STRC|SPPWAIT);
-       p->p_flag |= SWEXIT;
+       p->p_flag &= ~(P_TRACED | P_PPWAIT);
+       p->p_flag |= P_WEXIT;
        p->p_sigignore = ~0;
        p->p_sigignore = ~0;
-       p->p_sig = 0;
+       p->p_siglist = 0;
        untimeout(realitexpire, (caddr_t)p);
 
        /*
        untimeout(realitexpire, (caddr_t)p);
 
        /*
@@ -154,9 +158,15 @@ exit1(p, rv)
                                if (sp->s_ttyp->t_pgrp)
                                        pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
                                (void) ttywait(sp->s_ttyp);
                                if (sp->s_ttyp->t_pgrp)
                                        pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
                                (void) ttywait(sp->s_ttyp);
-                               vgoneall(sp->s_ttyvp);
+                               /*
+                                * The tty could have been revoked
+                                * if we blocked.
+                                */
+                               if (sp->s_ttyvp)
+                                       vgoneall(sp->s_ttyvp);
                        }
                        }
-                       vrele(sp->s_ttyvp);
+                       if (sp->s_ttyvp)
+                               vrele(sp->s_ttyvp);
                        sp->s_ttyvp = NULL;
                        /*
                         * s_ttyp is not zero'd; we use this to indicate
                        sp->s_ttyvp = NULL;
                        /*
                         * s_ttyp is not zero'd; we use this to indicate
@@ -181,10 +191,10 @@ exit1(p, rv)
         * Remove proc from allproc queue and pidhash chain.
         * Place onto zombproc.  Unlink from parent's child list.
         */
         * Remove proc from allproc queue and pidhash chain.
         * Place onto zombproc.  Unlink from parent's child list.
         */
-       if (*p->p_prev = p->p_nxt)
-               p->p_nxt->p_prev = p->p_prev;
-       if (p->p_nxt = zombproc)
-               p->p_nxt->p_prev = &p->p_nxt;
+       if (*p->p_prev = p->p_next)
+               p->p_next->p_prev = p->p_prev;
+       if (p->p_next = zombproc)
+               p->p_next->p_prev = &p->p_next;
        p->p_prev = &zombproc;
        zombproc = p;
        p->p_stat = SZOMB;
        p->p_prev = &zombproc;
        zombproc = p;
        p->p_stat = SZOMB;
@@ -214,8 +224,8 @@ done:
                 * Traced processes are killed
                 * since their existence means someone is screwing up.
                 */
                 * Traced processes are killed
                 * since their existence means someone is screwing up.
                 */
-               if (q->p_flag&STRC) {
-                       q->p_flag &= ~STRC;
+               if (q->p_flag & P_TRACED) {
+                       q->p_flag &= ~P_TRACED;
                        psignal(q, SIGKILL);
                }
        }
                        psignal(q, SIGKILL);
                }
        }
@@ -320,11 +330,7 @@ wait4(p, uap, retval)
 #define        wait1   wait4
 #endif
 
 #define        wait1   wait4
 #endif
 
-/*
- * Wait: check child processes to see if any have exited,
- * stopped under trace, or (optionally) stopped by a signal.
- * Pass back status and deallocate exited child's proc structure.
- */
+int
 wait1(q, uap, retval)
        register struct proc *q;
        register struct wait_args *uap;
 wait1(q, uap, retval)
        register struct proc *q;
        register struct wait_args *uap;
@@ -391,13 +397,19 @@ loop:
                                FREE(p->p_cred, M_SUBPROC);
                        }
 
                                FREE(p->p_cred, M_SUBPROC);
                        }
 
+                       /*
+                        * Release reference to text vnode
+                        */
+                       if (p->p_textvp)
+                               vrele(p->p_textvp);
+
                        /*
                         * Finally finished with old proc entry.
                         * Unlink it from its process group and free it.
                         */
                        leavepgrp(p);
                        /*
                         * Finally finished with old proc entry.
                         * Unlink it from its process group and free it.
                         */
                        leavepgrp(p);
-                       if (*p->p_prev = p->p_nxt)      /* off zombproc */
-                               p->p_nxt->p_prev = p->p_prev;
+                       if (*p->p_prev = p->p_next)     /* off zombproc */
+                               p->p_next->p_prev = p->p_prev;
                        if (q = p->p_ysptr)
                                q->p_osptr = p->p_osptr;
                        if (q = p->p_osptr)
                        if (q = p->p_ysptr)
                                q->p_osptr = p->p_osptr;
                        if (q = p->p_osptr)
@@ -415,9 +427,9 @@ loop:
                        nprocs--;
                        return (0);
                }
                        nprocs--;
                        return (0);
                }
-               if (p->p_stat == SSTOP && (p->p_flag & SWTED) == 0 &&
-                   (p->p_flag & STRC || uap->options & WUNTRACED)) {
-                       p->p_flag |= SWTED;
+               if (p->p_stat == SSTOP && (p->p_flag & P_WAITED) == 0 &&
+                   (p->p_flag & P_TRACED || uap->options & WUNTRACED)) {
+                       p->p_flag |= P_WAITED;
                        retval[0] = p->p_pid;
 #ifdef COMPAT_43
                        if (uap->compat) {
                        retval[0] = p->p_pid;
 #ifdef COMPAT_43
                        if (uap->compat) {