From John Dyson - fix for bug in kern_physio where buffers would be
[unix-history] / sys / kern / kern_exit.c
index 7be0727..6109310 100644 (file)
@@ -30,7 +30,8 @@
  * 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 7.35 (Berkeley) 6/27/91
+ *     from: @(#)kern_exit.c   7.35 (Berkeley) 6/27/91
+ *     $Id: kern_exit.c,v 1.14 1994/01/29 04:04:23 davidg Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -47,6 +48,7 @@
 #include "vnode.h"
 #include "syslog.h"
 #include "malloc.h"
 #include "vnode.h"
 #include "syslog.h"
 #include "malloc.h"
+#include "signalvar.h"
 #include "resourcevar.h"
 
 #include "machine/cpu.h"
 #include "resourcevar.h"
 
 #include "machine/cpu.h"
 struct rexit_args {
        int     rval;
 };
 struct rexit_args {
        int     rval;
 };
-
 /* ARGSUSED */
 /* ARGSUSED */
-volatile void
+void
 rexit(p, uap, retval)
        struct proc *p;
        struct rexit_args *uap;
        int *retval;
 {
 
 rexit(p, uap, retval)
        struct proc *p;
        struct rexit_args *uap;
        int *retval;
 {
 
-       exit(p, W_EXITCODE(uap->rval, 0));
+       kexit(p, W_EXITCODE(uap->rval, 0));
        /* NOTREACHED */
        /* NOTREACHED */
-       return(0);      /* XXX added to stop gcc from issuing warning */
 }
 
 /*
 }
 
 /*
@@ -85,7 +85,8 @@ rexit(p, uap, retval)
  * and parent's lists.  Save exit status and rusage for wait().
  * Check for child processes and orphan them.
  */
  * and parent's lists.  Save exit status and rusage for wait().
  * Check for child processes and orphan them.
  */
-exit(p, rv)
+void
+kexit(p, rv)
        register struct proc *p;
        int rv;
 {
        register struct proc *p;
        int rv;
 {
@@ -93,6 +94,9 @@ exit(p, rv)
        register struct proc **pp;
        int s;
 
        register struct proc **pp;
        int s;
 
+       acct(p);        /* MT - do  process accounting -- must be done before
+                          address space is released */
+
 #ifdef PGINPROF
        vmsizmon();
 #endif
 #ifdef PGINPROF
        vmsizmon();
 #endif
@@ -114,6 +118,10 @@ exit(p, rv)
         */
        fdfree(p);
 
         */
        fdfree(p);
 
+#ifdef SYSVSEM
+       semexit(p);
+#endif
+
        /* The next two chunks should probably be moved to vmspace_exit. */
 #ifdef SYSVSHM
        if (p->p_vmspace->vm_shm)
        /* The next two chunks should probably be moved to vmspace_exit. */
 #ifdef SYSVSHM
        if (p->p_vmspace->vm_shm)
@@ -150,7 +158,7 @@ exit(p, rv)
                                (void) ttywait(sp->s_ttyp);
                                vgoneall(sp->s_ttyvp);
                        }
                                (void) ttywait(sp->s_ttyp);
                                vgoneall(sp->s_ttyvp);
                        }
-                       vrele(sp->s_ttyvp);
+                       vn_close(sp->s_ttyvp, FREAD, p->p_ucred, p);
                        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
@@ -167,19 +175,9 @@ exit(p, rv)
         * release trace file
         */
        if (p->p_tracep)
         * release trace file
         */
        if (p->p_tracep)
-               vrele(p->p_tracep);
+               vn_close(p->p_tracep, FREAD|FWRITE, p->p_ucred, p);
 #endif
 
 #endif
 
-       /* current process does not exist, as far as other parts of the
-        * system (clock) is concerned, since parts of it might not be
-        * there anymore */
-       curproc = NULL;
-
-       if (--p->p_limit->p_refcnt == 0) {
-               FREE(p->p_limit, M_SUBPROC);
-               p->p_limit = (struct plimit *) -1;
-       }
-
        /*
         * 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.
@@ -242,6 +240,18 @@ done:
        /* move this to cpu_exit */
        p->p_addr->u_pcb.pcb_savacc.faddr = (float *)NULL;
 #endif
        /* move this to cpu_exit */
        p->p_addr->u_pcb.pcb_savacc.faddr = (float *)NULL;
 #endif
+       /*
+        * current process does not exist, as far as other parts of the
+        * system (clock) is concerned, since parts of it might not be
+        * there anymore
+        */
+       curproc = NULL;
+
+       if (--p->p_limit->p_refcnt == 0) {
+               FREE(p->p_limit, M_SUBPROC);
+               p->p_limit = (struct plimit *) -1;
+       }
+
        /*
         * Finally, call machine-dependent code to release the remaining
         * resources including address space, the kernel stack and pcb.
        /*
         * Finally, call machine-dependent code to release the remaining
         * resources including address space, the kernel stack and pcb.
@@ -255,7 +265,24 @@ done:
        /* NOTREACHED */
 }
 
        /* NOTREACHED */
 }
 
+/*
+ * 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.
+ */
+
+struct wait1_args {
+       int     pid;
+       int     *status;
+       int     options;
+       struct  rusage *rusage;
+#ifdef COMPAT_43
+       int compat;
+#endif
+};
+
 #ifdef COMPAT_43
 #ifdef COMPAT_43
+static int wait1(struct proc *, struct wait1_args *, int *);
 
 struct owait_args {
        int     pid;
 
 struct owait_args {
        int     pid;
@@ -265,6 +292,7 @@ struct owait_args {
        int     compat;
 };
 
        int     compat;
 };
 
+int
 owait(p, uap, retval)
        struct proc *p;
        register struct owait_args *uap;
 owait(p, uap, retval)
        struct proc *p;
        register struct owait_args *uap;
@@ -276,7 +304,7 @@ owait(p, uap, retval)
        uap->pid = WAIT_ANY;
        uap->status = 0;
        uap->compat = 1;
        uap->pid = WAIT_ANY;
        uap->status = 0;
        uap->compat = 1;
-       return (wait1(p, uap, retval));
+       return (wait1(p, (struct wait1_args *)uap, retval));
 }
 
 struct wait4_args {
 }
 
 struct wait4_args {
@@ -287,6 +315,7 @@ struct wait4_args {
        int     compat;
 };
 
        int     compat;
 };
 
+int
 wait4(p, uap, retval)
        struct proc *p;
        struct wait4_args *uap;
 wait4(p, uap, retval)
        struct proc *p;
        struct wait4_args *uap;
@@ -294,28 +323,13 @@ wait4(p, uap, retval)
 {
 
        uap->compat = 0;
 {
 
        uap->compat = 0;
-       return (wait1(p, uap, retval));
+       return (wait1(p, (struct wait1_args *)uap, retval));
 }
 #else
 #define        wait1   wait4
 #endif
 
 }
 #else
 #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.
- */
-
-struct wait1_args {
-       int     pid;
-       int     *status;
-       int     options;
-       struct  rusage *rusage;
-#ifdef COMPAT_43
-       int compat;
-#endif
-};
-
+static int
 wait1(q, uap, retval)
        register struct proc *q;
        register struct wait1_args *uap;
 wait1(q, uap, retval)
        register struct proc *q;
        register struct wait1_args *uap;
@@ -339,6 +353,9 @@ loop:
                        continue;
                nfound++;
                if (p->p_stat == SZOMB) {
                        continue;
                nfound++;
                if (p->p_stat == SZOMB) {
+                       /* charge childs cpu usage to parent */
+                       if( curproc->p_pid != 1)
+                               curproc->p_cpu += p->p_cpu;
                        retval[0] = p->p_pid;
 #ifdef COMPAT_43
                        if (uap->compat)
                        retval[0] = p->p_pid;
 #ifdef COMPAT_43
                        if (uap->compat)