X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/fe7f81f488465fb5012a4eee4707836281dda86d..e950748be99d47c449cad95598fec793143b49b1:/usr/src/sys/kern/kern_exit.c diff --git a/usr/src/sys/kern/kern_exit.c b/usr/src/sys/kern/kern_exit.c index 2435042ed6..2511e066e1 100644 --- a/usr/src/sys/kern/kern_exit.c +++ b/usr/src/sys/kern/kern_exit.c @@ -1,4 +1,10 @@ -/* kern_exit.c 6.6 85/03/12 */ +/* + * Copyright (c) 1982, 1986 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + * + * @(#)kern_exit.c 7.4 (Berkeley) %G% + */ #include "../machine/reg.h" #include "../machine/psl.h" @@ -14,8 +20,9 @@ #include "wait.h" #include "vm.h" #include "file.h" -#include "mbuf.h" #include "inode.h" +#include "syslog.h" +#include "malloc.h" /* * Exit system call: pass back caller's arg @@ -43,12 +50,13 @@ exit(rv) register int i; register struct proc *p, *q, *nq; register int x; - struct mbuf *m = m_getclr(M_WAIT, MT_ZOMBIE); #ifdef PGINPROF vmsizmon(); #endif p = u.u_procp; + MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage), + M_ZOMBIE, M_WAITOK); p->p_flag &= ~(STRC|SULOCK); p->p_flag |= SWEXIT; p->p_sigignore = ~0; @@ -71,13 +79,15 @@ exit(rv) sleep((caddr_t)p, PZERO - 1); p->p_flag &= ~SVFDONE; } - for (i = 0; i < NOFILE; i++) { + for (i = 0; i <= u.u_lastfile; i++) { struct file *f; f = u.u_ofile[i]; - u.u_ofile[i] = NULL; - u.u_pofile[i] = 0; - closef(f); + if (f) { + u.u_ofile[i] = NULL; + u.u_pofile[i] = 0; + closef(f); + } } ilock(u.u_cdir); iput(u.u_cdir); @@ -90,9 +100,14 @@ exit(rv) #ifdef QUOTA qclean(); #endif - vrelpt(u.u_procp); + /* + * Freeing the user structure and kernel stack + * for the current process: have to run a bit longer + * using the pages which are about to be freed... + * vrelu will block memory allocation by raising ipl. + */ vrelu(u.u_procp, 0); - (void) spl5(); /* hack for mem alloc race XXX */ + vrelpt(u.u_procp); if (*p->p_prev = p->p_nxt) /* off allproc queue */ p->p_nxt->p_prev = p->p_prev; if (p->p_nxt = zombproc) /* onto zombproc */ @@ -114,13 +129,16 @@ exit(rv) } panic("exit"); } - if (p->p_pid == 1) - panic("init died"); + if (p->p_pid == 1) { + if (p->p_dsize == 0) { + printf("Can't exec /etc/init (errno %d)\n", rv >> 8); + for (;;) + ; + } else + panic("init died"); + } done: p->p_xstat = rv; -if (m == 0) -panic("exit: m_getclr"); - p->p_ru = mtod(m, struct rusage *); *p->p_ru = u.u_ru; ruadd(p->p_ru, &u.u_cru); if (p->p_cptr) /* only need this if any child is S_ZOMB */ @@ -156,11 +174,16 @@ panic("exit: m_getclr"); * Protect this process from future * tty signals, clear TSTP/TTIN/TTOU if pending. */ - (void) spgrp(q, -1); + (void) spgrp(q); } p->p_cptr = NULL; psignal(p->p_pptr, SIGCHLD); wakeup((caddr_t)p->p_pptr); +#if defined(tahoe) + dkeyrelease(p->p_dkey), p->p_dkey = 0; + ckeyrelease(p->p_ckey), p->p_ckey = 0; + u.u_pcb.pcb_savacc.faddr = (float *)NULL; +#endif swtch(); } @@ -204,11 +227,13 @@ loop: u.u_r.r_val1 = p->p_pid; u.u_r.r_val2 = p->p_xstat; p->p_xstat = 0; - if (ru) + if (ru && p->p_ru) *ru = *p->p_ru; - ruadd(&u.u_cru, p->p_ru); - (void) m_free(dtom(p->p_ru)); - p->p_ru = 0; + if (p->p_ru) { + ruadd(&u.u_cru, p->p_ru); + FREE(p->p_ru, M_ZOMBIE); + p->p_ru = 0; + } p->p_stat = NULL; p->p_pid = 0; p->p_ppid = 0; @@ -252,8 +277,7 @@ loop: } if (setjmp(&u.u_qsave)) { p = u.u_procp; - if ((u.u_sigintr & sigmask(p->p_cursig)) != 0 || - (p->p_flag & SOUSIG) != 0) + if ((u.u_sigintr & sigmask(p->p_cursig)) != 0) return(EINTR); u.u_eosys = RESTARTSYS; return (0);