Cleanups for 4.4BSD-Lite
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 6 Sep 1993 00:36:09 +0000 (16:36 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 6 Sep 1993 00:36:09 +0000 (16:36 -0800)
SCCS-vsn: sys/kern/init_main.c 8.2
SCCS-vsn: sys/kern/kern_sig.c 8.2
SCCS-vsn: sys/kern/kern_resource.c 8.2
SCCS-vsn: sys/kern/vfs_conf.c 8.2

usr/src/sys/kern/init_main.c
usr/src/sys/kern/kern_resource.c
usr/src/sys/kern/kern_sig.c
usr/src/sys/kern/vfs_conf.c

index 5c1a37b..f546fe9 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)init_main.c 8.1 (Berkeley) %G%
+ *     @(#)init_main.c 8.2 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -38,10 +38,7 @@ char copyright[] =
 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California.  All rights reserved.\n\n";
 #endif
 
 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California.  All rights reserved.\n\n";
 #endif
 
-/*
- * Components of process 0;
- * never freed.
- */
+/* Components of the first process -- never freed. */
 struct session session0;
 struct pgrp pgrp0;
 struct proc proc0;
 struct session session0;
 struct pgrp pgrp0;
 struct proc proc0;
@@ -54,7 +51,6 @@ struct        proc *initproc, *pageproc;
 
 int    cmask = CMASK;
 extern struct user *proc0paddr;
 
 int    cmask = CMASK;
 extern struct user *proc0paddr;
-extern int (*mountroot)();
 
 struct vnode *rootvp, *swapdev_vp;
 int    boothowto;
 
 struct vnode *rootvp, *swapdev_vp;
 int    boothowto;
@@ -62,26 +58,26 @@ struct      timeval boottime;
 struct timeval runtime;
 
 /*
 struct timeval runtime;
 
 /*
- * System startup; initialize the world, create process 0,
- * mount root filesystem, and fork to create init and pagedaemon.
- * Most of the hard work is done in the lower-level initialization
- * routines including startup(), which does memory initialization
- * and autoconfiguration.
+ * System startup; initialize the world, create process 0, mount root
+ * filesystem, and fork to create init and pagedaemon.  Most of the
+ * hard work is done in the lower-level initialization routines including
+ * startup(), which does memory initialization and autoconfiguration.
  */
 main()
 {
  */
 main()
 {
-       register int i;
        register struct proc *p;
        register struct filedesc0 *fdp;
        register struct pdevinit *pdev;
        register struct proc *p;
        register struct filedesc0 *fdp;
        register struct pdevinit *pdev;
+       register int i;
        int s, rval[2];
        int s, rval[2];
+       extern int (*mountroot) __P((void));
        extern struct pdevinit pdevinit[];
        extern void roundrobin __P((void *));
        extern void schedcpu __P((void *));
 
        /*
        extern struct pdevinit pdevinit[];
        extern void roundrobin __P((void *));
        extern void schedcpu __P((void *));
 
        /*
-        * Initialize curproc before any possible traps/probes
-        * to simplify trap processing.
+        * Initialize the current process pointer (curproc) before
+        * any possible traps/probes to simplify trap processing.
         */
        p = &proc0;
        curproc = p;
         */
        p = &proc0;
        curproc = p;
@@ -96,9 +92,7 @@ main()
        kmeminit();
        cpu_startup();
 
        kmeminit();
        cpu_startup();
 
-       /*
-        * set up system process 0 (swapper)
-        */
+       /* Create process 0 (the swapper). */
        p = &proc0;
        curproc = p;
 
        p = &proc0;
        curproc = p;
 
@@ -116,17 +110,13 @@ main()
        p->p_nice = NZERO;
        bcopy("swapper", p->p_comm, sizeof ("swapper"));
 
        p->p_nice = NZERO;
        bcopy("swapper", p->p_comm, sizeof ("swapper"));
 
-       /*
-        * Setup credentials
-        */
+       /* Create credentials. */
        cred0.p_refcnt = 1;
        p->p_cred = &cred0;
        p->p_ucred = crget();
        p->p_ucred->cr_ngroups = 1;     /* group 0 */
 
        cred0.p_refcnt = 1;
        p->p_cred = &cred0;
        p->p_ucred = crget();
        p->p_ucred->cr_ngroups = 1;     /* group 0 */
 
-       /*
-        * Create the file descriptor table for process 0.
-        */
+       /* Create the file descriptor table. */
        fdp = &filedesc0;
        p->p_fd = &fdp->fd_fd;
        fdp->fd_fd.fd_refcnt = 1;
        fdp = &filedesc0;
        p->p_fd = &fdp->fd_fd;
        fdp->fd_fd.fd_refcnt = 1;
@@ -135,9 +125,7 @@ main()
        fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags;
        fdp->fd_fd.fd_nfiles = NDFILE;
 
        fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags;
        fdp->fd_fd.fd_nfiles = NDFILE;
 
-       /*
-        * Set initial limits
-        */
+       /* Create the limits structures. */
        p->p_limit = &limit0;
        for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
                limit0.pl_rlimit[i].rlim_cur =
        p->p_limit = &limit0;
        for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
                limit0.pl_rlimit[i].rlim_cur =
@@ -150,9 +138,7 @@ main()
        limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3;
        limit0.p_refcnt = 1;
 
        limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3;
        limit0.p_refcnt = 1;
 
-       /*
-        * Allocate a prototype map so we have something to fork
-        */
+       /* Allocate a prototype map so we have something to fork. */
        p->p_vmspace = &vmspace0;
        vmspace0.vm_refcnt = 1;
        pmap_pinit(&vmspace0.vm_pmap);
        p->p_vmspace = &vmspace0;
        vmspace0.vm_refcnt = 1;
        pmap_pinit(&vmspace0.vm_pmap);
@@ -162,8 +148,8 @@ main()
        p->p_addr = proc0paddr;                         /* XXX */
 
        /*
        p->p_addr = proc0paddr;                         /* XXX */
 
        /*
-        * We continue to place resource usage info
-        * and signal actions in the user struct so they're pageable.
+        * We continue to place resource usage info and signal
+        * actions in the user struct so they're pageable.
         */
        p->p_stats = &p->p_addr->u_stats;
        p->p_sigacts = &p->p_addr->u_sigacts;
         */
        p->p_stats = &p->p_addr->u_stats;
        p->p_sigacts = &p->p_addr->u_sigacts;
@@ -186,10 +172,14 @@ main()
        /* Start real time and statistics clocks. */
        initclocks();
 
        /* Start real time and statistics clocks. */
        initclocks();
 
-       /* Initialize tables. */
+       /* Initialize mbuf's. */
        mbinit();
        mbinit();
-       cinit();
+
+       /* Initialize clists. */
+       clist_init();
+
 #ifdef SYSVSHM
 #ifdef SYSVSHM
+       /* Initialize System V style shared memory. */
        shminit();
 #endif
 
        shminit();
 #endif
 
@@ -207,27 +197,24 @@ main()
        splx(s);
 
 #ifdef GPROF
        splx(s);
 
 #ifdef GPROF
+       /* Initialize kernel profiling. */
        kmstartup();
 #endif
 
        kmstartup();
 #endif
 
-       /* kick off timeout driven events by calling first time */
+       /* Kick off timeout driven events by calling first time. */
        roundrobin(NULL);
        schedcpu(NULL);
 
        roundrobin(NULL);
        schedcpu(NULL);
 
-       /*
-        * Set up the root file system and vnode.
-        */
+       /* Mount the root file system. */
        if ((*mountroot)())
                panic("cannot mount root");
        if ((*mountroot)())
                panic("cannot mount root");
-       /*
-        * Get vnode for '/'.
-        * Setup rootdir and fdp->fd_fd.fd_cdir to point to it.
-        */
-       if (VFS_ROOT(rootfs, &rootdir))
+
+       /* Get the vnode for '/'.  Set fdp->fd_fd.fd_cdir to reference it. */
+       if (VFS_ROOT(rootfs, &rootvnode))
                panic("cannot find root vnode");
                panic("cannot find root vnode");
-       fdp->fd_fd.fd_cdir = rootdir;
+       fdp->fd_fd.fd_cdir = rootvnode;
        VREF(fdp->fd_fd.fd_cdir);
        VREF(fdp->fd_fd.fd_cdir);
-       VOP_UNLOCK(rootdir);
+       VOP_UNLOCK(rootvnode);
        fdp->fd_fd.fd_rdir = NULL;
        swapinit();
 
        fdp->fd_fd.fd_rdir = NULL;
        swapinit();
 
@@ -239,10 +226,10 @@ main()
        p->p_stats->p_start = runtime = mono_time = boottime = time;
        p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
 
        p->p_stats->p_start = runtime = mono_time = boottime = time;
        p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
 
-       /*
-        * make init process
-        */
+       /* Initialize signal state for process 0. */
        siginit(p);
        siginit(p);
+
+       /* Create process 1 (init(8)). */
        if (fork(p, NULL, rval))
                panic("fork init");
        if (rval[1]) {
        if (fork(p, NULL, rval))
                panic("fork init");
        if (rval[1]) {
@@ -275,7 +262,7 @@ main()
                    addr != VM_MIN_ADDRESS)
                        panic("init: couldn't allocate at zero");
 
                    addr != VM_MIN_ADDRESS)
                        panic("init: couldn't allocate at zero");
 
-               /* need just enough stack to exec from */
+               /* Need just enough stack from which to exec. */
                addr = trunc_page(USRSTACK - PAGE_SIZE);
                if (vm_allocate(&p->p_vmspace->vm_map, &addr,
                    PAGE_SIZE, FALSE) != KERN_SUCCESS)
                addr = trunc_page(USRSTACK - PAGE_SIZE);
                if (vm_allocate(&p->p_vmspace->vm_map, &addr,
                    PAGE_SIZE, FALSE) != KERN_SUCCESS)
@@ -288,9 +275,7 @@ main()
                return;                 /* returns to icode */
        }
 
                return;                 /* returns to icode */
        }
 
-       /*
-        * Start up pageout daemon (process 2).
-        */
+       /* Create process 2 (the pageout daemon). */
        if (fork(p, NULL, rval))
                panic("fork pager");
        if (rval[1]) {
        if (fork(p, NULL, rval))
                panic("fork pager");
        if (rval[1]) {
@@ -302,11 +287,10 @@ main()
                p->p_flag |= SLOAD|SSYS;                /* XXX */
                bcopy("pagedaemon", curproc->p_comm, sizeof ("pagedaemon"));
                vm_pageout();
                p->p_flag |= SLOAD|SSYS;                /* XXX */
                bcopy("pagedaemon", curproc->p_comm, sizeof ("pagedaemon"));
                vm_pageout();
-               /*NOTREACHED*/
+               /* NOTREACHED */
        }
 
        }
 
-       /*
-        * enter scheduling loop
-        */
-       sched();
+       /* The scheduler is an infinite loop. */
+       scheduler();
+       /* NOTREACHED */
 }
 }
index 783bb9a..c1d9b4a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_resource.c     8.1 (Berkeley) %G%
+ *     @(#)kern_resource.c     8.2 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -153,7 +153,7 @@ donice(curp, chgp, n)
        if (n < chgp->p_nice && suser(pcred->pc_ucred, &curp->p_acflag))
                return (EACCES);
        chgp->p_nice = n;
        if (n < chgp->p_nice && suser(pcred->pc_ucred, &curp->p_acflag))
                return (EACCES);
        chgp->p_nice = n;
-       (void) setpri(chgp);
+       (void)resetpriority(chgp);
        return (0);
 }
 
        return (0);
 }
 
index 5518e3c..bb5bc93 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_sig.c  8.1 (Berkeley) %G%
+ *     @(#)kern_sig.c  8.2 (Berkeley) %G%
  */
 
 #define        SIGPROP         /* include signal properties table */
  */
 
 #define        SIGPROP         /* include signal properties table */
@@ -24,6 +24,7 @@
 #include <sys/wait.h>
 #include <sys/ktrace.h>
 #include <sys/syslog.h>
 #include <sys/wait.h>
 #include <sys/ktrace.h>
 #include <sys/syslog.h>
+#include <sys/stat.h>
 
 #include <machine/cpu.h>
 
 
 #include <machine/cpu.h>
 
 #include <sys/user.h>          /* for coredump */
 
 /*
 #include <sys/user.h>          /* for coredump */
 
 /*
- * Can process p, with pcred pc, send the signal signo to process q?
+ * Can process p, with pcred pc, send the signal signum to process q?
  */
  */
-#define CANSIGNAL(p, pc, q, signo) \
+#define CANSIGNAL(p, pc, q, signum) \
        ((pc)->pc_ucred->cr_uid == 0 || \
            (pc)->p_ruid == (q)->p_cred->p_ruid || \
            (pc)->pc_ucred->cr_uid == (q)->p_cred->p_ruid || \
            (pc)->p_ruid == (q)->p_ucred->cr_uid || \
            (pc)->pc_ucred->cr_uid == (q)->p_ucred->cr_uid || \
        ((pc)->pc_ucred->cr_uid == 0 || \
            (pc)->p_ruid == (q)->p_cred->p_ruid || \
            (pc)->pc_ucred->cr_uid == (q)->p_cred->p_ruid || \
            (pc)->p_ruid == (q)->p_ucred->cr_uid || \
            (pc)->pc_ucred->cr_uid == (q)->p_ucred->cr_uid || \
-           ((signo) == SIGCONT && (q)->p_session == (p)->p_session))
+           ((signum) == SIGCONT && (q)->p_session == (p)->p_session))
 
 struct sigaction_args {
 
 struct sigaction_args {
-       int     signo;
+       int     signum;
        struct  sigaction *nsa;
        struct  sigaction *osa;
 };
        struct  sigaction *nsa;
        struct  sigaction *osa;
 };
@@ -55,17 +56,18 @@ sigaction(p, uap, retval)
        struct sigaction vec;
        register struct sigaction *sa;
        register struct sigacts *ps = p->p_sigacts;
        struct sigaction vec;
        register struct sigaction *sa;
        register struct sigacts *ps = p->p_sigacts;
-       register int sig;
+       register int signum;
        int bit, error;
 
        int bit, error;
 
-       sig = uap->signo;
-       if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
+       signum = uap->signum;
+       if (signum <= 0 || signum >= NSIG ||
+           signum == SIGKILL || signum == SIGSTOP)
                return (EINVAL);
        sa = &vec;
        if (uap->osa) {
                return (EINVAL);
        sa = &vec;
        if (uap->osa) {
-               sa->sa_handler = ps->ps_sigact[sig];
-               sa->sa_mask = ps->ps_catchmask[sig];
-               bit = sigmask(sig);
+               sa->sa_handler = ps->ps_sigact[signum];
+               sa->sa_mask = ps->ps_catchmask[signum];
+               bit = sigmask(signum);
                sa->sa_flags = 0;
                if ((ps->ps_sigonstack & bit) != 0)
                        sa->sa_flags |= SA_ONSTACK;
                sa->sa_flags = 0;
                if ((ps->ps_sigonstack & bit) != 0)
                        sa->sa_flags |= SA_ONSTACK;
@@ -81,26 +83,26 @@ sigaction(p, uap, retval)
                if (error = copyin((caddr_t)uap->nsa, (caddr_t)sa,
                    sizeof (vec)))
                        return (error);
                if (error = copyin((caddr_t)uap->nsa, (caddr_t)sa,
                    sizeof (vec)))
                        return (error);
-               setsigvec(p, sig, sa);
+               setsigvec(p, signum, sa);
        }
        return (0);
 }
 
        }
        return (0);
 }
 
-setsigvec(p, sig, sa)
+setsigvec(p, signum, sa)
        register struct proc *p;
        register struct proc *p;
-       int sig;
+       int signum;
        register struct sigaction *sa;
 {
        register struct sigacts *ps = p->p_sigacts;
        register int bit;
 
        register struct sigaction *sa;
 {
        register struct sigacts *ps = p->p_sigacts;
        register int bit;
 
-       bit = sigmask(sig);
+       bit = sigmask(signum);
        /*
         * Change setting atomically.
         */
        (void) splhigh();
        /*
         * Change setting atomically.
         */
        (void) splhigh();
-       ps->ps_sigact[sig] = sa->sa_handler;
-       ps->ps_catchmask[sig] = sa->sa_mask &~ sigcantmask;
+       ps->ps_sigact[signum] = sa->sa_handler;
+       ps->ps_catchmask[signum] = sa->sa_mask &~ sigcantmask;
        if ((sa->sa_flags & SA_RESTART) == 0)
                ps->ps_sigintr |= bit;
        else
        if ((sa->sa_flags & SA_RESTART) == 0)
                ps->ps_sigintr |= bit;
        else
@@ -115,7 +117,7 @@ setsigvec(p, sig, sa)
        else
                ps->ps_usertramp &= ~bit;
 #endif
        else
                ps->ps_usertramp &= ~bit;
 #endif
-       if (sig == SIGCHLD) {
+       if (signum == SIGCHLD) {
                if (sa->sa_flags & SA_NOCLDSTOP)
                        p->p_flag |= SNOCLDSTOP;
                else
                if (sa->sa_flags & SA_NOCLDSTOP)
                        p->p_flag |= SNOCLDSTOP;
                else
@@ -128,9 +130,9 @@ setsigvec(p, sig, sa)
         * as we have to restart the process.
         */
        if (sa->sa_handler == SIG_IGN ||
         * as we have to restart the process.
         */
        if (sa->sa_handler == SIG_IGN ||
-           (sigprop[sig] & SA_IGNORE && sa->sa_handler == SIG_DFL)) {
+           (sigprop[signum] & SA_IGNORE && sa->sa_handler == SIG_DFL)) {
                p->p_sig &= ~bit;               /* never to be seen again */
                p->p_sig &= ~bit;               /* never to be seen again */
-               if (sig != SIGCONT)
+               if (signum != SIGCONT)
                        p->p_sigignore |= bit;  /* easier in psignal */
                p->p_sigcatch &= ~bit;
        } else {
                        p->p_sigignore |= bit;  /* easier in psignal */
                p->p_sigcatch &= ~bit;
        } else {
@@ -254,7 +256,7 @@ sigpending(p, uap, retval)
  * Generalized interface signal handler, 4.3-compatible.
  */
 struct osigvec_args {
  * Generalized interface signal handler, 4.3-compatible.
  */
 struct osigvec_args {
-       int     signo;
+       int     signum;
        struct  sigvec *nsv;
        struct  sigvec *osv;
 };
        struct  sigvec *nsv;
        struct  sigvec *osv;
 };
@@ -267,17 +269,18 @@ osigvec(p, uap, retval)
        struct sigvec vec;
        register struct sigacts *ps = p->p_sigacts;
        register struct sigvec *sv;
        struct sigvec vec;
        register struct sigacts *ps = p->p_sigacts;
        register struct sigvec *sv;
-       register int sig;
+       register int signum;
        int bit, error;
 
        int bit, error;
 
-       sig = uap->signo;
-       if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
+       signum = uap->signum;
+       if (signum <= 0 || signum >= NSIG ||
+           signum == SIGKILL || signum == SIGSTOP)
                return (EINVAL);
        sv = &vec;
        if (uap->osv) {
                return (EINVAL);
        sv = &vec;
        if (uap->osv) {
-               *(sig_t *)&sv->sv_handler = ps->ps_sigact[sig];
-               sv->sv_mask = ps->ps_catchmask[sig];
-               bit = sigmask(sig);
+               *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
+               sv->sv_mask = ps->ps_catchmask[signum];
+               bit = sigmask(signum);
                sv->sv_flags = 0;
                if ((ps->ps_sigonstack & bit) != 0)
                        sv->sv_flags |= SV_ONSTACK;
                sv->sv_flags = 0;
                if ((ps->ps_sigonstack & bit) != 0)
                        sv->sv_flags |= SV_ONSTACK;
@@ -306,7 +309,7 @@ osigvec(p, uap, retval)
                sv->sv_flags |= SA_USERTRAMP;
 #endif
                sv->sv_flags ^= SA_RESTART;     /* opposite of SV_INTERRUPT */
                sv->sv_flags |= SA_USERTRAMP;
 #endif
                sv->sv_flags ^= SA_RESTART;     /* opposite of SV_INTERRUPT */
-               setsigvec(p, sig, (struct sigaction *)sv);
+               setsigvec(p, signum, (struct sigaction *)sv);
        }
        return (0);
 }
        }
        return (0);
 }
@@ -448,7 +451,7 @@ sigaltstack(p, uap, retval)
 
 struct kill_args {
        int     pid;
 
 struct kill_args {
        int     pid;
-       int     signo;
+       int     signum;
 };
 /* ARGSUSED */
 kill(cp, uap, retval)
 };
 /* ARGSUSED */
 kill(cp, uap, retval)
@@ -459,26 +462,25 @@ kill(cp, uap, retval)
        register struct proc *p;
        register struct pcred *pc = cp->p_cred;
 
        register struct proc *p;
        register struct pcred *pc = cp->p_cred;
 
-       if ((unsigned) uap->signo >= NSIG)
+       if ((u_int)uap->signum >= NSIG)
                return (EINVAL);
        if (uap->pid > 0) {
                /* kill single process */
                return (EINVAL);
        if (uap->pid > 0) {
                /* kill single process */
-               p = pfind(uap->pid);
-               if (p == 0)
+               if ((p = pfind(uap->pid)) == NULL)
                        return (ESRCH);
                        return (ESRCH);
-               if (!CANSIGNAL(cp, pc, p, uap->signo))
+               if (!CANSIGNAL(cp, pc, p, uap->signum))
                        return (EPERM);
                        return (EPERM);
-               if (uap->signo)
-                       psignal(p, uap->signo);
+               if (uap->signum)
+                       psignal(p, uap->signum);
                return (0);
        }
        switch (uap->pid) {
        case -1:                /* broadcast signal */
                return (0);
        }
        switch (uap->pid) {
        case -1:                /* broadcast signal */
-               return (killpg1(cp, uap->signo, 0, 1));
+               return (killpg1(cp, uap->signum, 0, 1));
        case 0:                 /* signal own process group */
        case 0:                 /* signal own process group */
-               return (killpg1(cp, uap->signo, 0, 0));
+               return (killpg1(cp, uap->signum, 0, 0));
        default:                /* negative explicit process group */
        default:                /* negative explicit process group */
-               return (killpg1(cp, uap->signo, -uap->pid, 0));
+               return (killpg1(cp, uap->signum, -uap->pid, 0));
        }
        /* NOTREACHED */
 }
        }
        /* NOTREACHED */
 }
@@ -486,7 +488,7 @@ kill(cp, uap, retval)
 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
 struct okillpg_args {
        int     pgid;
 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
 struct okillpg_args {
        int     pgid;
-       int     signo;
+       int     signum;
 };
 /* ARGSUSED */
 okillpg(p, uap, retval)
 };
 /* ARGSUSED */
 okillpg(p, uap, retval)
@@ -495,9 +497,9 @@ okillpg(p, uap, retval)
        int *retval;
 {
 
        int *retval;
 {
 
-       if ((unsigned) uap->signo >= NSIG)
+       if ((u_int)uap->signum >= NSIG)
                return (EINVAL);
                return (EINVAL);
-       return (killpg1(p, uap->signo, uap->pgid, 0));
+       return (killpg1(p, uap->signum, uap->pgid, 0));
 }
 #endif /* COMPAT_43 || COMPAT_SUNOS */
 
 }
 #endif /* COMPAT_43 || COMPAT_SUNOS */
 
@@ -505,9 +507,9 @@ okillpg(p, uap, retval)
  * Common code for kill process group/broadcast kill.
  * cp is calling process.
  */
  * Common code for kill process group/broadcast kill.
  * cp is calling process.
  */
-killpg1(cp, signo, pgid, all)
+killpg1(cp, signum, pgid, all)
        register struct proc *cp;
        register struct proc *cp;
-       int signo, pgid, all;
+       int signum, pgid, all;
 {
        register struct proc *p;
        register struct pcred *pc = cp->p_cred;
 {
        register struct proc *p;
        register struct pcred *pc = cp->p_cred;
@@ -520,11 +522,11 @@ killpg1(cp, signo, pgid, all)
                 */
                for (p = (struct proc *)allproc; p != NULL; p = p->p_nxt) {
                        if (p->p_pid <= 1 || p->p_flag & SSYS || 
                 */
                for (p = (struct proc *)allproc; p != NULL; p = p->p_nxt) {
                        if (p->p_pid <= 1 || p->p_flag & SSYS || 
-                           p == cp || !CANSIGNAL(cp, pc, p, signo))
+                           p == cp || !CANSIGNAL(cp, pc, p, signum))
                                continue;
                        nfound++;
                                continue;
                        nfound++;
-                       if (signo)
-                               psignal(p, signo);
+                       if (signum)
+                               psignal(p, signum);
                }
        else {
                if (pgid == 0)          
                }
        else {
                if (pgid == 0)          
@@ -539,47 +541,45 @@ killpg1(cp, signo, pgid, all)
                }
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
                        if (p->p_pid <= 1 || p->p_flag & SSYS ||
                }
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
                        if (p->p_pid <= 1 || p->p_flag & SSYS ||
-                           p->p_stat == SZOMB || !CANSIGNAL(cp, pc, p, signo))
+                           p->p_stat == SZOMB ||
+                           !CANSIGNAL(cp, pc, p, signum))
                                continue;
                        nfound++;
                                continue;
                        nfound++;
-                       if (signo)
-                               psignal(p, signo);
+                       if (signum)
+                               psignal(p, signum);
                }
        }
        return (nfound ? 0 : ESRCH);
 }
 
 /*
                }
        }
        return (nfound ? 0 : ESRCH);
 }
 
 /*
- * Send the specified signal to
- * all processes with 'pgid' as
- * process group.
+ * Send a signal to a process group.
  */
 void
  */
 void
-gsignal(pgid, sig)
-       int pgid, sig;
+gsignal(pgid, signum)
+       int pgid, signum;
 {
        struct pgrp *pgrp;
 
        if (pgid && (pgrp = pgfind(pgid)))
 {
        struct pgrp *pgrp;
 
        if (pgid && (pgrp = pgfind(pgid)))
-               pgsignal(pgrp, sig, 0);
+               pgsignal(pgrp, signum, 0);
 }
 
 /*
 }
 
 /*
- * Send sig to every member of a process group.
- * If checktty is 1, limit to members which have a controlling
- * terminal.
+ * Send a signal to a  process group.  If checktty is 1,
+ * limit to members which have a controlling terminal.
  */
 void
  */
 void
-pgsignal(pgrp, sig, checkctty)
+pgsignal(pgrp, signum, checkctty)
        struct pgrp *pgrp;
        struct pgrp *pgrp;
-       int sig, checkctty;
+       int signum, checkctty;
 {
        register struct proc *p;
 
        if (pgrp)
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt)
                        if (checkctty == 0 || p->p_flag & SCTTY)
 {
        register struct proc *p;
 
        if (pgrp)
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt)
                        if (checkctty == 0 || p->p_flag & SCTTY)
-                               psignal(p, sig);
+                               psignal(p, signum);
 }
 
 /*
 }
 
 /*
@@ -588,56 +588,57 @@ pgsignal(pgrp, sig, checkctty)
  * Otherwise, post it normally.
  */
 void
  * Otherwise, post it normally.
  */
 void
-trapsignal(p, sig, code)
+trapsignal(p, signum, code)
        struct proc *p;
        struct proc *p;
-       register int sig;
-       unsigned code;
+       register int signum;
+       u_int code;
 {
        register struct sigacts *ps = p->p_sigacts;
        int mask;
 
 {
        register struct sigacts *ps = p->p_sigacts;
        int mask;
 
-       mask = sigmask(sig);
+       mask = sigmask(signum);
        if ((p->p_flag & STRC) == 0 && (p->p_sigcatch & mask) != 0 &&
            (p->p_sigmask & mask) == 0) {
                p->p_stats->p_ru.ru_nsignals++;
 #ifdef KTRACE
                if (KTRPOINT(p, KTR_PSIG))
        if ((p->p_flag & STRC) == 0 && (p->p_sigcatch & mask) != 0 &&
            (p->p_sigmask & mask) == 0) {
                p->p_stats->p_ru.ru_nsignals++;
 #ifdef KTRACE
                if (KTRPOINT(p, KTR_PSIG))
-                       ktrpsig(p->p_tracep, sig, ps->ps_sigact[sig], 
+                       ktrpsig(p->p_tracep, signum, ps->ps_sigact[signum], 
                                p->p_sigmask, code);
 #endif
                                p->p_sigmask, code);
 #endif
-               sendsig(ps->ps_sigact[sig], sig, p->p_sigmask, code);
-               p->p_sigmask |= ps->ps_catchmask[sig] | mask;
+               sendsig(ps->ps_sigact[signum], signum, p->p_sigmask, code);
+               p->p_sigmask |= ps->ps_catchmask[signum] | mask;
        } else {
                ps->ps_code = code;     /* XXX for core dump/debugger */
        } else {
                ps->ps_code = code;     /* XXX for core dump/debugger */
-               psignal(p, sig);
+               psignal(p, signum);
        }
 }
 
 /*
        }
 }
 
 /*
- * Send the specified signal to the specified process.
- * If the signal has an action, the action is usually performed
- * by the target process rather than the caller; we simply add
+ * Send the signal to the process.  If the signal has an action, the action
+ * is usually performed by the target process rather than the caller; we add
  * the signal to the set of pending signals for the process.
  * the signal to the set of pending signals for the process.
+ *
  * Exceptions:
  * Exceptions:
- *   o When a stop signal is sent to a sleeping process that takes the default
- *     action, the process is stopped without awakening it.
+ *   o When a stop signal is sent to a sleeping process that takes the
+ *     default action, the process is stopped without awakening it.
  *   o SIGCONT restarts stopped processes (or puts them back to sleep)
  *     regardless of the signal action (eg, blocked or ignored).
  *   o SIGCONT restarts stopped processes (or puts them back to sleep)
  *     regardless of the signal action (eg, blocked or ignored).
+ *
  * Other ignored signals are discarded immediately.
  */
 void
  * Other ignored signals are discarded immediately.
  */
 void
-psignal(p, sig)
+psignal(p, signum)
        register struct proc *p;
        register struct proc *p;
-       register int sig;
+       register int signum;
 {
        register int s, prop;
        register sig_t action;
        int mask;
 
 {
        register int s, prop;
        register sig_t action;
        int mask;
 
-       if ((unsigned)sig >= NSIG || sig == 0)
-               panic("psignal sig");
-       mask = sigmask(sig);
-       prop = sigprop[sig];
+       if ((u_int)signum >= NSIG || signum == 0)
+               panic("psignal signal number");
+       mask = sigmask(signum);
+       prop = sigprop[signum];
 
        /*
         * If proc is traced, always give parent a chance.
 
        /*
         * If proc is traced, always give parent a chance.
@@ -733,7 +734,7 @@ psignal(p, sig)
                        if (p->p_flag & SPPWAIT)
                                goto out;
                        p->p_sig &= ~mask;
                        if (p->p_flag & SPPWAIT)
                                goto out;
                        p->p_sig &= ~mask;
-                       p->p_xstat = sig;
+                       p->p_xstat = signum;
                        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);
@@ -753,7 +754,7 @@ psignal(p, sig)
                /*
                 * Kill signal always sets processes running.
                 */
                /*
                 * Kill signal always sets processes running.
                 */
-               if (sig == SIGKILL)
+               if (signum == SIGKILL)
                        goto runfast;
 
                if (prop & SA_CONT) {
                        goto runfast;
 
                if (prop & SA_CONT) {
@@ -821,22 +822,21 @@ out:
 }
 
 /*
 }
 
 /*
- * If the current process has a signal to process (should be caught
- * or cause termination, should interrupt current syscall),
- * return the signal number.  Stop signals with default action
- * are processed immediately, then cleared; they aren't returned.
- * This is checked after each entry to the system for a syscall
- * or trap (though this can usually be done without actually calling
- * issig by checking the pending signal masks in the CURSIG macro.)
- * The normal call sequence is
+ * If the current process has received a signal (should be caught or cause
+ * termination, should interrupt current syscall), return the signal number.
+ * Stop signals with default action are processed immediately, then cleared;
+ * they aren't returned.  This is checked after each entry to the system for
+ * a syscall or trap (though this can usually be done without calling issig
+ * by checking the pending signal masks in the CURSIG macro.) The normal call
+ * sequence is
  *
  *
- *     while (sig = CURSIG(curproc))
- *             psig(sig);
+ *     while (signum = CURSIG(curproc))
+ *             psig(signum);
  */
 issig(p)
        register struct proc *p;
 {
  */
 issig(p)
        register struct proc *p;
 {
-       register int sig, mask, prop;
+       register int signum, mask, prop;
 
        for (;;) {
                mask = p->p_sig &~ p->p_sigmask;
 
        for (;;) {
                mask = p->p_sig &~ p->p_sigmask;
@@ -844,9 +844,9 @@ issig(p)
                        mask &= ~stopsigmask;
                if (mask == 0)          /* no signal to send */
                        return (0);
                        mask &= ~stopsigmask;
                if (mask == 0)          /* no signal to send */
                        return (0);
-               sig = ffs((long)mask);
-               mask = sigmask(sig);
-               prop = sigprop[sig];
+               signum = ffs((long)mask);
+               mask = sigmask(signum);
+               prop = sigprop[signum];
                /*
                 * We should see pending but ignored signals
                 * only if STRC was on when they were posted.
                /*
                 * We should see pending but ignored signals
                 * only if STRC was on when they were posted.
@@ -860,7 +860,7 @@ issig(p)
                         * 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_xstat = sig;
+                       p->p_xstat = signum;
                        psignal(p->p_pptr, SIGCHLD);
                        do {
                                stop(p);
                        psignal(p->p_pptr, SIGCHLD);
                        do {
                                stop(p);
@@ -882,8 +882,8 @@ issig(p)
                         * 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_xstat;
-                       if (sig == 0)
+                       signum = p->p_xstat;
+                       if (signum == 0)
                                continue;
 
                        /*
                                continue;
 
                        /*
@@ -891,7 +891,7 @@ issig(p)
                         * If signal is being masked,
                         * look for other signals.
                         */
                         * If signal is being masked,
                         * look for other signals.
                         */
-                       mask = sigmask(sig);
+                       mask = sigmask(signum);
                        p->p_sig |= mask;
                        if (p->p_sigmask & mask)
                                continue;
                        p->p_sig |= mask;
                        if (p->p_sigmask & mask)
                                continue;
@@ -902,7 +902,7 @@ issig(p)
                 * Return the signal's number, or fall through
                 * to clear it from the pending mask.
                 */
                 * Return the signal's number, or fall through
                 * to clear it from the pending mask.
                 */
-               switch ((int)p->p_sigacts->ps_sigact[sig]) {
+               switch ((int)p->p_sigacts->ps_sigact[signum]) {
 
                case SIG_DFL:
                        /*
 
                case SIG_DFL:
                        /*
@@ -915,7 +915,7 @@ issig(p)
                                 * in init? XXX
                                 */
                                printf("Process (pid %d) got signal %d\n",
                                 * in init? XXX
                                 */
                                printf("Process (pid %d) got signal %d\n",
-                                       p->p_pid, sig);
+                                       p->p_pid, signum);
 #endif
                                break;          /* == ignore */
                        }
 #endif
                                break;          /* == ignore */
                        }
@@ -931,7 +931,7 @@ issig(p)
                                    (p->p_pgrp->pg_jobc == 0 &&
                                    prop & SA_TTYSTOP))
                                        break;  /* == ignore */
                                    (p->p_pgrp->pg_jobc == 0 &&
                                    prop & SA_TTYSTOP))
                                        break;  /* == ignore */
-                               p->p_xstat = sig;
+                               p->p_xstat = signum;
                                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);
@@ -944,7 +944,7 @@ issig(p)
                                 */
                                break;          /* == ignore */
                        } else
                                 */
                                break;          /* == ignore */
                        } else
-                               return (sig);
+                               return (signum);
                        /*NOTREACHED*/
 
                case SIG_IGN:
                        /*NOTREACHED*/
 
                case SIG_IGN:
@@ -962,7 +962,7 @@ issig(p)
                         * This signal has an action, let
                         * psig process it.
                         */
                         * This signal has an action, let
                         * psig process it.
                         */
-                       return (sig);
+                       return (signum);
                }
                p->p_sig &= ~mask;              /* take the signal! */
        }
                }
                p->p_sig &= ~mask;              /* take the signal! */
        }
@@ -970,10 +970,9 @@ issig(p)
 }
 
 /*
 }
 
 /*
- * Put the argument process into the stopped
- * state and notify the parent via wakeup.
- * Signals are handled elsewhere.
- * The process must not be on the run queue.
+ * Put the argument process into the stopped state and notify the parent
+ * via wakeup.  Signals are handled elsewhere.  The process must not be
+ * on the run queue.
  */
 stop(p)
        register struct proc *p;
  */
 stop(p)
        register struct proc *p;
@@ -989,8 +988,8 @@ stop(p)
  * from the current set of pending signals.
  */
 void
  * from the current set of pending signals.
  */
 void
-psig(sig)
-       register int sig;
+psig(signum)
+       register int signum;
 {
        register struct proc *p = curproc;
        register struct sigacts *ps = p->p_sigacts;
 {
        register struct proc *p = curproc;
        register struct sigacts *ps = p->p_sigacts;
@@ -998,15 +997,16 @@ psig(sig)
        int mask, returnmask;
 
 #ifdef DIAGNOSTIC
        int mask, returnmask;
 
 #ifdef DIAGNOSTIC
-       if (sig == 0)
+       if (signum == 0)
                panic("psig");
 #endif
                panic("psig");
 #endif
-       mask = sigmask(sig);
+       mask = sigmask(signum);
        p->p_sig &= ~mask;
        p->p_sig &= ~mask;
-       action = ps->ps_sigact[sig];
+       action = ps->ps_sigact[signum];
 #ifdef KTRACE
        if (KTRPOINT(p, KTR_PSIG))
 #ifdef KTRACE
        if (KTRPOINT(p, KTR_PSIG))
-               ktrpsig(p->p_tracep, sig, action, ps->ps_flags & SAS_OLDMASK ?
+               ktrpsig(p->p_tracep,
+                   signum, action, ps->ps_flags & SAS_OLDMASK ?
                    ps->ps_oldmask : p->p_sigmask, 0);
 #endif
        if (action == SIG_DFL) {
                    ps->ps_oldmask : p->p_sigmask, 0);
 #endif
        if (action == SIG_DFL) {
@@ -1014,7 +1014,7 @@ psig(sig)
                 * Default action, where the default is to kill
                 * the process.  (Other cases were ignored above.)
                 */
                 * Default action, where the default is to kill
                 * the process.  (Other cases were ignored above.)
                 */
-               sigexit(p, sig);
+               sigexit(p, signum);
                /* NOTREACHED */
        } else {
                /*
                /* NOTREACHED */
        } else {
                /*
@@ -1039,10 +1039,10 @@ psig(sig)
                        ps->ps_flags &= ~SAS_OLDMASK;
                } else
                        returnmask = p->p_sigmask;
                        ps->ps_flags &= ~SAS_OLDMASK;
                } else
                        returnmask = p->p_sigmask;
-               p->p_sigmask |= ps->ps_catchmask[sig] | mask;
+               p->p_sigmask |= ps->ps_catchmask[signum] | mask;
                (void) spl0();
                p->p_stats->p_ru.ru_nsignals++;
                (void) spl0();
                p->p_stats->p_ru.ru_nsignals++;
-               sendsig(action, sig, returnmask, 0);
+               sendsig(action, signum, returnmask, 0);
        }
 }
 
        }
 }
 
@@ -1060,33 +1060,31 @@ killproc(p, why)
 }
 
 /*
 }
 
 /*
- * Force the current process to exit with the specified
- * signal, dumping core if appropriate.  We bypass the normal
- * tests for masked and caught signals, allowing unrecoverable
- * failures to terminate the process without changing signal state.
- * Mark the accounting record with the signal termination.
- * If dumping core, save the signal number for the debugger.
- * Calls exit and does not return.
+ * Force the current process to exit with the specified signal, dumping core
+ * if appropriate.  We bypass the normal tests for masked and caught signals,
+ * allowing unrecoverable failures to terminate the process without changing
+ * signal state.  Mark the accounting record with the signal termination.
+ * If dumping core, save the signal number for the debugger.  Calls exit and
+ * does not return.
  */
  */
-sigexit(p, sig)
+sigexit(p, signum)
        register struct proc *p;
        register struct proc *p;
-       int sig;
+       int signum;
 {
 
        p->p_acflag |= AXSIG;
 {
 
        p->p_acflag |= AXSIG;
-       if (sigprop[sig] & SA_CORE) {
-               p->p_sigacts->ps_sig = sig;
+       if (sigprop[signum] & SA_CORE) {
+               p->p_sigacts->ps_sig = signum;
                if (coredump(p) == 0)
                if (coredump(p) == 0)
-                       sig |= WCOREFLAG;
+                       signum |= WCOREFLAG;
        }
        }
-       exit1(p, W_EXITCODE(0, sig));
+       exit1(p, W_EXITCODE(0, signum));
        /* NOTREACHED */
 }
 
 /*
        /* NOTREACHED */
 }
 
 /*
- * Create a core dump.
- * The file name is "core.progname".
- * Core dumps are not created if the process is setuid.
+ * Dump core, into a file named "core.progname".
+ * Do not drop core if the process was setuid/setgid.
  */
 coredump(p)
        register struct proc *p;
  */
 coredump(p)
        register struct proc *p;
@@ -1098,21 +1096,23 @@ coredump(p)
        struct vattr vattr;
        int error, error1;
        struct nameidata nd;
        struct vattr vattr;
        int error, error1;
        struct nameidata nd;
-       char name[MAXCOMLEN+6]; /* core.progname */
+       char name[MAXCOMLEN+6];         /* progname.core */
 
 
-       if (pcred->p_svuid != pcred->p_ruid ||
-           pcred->p_svgid != pcred->p_rgid)
+       if (pcred->p_svuid != pcred->p_ruid || pcred->p_svgid != pcred->p_rgid)
                return (EFAULT);
        if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
            p->p_rlimit[RLIMIT_CORE].rlim_cur)
                return (EFAULT);
                return (EFAULT);
        if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
            p->p_rlimit[RLIMIT_CORE].rlim_cur)
                return (EFAULT);
-       sprintf(name, "core.%s", p->p_comm);
+       sprintf(name, "%s.core", p->p_comm);
        NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
        NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
-       if (error = vn_open(&nd, O_CREAT|FWRITE, 0644))
+       if (error = vn_open(&nd,
+           O_CREAT | FWRITE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))
                return (error);
        vp = nd.ni_vp;
                return (error);
        vp = nd.ni_vp;
-       if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred, p) ||
-           vattr.va_nlink != 1) {
+
+       /* Don't dump to non-regular files or files with links. */
+       if (vp->v_type != VREG ||
+           VOP_GETATTR(vp, &vattr, cred, p) || vattr.va_nlink != 1) {
                error = EFAULT;
                goto out;
        }
                error = EFAULT;
                goto out;
        }
index 70ce9ef..0581446 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_conf.c  8.1 (Berkeley) %G%
+ *     @(#)vfs_conf.c  8.2 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -25,7 +25,7 @@ int (*mountroot)() = ffs_mountroot;
  * These define the root filesystem and device.
  */
 struct mount *rootfs;
  * These define the root filesystem and device.
  */
 struct mount *rootfs;
-struct vnode *rootdir;
+struct vnode *rootvnode;
 
 /*
  * Set up the filesystem operations for vnodes.
 
 /*
  * Set up the filesystem operations for vnodes.