Correct the links between threads, processes, pgrps, and sessions,
authorguenther <guenther@openbsd.org>
Mon, 26 Jul 2010 01:56:27 +0000 (01:56 +0000)
committerguenther <guenther@openbsd.org>
Mon, 26 Jul 2010 01:56:27 +0000 (01:56 +0000)
so that the process-level stuff is to/from struct process and not
struct proc.  This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots

44 files changed:
lib/libkvm/kvm_proc.c
lib/libkvm/kvm_proc2.c
sys/compat/common/tty_43.c
sys/compat/linux/linux_file.c
sys/compat/linux/linux_misc.c
sys/compat/svr4/svr4_fcntl.c
sys/compat/svr4/svr4_misc.c
sys/ddb/db_usrreq.c
sys/dev/usb/uhid.c
sys/dev/wscons/wseventvar.h
sys/dev/wscons/wskbd.c
sys/dev/wscons/wsmouse.c
sys/dev/wscons/wsmux.c
sys/kern/exec_elf.c
sys/kern/init_main.c
sys/kern/kern_acct.c
sys/kern/kern_descrip.c
sys/kern/kern_exec.c
sys/kern/kern_exit.c
sys/kern/kern_fork.c
sys/kern/kern_ktrace.c
sys/kern/kern_proc.c
sys/kern/kern_prot.c
sys/kern/kern_resource.c
sys/kern/kern_sig.c
sys/kern/kern_sysctl.c
sys/kern/spec_vnops.c
sys/kern/subr_prf.c
sys/kern/sys_generic.c
sys/kern/sys_process.c
sys/kern/tty.c
sys/kern/tty_pty.c
sys/kern/tty_tty.c
sys/kern/vfs_vnops.c
sys/miscfs/procfs/procfs_ctl.c
sys/miscfs/procfs/procfs_status.c
sys/miscfs/specfs/spec_vnops.c
sys/sys/proc.h
sys/sys/ptrace.h
sys/sys/resource.h
sys/sys/signalvar.h
sys/sys/sysctl.h
sys/sys/tty.h
sys/sys/uio.h

index 9e35623..63351d9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kvm_proc.c,v 1.40 2010/01/10 03:37:50 guenther Exp $  */
+/*     $OpenBSD: kvm_proc.c,v 1.41 2010/07/26 01:56:27 guenther Exp $  */
 /*     $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $        */
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -303,9 +303,9 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
                 * gather eproc
                 */
                eproc.e_paddr = p;
-               if (KREAD(kd, (u_long)proc.p_pgrp, &pgrp)) {
+               if (KREAD(kd, (u_long)process.ps_pgrp, &pgrp)) {
                        _kvm_err(kd, kd->program, "can't read pgrp at %x",
-                           proc.p_pgrp);
+                           process.ps_pgrp);
                        return (-1);
                }
                eproc.e_sess = pgrp.pg_session;
@@ -316,7 +316,7 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
                            pgrp.pg_session);
                        return (-1);
                }
-               if ((proc.p_flag & P_CONTROLT) && sess.s_ttyp != NULL) {
+               if ((process.ps_flags & PS_CONTROLT) && sess.s_ttyp != NULL) {
                        if (KREAD(kd, (u_long)sess.s_ttyp, &tty)) {
                                _kvm_err(kd, kd->program,
                                    "can't read tty at %x", sess.s_ttyp);
@@ -337,7 +337,7 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
                } else
                        eproc.e_tdev = NODEV;
                eproc.e_flag = sess.s_ttyvp ? EPROC_CTTY : 0;
-               if (sess.s_leader == p)
+               if (sess.s_leader == proc.p_p)
                        eproc.e_flag |= EPROC_SLEADER;
                if (proc.p_wmesg)
                        (void)kvm_read(kd, (u_long)proc.p_wmesg,
@@ -356,11 +356,12 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
                        break;
 
                case KERN_PROC_TTY:
-                       if ((proc.p_flag & P_CONTROLT) == 0 ||
+                       if ((process.ps_flags & PS_CONTROLT) == 0 ||
                            eproc.e_tdev != (dev_t)arg)
                                continue;
                        break;
                }
+               proc.p_flag |= process.ps_flags;
                bcopy(&proc, &bp->kp_proc, sizeof(proc));
                bcopy(&eproc, &bp->kp_eproc, sizeof(eproc));
                ++bp;
index 00e7f77..e98c359 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kvm_proc2.c,v 1.2 2010/06/29 16:39:23 guenther Exp $  */
+/*     $OpenBSD: kvm_proc2.c,v 1.3 2010/07/26 01:56:27 guenther Exp $  */
 /*     $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $        */
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -110,7 +110,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
        struct pcred pcred;
        struct ucred ucred;
        struct proc proc, proc2;
-       struct process process;
+       struct process process, process2;
        struct pgrp pgrp;
        struct tty tty;
        struct vmspace vm, *vmp;
@@ -139,9 +139,9 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
                            pcred.pc_ucred);
                        return (-1);
                }
-               if (KREAD(kd, (u_long)proc.p_pgrp, &pgrp)) {
+               if (KREAD(kd, (u_long)process.ps_pgrp, &pgrp)) {
                        _kvm_err(kd, kd->program, "can't read pgrp at %x",
-                           proc.p_pgrp);
+                           process.ps_pgrp);
                        return (-1);
                }
                if (KREAD(kd, (u_long)pgrp.pg_session, &sess)) {
@@ -149,16 +149,23 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
                            pgrp.pg_session);
                        return (-1);
                }
-               if ((proc.p_flag & P_CONTROLT) && sess.s_ttyp != NULL &&
+               if ((process.ps_flags & PS_CONTROLT) && sess.s_ttyp != NULL &&
                    KREAD(kd, (u_long)sess.s_ttyp, &tty)) {
                        _kvm_err(kd, kd->program,
                            "can't read tty at %x", sess.s_ttyp);
                        return (-1);
                }
-               if (proc.p_pptr) {
-                       if (KREAD(kd, (u_long)proc.p_pptr, &proc2)) {
+               if (process.ps_pptr) {
+                       if (KREAD(kd, (u_long)process.ps_pptr, &process2)) {
                                _kvm_err(kd, kd->program,
-                                   "can't read proc at %x", proc.p_pptr);
+                                   "can't read process at %x",
+                                   process.ps_pptr);
+                               return (-1);
+                       }
+                       if (KREAD(kd, (u_long)process2.ps_mainproc, &proc2)) {
+                               _kvm_err(kd, kd->program,
+                                   "can't read proc at %x",
+                                   process2.ps_mainproc);
                                return (-1);
                        }
                        parent_pid = proc2.p_pid;
@@ -166,11 +173,17 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
                else
                        parent_pid = 0;
                if (sess.s_leader) {
-                       if (KREAD(kd, (u_long)sess.s_leader, &proc2)) {
+                       if (KREAD(kd, (u_long)sess.s_leader, &process2)) {
                                _kvm_err(kd, kd->program,
                                    "can't read proc at %x", sess.s_leader);
                                return (-1);
                        }
+                       if (KREAD(kd, (u_long)process2.ps_mainproc, &proc2)) {
+                               _kvm_err(kd, kd->program,
+                                   "can't read proc at %x",
+                                   process2.ps_mainproc);
+                               return (-1);
+                       }
                        leader_pid = proc2.p_pid;
                }
                else
@@ -189,12 +202,12 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
 
                case KERN_PROC_SESSION:
                        if (sess.s_leader == NULL ||
-                           leader_pid == (pid_t)arg)
+                           leader_pid != (pid_t)arg)
                                continue;
                        break;
 
                case KERN_PROC_TTY:
-                       if ((proc.p_flag & P_CONTROLT) == 0 ||
+                       if ((process.ps_flags & PS_CONTROLT) == 0 ||
                            sess.s_ttyp == NULL ||
                            tty.t_dev != (dev_t)arg)
                                continue;
@@ -253,16 +266,16 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p,
 
 #define do_copy_str(_d, _s, _l)        kvm_read(kd, (u_long)(_s), (_d), (_l)-1)
                FILL_KPROC2(&kp, do_copy_str, &proc, &process, &pcred, &ucred,
-                   &pgrp, p, &sess, vmp, limp, ps);
+                   &pgrp, p, proc.p_p, &sess, vmp, limp, ps);
 #undef do_copy_str
 
                /* stuff that's too painful to generalize into the macros */
                kp.p_ppid = parent_pid;
                kp.p_sid = leader_pid;
-               if ((proc.p_flag & P_CONTROLT) && sess.s_ttyp != NULL) {
+               if ((process.ps_flags & PS_CONTROLT) && sess.s_ttyp != NULL) {
                        kp.p_tdev = tty.t_dev;
                        if (tty.t_pgrp != NULL &&
-                           tty.t_pgrp != proc.p_pgrp &&
+                           tty.t_pgrp != process.ps_pgrp &&
                            KREAD(kd, (u_long)tty.t_pgrp, &pgrp)) {
                                _kvm_err(kd, kd->program,
                                    "can't read tpgrp at &x", tty.t_pgrp);
index 8c7595b..e2973d4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tty_43.c,v 1.9 2004/09/19 21:34:42 mickey Exp $       */
+/*     $OpenBSD: tty_43.c,v 1.10 2010/07/26 01:56:27 guenther Exp $    */
 /*     $NetBSD: tty_43.c,v 1.5 1996/05/20 14:29:17 mark Exp $  */
 
 /*-
@@ -243,7 +243,7 @@ ttcompat(tp, com, data, flag, p)
                if (tp->t_session->s_leader == NULL)
                        return ENOTTY;
 
-               *(int *) data =  tp->t_session->s_leader->p_pid;
+               *(int *) data =  tp->t_session->s_leader->ps_pid;
                break;
 
        default:
index d717b8d..3cce374 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: linux_file.c,v 1.23 2006/09/25 07:12:57 otto Exp $    */
+/*     $OpenBSD: linux_file.c,v 1.24 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: linux_file.c,v 1.15 1996/05/20 01:59:09 fvdl Exp $     */
 
 /*
@@ -190,7 +190,8 @@ linux_sys_open(p, v, retval)
         * terminal yet, and the O_NOCTTY flag is not set, try to make
         * this the controlling terminal.
         */ 
-        if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
+        if (!(fl & O_NOCTTY) && SESS_LEADER(p->p_p) &&
+           !(p->p_p->ps_flags & PS_CONTROLT)) {
                 struct filedesc *fdp = p->p_fd;
                 struct file     *fp;
 
@@ -417,13 +418,13 @@ linux_sys_fcntl(p, v, retval)
                if ((long)arg <= 0) {
                        pgid = -(long)arg;
                } else {
-                       struct proc *p1 = pfind((long)arg);
-                       if (p1 == 0)
+                       struct process *pr = prfind((long)arg);
+                       if (pr == 0)
                                return (ESRCH);
-                       pgid = (long)p1->p_pgrp->pg_id;
+                       pgid = (long)pr->ps_pgrp->pg_id;
                }
                pgrp = pgfind(pgid);
-               if (pgrp == NULL || pgrp->pg_session != p->p_session)
+               if (pgrp == NULL || pgrp->pg_session != p->p_p->ps_session)
                        return EPERM;
                tp->t_pgrp = pgrp;
                return 0;
index 5def155..cb7abec 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: linux_misc.c,v 1.64 2010/06/30 21:54:35 guenther Exp $        */
+/*     $OpenBSD: linux_misc.c,v 1.65 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: linux_misc.c,v 1.27 1996/05/20 01:59:21 fvdl Exp $     */
 
 /*-
@@ -1223,16 +1223,16 @@ linux_sys_getpgid(p, v, retval)
        struct linux_sys_getpgid_args /* {
                syscallarg(int) pid;
        } */ *uap = v;
-       struct proc *targp;
+       struct process *targpr;
 
        if (SCARG(uap, pid) != 0 && SCARG(uap, pid) != p->p_pid) {
-               if ((targp = pfind(SCARG(uap, pid))) == 0)
+               if ((targpr = prfind(SCARG(uap, pid))) == 0)
                        return ESRCH;
        }
        else
-               targp = p;
+               targpr = p->p_p;
 
-       retval[0] = targp->p_pgid;
+       retval[0] = targpr->ps_pgid;
        return 0;
 }
 
index 02d10d8..eb4d927 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: svr4_fcntl.c,v 1.22 2002/03/14 01:26:51 millert Exp $  */
+/*     $OpenBSD: svr4_fcntl.c,v 1.23 2010/07/26 01:56:27 guenther Exp $         */
 /*     $NetBSD: svr4_fcntl.c,v 1.14 1995/10/14 20:24:24 christos Exp $  */
 
 /*
@@ -338,8 +338,8 @@ svr4_sys_open(p, v, retval)
        if (error)
                return error;
 
-       if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
-           !(p->p_flag & P_CONTROLT)) {
+       if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p->p_p) &&
+           !(p->p_p->ps_flags & PS_CONTROLT)) {
                struct filedesc *fdp = p->p_fd;
                struct file     *fp;
 
index f2700bf..dd21305 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: svr4_misc.c,v 1.54 2010/05/25 16:39:15 thib Exp $      */
+/*     $OpenBSD: svr4_misc.c,v 1.55 2010/07/26 01:56:27 guenther Exp $  */
 /*     $NetBSD: svr4_misc.c,v 1.42 1996/12/06 03:22:34 christos Exp $   */
 
 /*
@@ -101,7 +101,7 @@ static void bsd_statfs_to_svr4_statvfs(const struct statfs *,
     struct svr4_statvfs *);
 static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
     struct svr4_statvfs64 *);
-static struct proc *svr4_pfind(pid_t pid);
+static struct process *svr4_prfind(pid_t pid);
 
 static int svr4_mknod(struct proc *, register_t *, char *,
                           svr4_mode_t, svr4_dev_t);
@@ -815,20 +815,20 @@ svr4_sys_ulimit(p, v, retval)
 }
 
 
-static struct proc *
-svr4_pfind(pid)
-       pid_t pid;
+static struct process *
+svr4_prfind(pid_t pid)
 {
+       struct process *pr;
        struct proc *p;
 
        /* look in the live processes */
-       if ((p = pfind(pid)) != NULL)
-               return p;
+       if ((pr = prfind(pid)) != NULL)
+               return pr;
 
        /* look in the zombies */
        LIST_FOREACH(p, &zombproc, p_list)
                if (p->p_pid == pid)
-                       return p;
+                       return p->p_flag & P_THREAD ? NULL : p->p_p;
 
        return NULL;
 }
@@ -841,11 +841,12 @@ svr4_sys_pgrpsys(p, v, retval)
        register_t *retval;
 {
        struct svr4_sys_pgrpsys_args *uap = v;
+       struct process *pr = p->p_p;
        int error;
 
        switch (SCARG(uap, cmd)) {
        case 0:                 /* getpgrp() */
-               *retval = p->p_pgrp->pg_id;
+               *retval = pr->ps_pgrp->pg_id;
                return 0;
 
        case 1:                 /* setpgrp() */
@@ -856,19 +857,19 @@ svr4_sys_pgrpsys(p, v, retval)
                        SCARG(&sa, pgid) = 0;
                        if ((error = sys_setpgid(p, &sa, retval)) != 0)
                                return error;
-                       *retval = p->p_pgrp->pg_id;
+                       *retval = pr->ps_pgrp->pg_id;
                        return 0;
                }
 
        case 2:                 /* getsid(pid) */
                if (SCARG(uap, pid) != 0 &&
-                   (p = svr4_pfind(SCARG(uap, pid))) == NULL)
+                   (pr = svr4_prfind(SCARG(uap, pid))) == NULL)
                        return ESRCH;
                /* 
                 * we return the pid of the session leader for this
                 * process
                 */
-               *retval = (register_t) p->p_session->s_leader->p_pid;
+               *retval = (register_t)pr->ps_session->s_leader->ps_pid;
                return 0;
 
        case 3:                 /* setsid() */
@@ -877,10 +878,10 @@ svr4_sys_pgrpsys(p, v, retval)
        case 4:                 /* getpgid(pid) */
 
                if (SCARG(uap, pid) != 0 &&
-                   (p = svr4_pfind(SCARG(uap, pid))) == NULL)
+                   (pr = svr4_prfind(SCARG(uap, pid))) == NULL)
                        return ESRCH;
 
-               *retval = (int) p->p_pgrp->pg_id;
+               *retval = (int)pr->ps_pgrp->pg_id;
                return 0;
 
        case 5:                 /* setpgid(pid, pgid); */
@@ -1042,6 +1043,7 @@ svr4_sys_waitsys(q, v, retval)
        struct svr4_sys_waitsys_args *uap = v;
        int nfound;
        int error;
+       struct process *pr;
        struct proc *p;
 
        switch (SCARG(uap, grp)) {
@@ -1049,7 +1051,7 @@ svr4_sys_waitsys(q, v, retval)
                break;
 
        case SVR4_P_PGID:
-               SCARG(uap, id) = -q->p_pgid;
+               SCARG(uap, id) = -q->p_p->ps_pgid;
                break;
 
        case SVR4_P_ALL:
@@ -1065,12 +1067,13 @@ svr4_sys_waitsys(q, v, retval)
 
 loop:
        nfound = 0;
-       LIST_FOREACH(p, &q->p_children, p_sibling) {
+       LIST_FOREACH(pr, &q->p_p->ps_children, ps_sibling) {
+               p = pr->ps_mainproc;
                if (SCARG(uap, id) != WAIT_ANY &&
                    p->p_pid != SCARG(uap, id) &&
-                   p->p_pgid != -SCARG(uap, id)) {
+                   pr->ps_pgid != -SCARG(uap, id)) {
                        DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
-                                p->p_pgid, SCARG(uap, id)));
+                                pr->ps_pgid, SCARG(uap, id)));
                        continue;
                }
                nfound++;
index f62908f..b93d667 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: db_usrreq.c,v 1.13 2008/11/08 01:14:51 mpf Exp $      */
+/*     $OpenBSD: db_usrreq.c,v 1.14 2010/07/26 01:56:27 guenther Exp $ */
 
 /*
  * Copyright (c) 1996 Michael Shalayeff.  All rights reserved.
@@ -91,10 +91,11 @@ ddb_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
                return (sysctl_int(oldp, oldlenp, newp, newlen, &db_log));
        case DBCTL_TRIGGER:
                if (newp && db_console) {
-                       struct proc *p = curproc;
+                       struct process *pr = curproc->p_p;
+
                        if (securelevel < 1 ||
-                           (p->p_flag & P_CONTROLT && cn_tab &&
-                           cn_tab->cn_dev == p->p_session->s_ttyp->t_dev)) {
+                           (pr->ps_flags & PS_CONTROLT && cn_tab &&
+                           cn_tab->cn_dev == pr->ps_session->s_ttyp->t_dev)) {
                                Debugger();
                                newp = NULL;
                        } else
index 6ebeba1..9955bca 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uhid.c,v 1.47 2009/11/23 11:10:16 yuo Exp $ */
+/*     $OpenBSD: uhid.c,v 1.48 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: uhid.c,v 1.57 2003/03/11 16:44:00 augustss Exp $       */
 
 /*
@@ -81,10 +81,10 @@ struct uhid_softc {
 
        struct clist sc_q;
        struct selinfo sc_rsel;
-       struct proc *sc_async;  /* process that wants SIGIO */
-       u_char sc_state;        /* driver state */
-#define        UHID_ASLP       0x01    /* waiting for device data */
-#define UHID_IMMED     0x02    /* return read data immediately */
+       struct process *sc_async;       /* process that wants SIGIO */
+       u_char sc_state;                /* driver state */
+#define        UHID_ASLP       0x01            /* waiting for device data */
+#define UHID_IMMED     0x02            /* return read data immediately */
 
        int sc_refcnt;
        u_char sc_dying;
@@ -236,7 +236,7 @@ uhid_intr(struct uhidev *addr, void *data, u_int len)
        selwakeup(&sc->sc_rsel);
        if (sc->sc_async != NULL) {
                DPRINTFN(3, ("uhid_intr: sending SIGIO %p\n", sc->sc_async));
-               psignal(sc->sc_async, SIGIO);
+               prsignal(sc->sc_async, SIGIO);
        }
 }
 
@@ -427,7 +427,7 @@ uhid_do_ioctl(struct uhid_softc *sc, u_long cmd, caddr_t addr,
                if (*(int *)addr) {
                        if (sc->sc_async != NULL)
                                return (EBUSY);
-                       sc->sc_async = p;
+                       sc->sc_async = p->p_p;
                        DPRINTF(("uhid_do_ioctl: FIOASYNC %p\n", p));
                } else
                        sc->sc_async = NULL;
@@ -437,7 +437,7 @@ uhid_do_ioctl(struct uhid_softc *sc, u_long cmd, caddr_t addr,
        case TIOCSPGRP:
                if (sc->sc_async == NULL)
                        return (EINVAL);
-               if (*(int *)addr != sc->sc_async->p_pgid)
+               if (*(int *)addr != sc->sc_async->ps_pgid)
                        return (EPERM);
                break;
 
index f1eeb74..213ffc9 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: wseventvar.h,v 1.6 2009/11/09 17:53:39 nicm Exp $ */
+/* $OpenBSD: wseventvar.h,v 1.7 2010/07/26 01:56:27 guenther Exp $ */
 /* $NetBSD: wseventvar.h,v 1.1 1998/03/22 14:24:03 drochner Exp $ */
 
 /*
@@ -84,7 +84,7 @@ struct wseventvar {
        u_int   get;            /* get (read) index (modified synchronously) */
        volatile u_int put;     /* put (write) index (modified by interrupt) */
        struct selinfo sel;     /* process selecting */
-       struct proc *io;        /* process that opened queue (can get SIGIO) */
+       struct process *io;     /* process that opened queue (can get SIGIO) */
        int     wanted;         /* wake up on input ready */
        int     async;          /* send SIGIO on input ready */
        struct wscons_event *q; /* circular buffer (queue) of events */
@@ -99,7 +99,7 @@ struct wseventvar {
                wakeup((caddr_t)(ev)); \
        } \
        if ((ev)->async) \
-               pgsignal((ev)->io->p_pgrp, SIGIO, 0); \
+               pgsignal((ev)->io->ps_pgrp, SIGIO, 0); \
 }
 
 void   wsevent_init(struct wseventvar *);
index 5fd868c..21bc897 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: wskbd.c,v 1.61 2009/10/13 19:33:19 pirofti Exp $ */
+/* $OpenBSD: wskbd.c,v 1.62 2010/07/26 01:56:27 guenther Exp $ */
 /* $NetBSD: wskbd.c,v 1.80 2005/05/04 01:52:16 augustss Exp $ */
 
 /*
@@ -815,7 +815,7 @@ wskbdopen(dev_t dev, int flags, int mode, struct proc *p)
 
        evar = &sc->sc_base.me_evar;
        wsevent_init(evar);
-       evar->io = p;
+       evar->io = p->p_p;
 
        error = wskbd_do_open(sc, evar);
        if (error) {
@@ -937,15 +937,15 @@ wskbd_do_ioctl_sc(struct wskbd_softc *sc, u_long cmd, caddr_t data, int flag,
        case FIOSETOWN:
                if (sc->sc_base.me_evp == NULL)
                        return (EINVAL);
-               if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid &&
-                   *(int *)data != sc->sc_base.me_evp->io->p_pid)
+               if (-*(int *)data != sc->sc_base.me_evp->io->ps_pgid &&
+                   *(int *)data != sc->sc_base.me_evp->io->ps_pid)
                        return (EPERM);
                return (0);
                   
        case TIOCSPGRP:
                if (sc->sc_base.me_evp == NULL)
                        return (EINVAL);
-               if (*(int *)data != sc->sc_base.me_evp->io->p_pgid)
+               if (*(int *)data != sc->sc_base.me_evp->io->ps_pgid)
                        return (EPERM);
                return (0);
        }
index bb5e5e1..e1ab5d2 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsmouse.c,v 1.20 2009/10/13 19:33:19 pirofti Exp $ */
+/* $OpenBSD: wsmouse.c,v 1.21 2010/07/26 01:56:27 guenther Exp $ */
 /* $NetBSD: wsmouse.c,v 1.35 2005/02/27 00:27:52 perry Exp $ */
 
 /*
@@ -512,7 +512,7 @@ wsmouseopen(dev_t dev, int flags, int mode, struct proc *p)
 
        evar = &sc->sc_base.me_evar;
        wsevent_init(evar);
-       evar->io = p;
+       evar->io = p->p_p;
 
        error = wsmousedoopen(sc, evar);
        if (error) {
@@ -638,15 +638,15 @@ wsmouse_do_ioctl(struct wsmouse_softc *sc, u_long cmd, caddr_t data, int flag,
        case FIOSETOWN:
                if (sc->sc_base.me_evp == NULL)
                        return (EINVAL);
-               if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid
-                   && *(int *)data != sc->sc_base.me_evp->io->p_pid)
+               if (-*(int *)data != sc->sc_base.me_evp->io->ps_pgid
+                   && *(int *)data != sc->sc_base.me_evp->io->ps_pid)
                        return (EPERM);
                return (0);
 
        case TIOCSPGRP:
                if (sc->sc_base.me_evp == NULL)
                        return (EINVAL);
-               if (*(int *)data != sc->sc_base.me_evp->io->p_pgid)
+               if (*(int *)data != sc->sc_base.me_evp->io->ps_pgid)
                        return (EPERM);
                return (0);
        }
index 1a9ac76..1437256 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: wsmux.c,v 1.23 2008/06/26 05:42:19 ray Exp $  */
+/*     $OpenBSD: wsmux.c,v 1.24 2010/07/26 01:56:27 guenther Exp $     */
 /*      $NetBSD: wsmux.c,v 1.37 2005/04/30 03:47:12 augustss Exp $      */
 
 /*
@@ -193,7 +193,7 @@ wsmuxopen(dev_t dev, int flags, int mode, struct proc *p)
 
        evar = &sc->sc_base.me_evar;
        wsevent_init(evar);
-       evar->io = p;
+       evar->io = p->p_p;
 #ifdef WSDISPLAY_COMPAT_RAWKBD
        sc->sc_rawkbd = 0;
 #endif
@@ -477,8 +477,8 @@ wsmux_do_ioctl(struct device *dv, u_long cmd, caddr_t data, int flag,
                evar = sc->sc_base.me_evp;
                if (evar == NULL)
                        return (EINVAL);
-               if (-*(int *)data != evar->io->p_pgid
-                   && *(int *)data != evar->io->p_pid)
+               if (-*(int *)data != evar->io->ps_pgid
+                   && *(int *)data != evar->io->ps_pid)
                        return (EPERM);
                return (0);
        case TIOCSPGRP:
@@ -486,7 +486,7 @@ wsmux_do_ioctl(struct device *dv, u_long cmd, caddr_t data, int flag,
                evar = sc->sc_base.me_evp;
                if (evar == NULL)
                        return (EINVAL);
-               if (*(int *)data != evar->io->p_pgid)
+               if (*(int *)data != evar->io->ps_pgid)
                        return (EPERM);
                return (0);
        default:
index e962f9f..10993c6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: exec_elf.c,v 1.75 2010/07/24 09:50:45 guenther Exp $  */
+/*     $OpenBSD: exec_elf.c,v 1.76 2010/07/26 01:56:27 guenther Exp $  */
 
 /*
  * Copyright (c) 1996 Per Fogelstrom
@@ -1137,6 +1137,7 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep)
        struct uio uio;
        struct elfcore_procinfo cpi;
        Elf_Note nhdr;
+       struct process *pr = p->p_p;
        struct proc *q;
        size_t size, notesize;
        int error;
@@ -1159,11 +1160,11 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep)
                cpi.cpi_sigignore = p->p_sigignore;
                cpi.cpi_sigcatch = p->p_sigcatch;
 
-               cpi.cpi_pid = p->p_pid;
-               cpi.cpi_ppid = p->p_pptr->p_pid;
-               cpi.cpi_pgrp = p->p_pgid;
-               if (p->p_session->s_leader)
-                       cpi.cpi_sid = p->p_session->s_leader->p_pid;
+               cpi.cpi_pid = pr->ps_pid;
+               cpi.cpi_ppid = pr->ps_pptr->ps_pid;
+               cpi.cpi_pgrp = pr->ps_pgid;
+               if (pr->ps_session->s_leader)
+                       cpi.cpi_sid = pr->ps_session->s_leader->ps_pid;
                else
                        cpi.cpi_sid = 0;
 
@@ -1263,7 +1264,7 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep)
         * per-thread notes.  Since we're dumping core, we don't bother
         * locking.
         */
-       TAILQ_FOREACH(q, &p->p_p->ps_threads, p_thr_link) {
+       TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) {
                if (q == p)             /* we've taken care of this thread */
                        continue;
                error = ELFNAMEEND(coredump_note)(q, iocookie, &notesize);
index e3d5d4c..14afa2a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: init_main.c,v 1.169 2010/07/03 04:44:51 guenther Exp $        */
+/*     $OpenBSD: init_main.c,v 1.170 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $   */
 
 /*
@@ -184,6 +184,7 @@ int
 main(void *framep)
 {
        struct proc *p;
+       struct process *pr;
        struct pdevinit *pdev;
        struct timeval rtv;
        quad_t lim;
@@ -263,21 +264,21 @@ main(void *framep)
        TAILQ_INIT(&process0.ps_threads);
        TAILQ_INSERT_TAIL(&process0.ps_threads, p, p_thr_link);
        process0.ps_refcnt = 1;
-       p->p_p = &process0;
+       p->p_p = pr = &process0;
 
        /* Set the default routing table/domain. */
        process0.ps_rtableid = 0;
 
        LIST_INSERT_HEAD(&allproc, p, p_list);
-       p->p_pgrp = &pgrp0;
+       pr->ps_pgrp = &pgrp0;
        LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
        LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
        LIST_INIT(&pgrp0.pg_members);
-       LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
+       LIST_INSERT_HEAD(&pgrp0.pg_members, pr, ps_pglist);
 
        pgrp0.pg_session = &session0;
        session0.s_count = 1;
-       session0.s_leader = p;
+       session0.s_leader = pr;
 
        atomic_setbits_int(&p->p_flag, P_SYSTEM | P_NOCLDWAIT);
        p->p_stat = SONPROC;
@@ -303,7 +304,7 @@ main(void *framep)
        p->p_fd = fdinit(NULL);
 
        /* Create the limits structures. */
-       p->p_p->ps_limit = &limit0;
+       pr->ps_limit = &limit0;
        for (i = 0; i < nitems(p->p_rlimit); i++)
                limit0.pl_rlimit[i].rlim_cur =
                    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
index 52f002b..0051d4f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_acct.c,v 1.22 2010/01/14 23:12:11 schwarze Exp $ */
+/*     $OpenBSD: kern_acct.c,v 1.23 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $  */
 
 /*-
@@ -216,8 +216,9 @@ acct_process(struct proc *p)
        acct.ac_gid = p->p_cred->p_rgid;
 
        /* (7) The terminal from which the process was started */
-       if ((p->p_flag & P_CONTROLT) && p->p_pgrp->pg_session->s_ttyp)
-               acct.ac_tty = p->p_pgrp->pg_session->s_ttyp->t_dev;
+       if ((p->p_p->ps_flags & PS_CONTROLT) &&
+           p->p_p->ps_pgrp->pg_session->s_ttyp)
+               acct.ac_tty = p->p_p->ps_pgrp->pg_session->s_ttyp->t_dev;
        else
                acct.ac_tty = NODEV;
 
index 12c44f0..e669c3e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_descrip.c,v 1.84 2010/07/19 23:00:15 guenther Exp $      */
+/*     $OpenBSD: kern_descrip.c,v 1.85 2010/07/26 01:56:27 guenther Exp $      */
 /*     $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $       */
 
 /*
@@ -389,12 +389,12 @@ restart:
                if ((long)SCARG(uap, arg) <= 0) {
                        SCARG(uap, arg) = (void *)(-(long)SCARG(uap, arg));
                } else {
-                       struct proc *p1 = pfind((long)SCARG(uap, arg));
-                       if (p1 == 0) {
+                       struct process *pr1 = prfind((long)SCARG(uap, arg));
+                       if (pr1 == 0) {
                                error = ESRCH;
                                break;
                        }
-                       SCARG(uap, arg) = (void *)(long)p1->p_pgrp->pg_id;
+                       SCARG(uap, arg) = (void *)(long)pr1->ps_pgrp->pg_id;
                }
                error = ((*fp->f_ops->fo_ioctl)
                        (fp, TIOCSPGRP, (caddr_t)&SCARG(uap, arg), p));
index 3bd0efe..5afdacd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_exec.c,v 1.112 2010/05/18 22:26:10 tedu Exp $    */
+/*     $OpenBSD: kern_exec.c,v 1.113 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $  */
 
 /*-
@@ -468,9 +468,9 @@ sys_execve(struct proc *p, void *v, register_t *retval)
        p->p_textvp = pack.ep_vp;
 
        atomic_setbits_int(&p->p_flag, P_EXEC);
-       if (p->p_flag & P_PPWAIT) {
-               atomic_clearbits_int(&p->p_flag, P_PPWAIT);
-               wakeup((caddr_t)p->p_pptr);
+       if (p->p_p->ps_mainproc->p_flag & P_PPWAIT) {
+               atomic_clearbits_int(&p->p_p->ps_mainproc->p_flag, P_PPWAIT);
+               wakeup(p->p_p->ps_pptr);
        }
 
        /*
index bf36116..3302bc6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_exit.c,v 1.95 2010/07/19 23:00:15 guenther Exp $ */
+/*     $OpenBSD: kern_exit.c,v 1.96 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $  */
 
 /*
@@ -120,34 +120,37 @@ void
 exit1(struct proc *p, int rv, int flags)
 {
        struct proc *q, *nq;
+       struct process *pr, *qr, *nqr;
 
        if (p->p_pid == 1)
                panic("init died (signal %d, exit %d)",
                    WTERMSIG(rv), WEXITSTATUS(rv));
        
+       atomic_setbits_int(&p->p_flag, P_WEXIT);
+
        /* unlink ourselves from the active threads */
-       TAILQ_REMOVE(&p->p_p->ps_threads, p, p_thr_link);
-       if (TAILQ_EMPTY(&p->p_p->ps_threads))
-               wakeup(&p->p_p->ps_threads);
+       pr = p->p_p;
+       TAILQ_REMOVE(&pr->ps_threads, p, p_thr_link);
+       if (TAILQ_EMPTY(&pr->ps_threads))
+               wakeup(&pr->ps_threads);
        /*
         * if one thread calls exit, we take down everybody.
         * we have to be careful not to get recursively caught.
         * this is kinda sick.
         */
        if (flags == EXIT_NORMAL && (p->p_flag & P_THREAD) &&
-           (p->p_p->ps_mainproc->p_flag & P_WEXIT) == 0) {
+           (pr->ps_mainproc->p_flag & P_WEXIT) == 0) {
                /*
                 * we are one of the threads.  we SIGKILL the parent,
                 * it will wake us up again, then we proceed.
                 */
-               atomic_setbits_int(&p->p_p->ps_mainproc->p_flag, P_IGNEXITRV);
-               p->p_p->ps_mainproc->p_xstat = rv;
-               ptsignal(p->p_p->ps_mainproc, SIGKILL, SPROPAGATED);
-               tsleep(p->p_p, PUSER, "thrdying", 0);
+               atomic_setbits_int(&pr->ps_mainproc->p_flag, P_IGNEXITRV);
+               pr->ps_mainproc->p_xstat = rv;
+               ptsignal(pr->ps_mainproc, SIGKILL, SPROPAGATED);
+               tsleep(pr, PUSER, "thrdying", 0);
        } else if ((p->p_flag & P_THREAD) == 0) {
-               atomic_setbits_int(&p->p_flag, P_WEXIT);
                if (flags == EXIT_NORMAL) {
-                       q = TAILQ_FIRST(&p->p_p->ps_threads);
+                       q = TAILQ_FIRST(&pr->ps_threads);
                        for (; q != NULL; q = nq) {
                                nq = TAILQ_NEXT(q, p_thr_link);
                                atomic_setbits_int(&q->p_flag, P_IGNEXITRV);
@@ -155,23 +158,22 @@ exit1(struct proc *p, int rv, int flags)
                                ptsignal(q, SIGKILL, SPROPAGATED);
                        }
                }
-               wakeup(p->p_p);
-               while (!TAILQ_EMPTY(&p->p_p->ps_threads))
-                       tsleep(&p->p_p->ps_threads, PUSER, "thrdeath", 0);
+               wakeup(pr);
+               while (!TAILQ_EMPTY(&pr->ps_threads))
+                       tsleep(&pr->ps_threads, PUSER, "thrdeath", 0);
+               /*
+                * If parent is waiting for us to exit or exec, P_PPWAIT
+                * is set; we wake up the parent early to avoid deadlock.
+                */
+               if (p->p_flag & P_PPWAIT) {
+                       atomic_clearbits_int(&p->p_flag, P_PPWAIT);
+                       wakeup(pr->ps_pptr);
+               }
        }
 
        if (p->p_flag & P_PROFIL)
                stopprofclock(p);
        p->p_ru = pool_get(&rusage_pool, PR_WAITOK);
-       /*
-        * If parent is waiting for us to exit or exec, P_PPWAIT is set; we
-        * wake up the parent early to avoid deadlock.
-        */
-       atomic_setbits_int(&p->p_flag, P_WEXIT);
-       if (p->p_flag & P_PPWAIT) {
-               atomic_clearbits_int(&p->p_flag, P_PPWAIT);
-               wakeup(p->p_pptr);
-       }
        p->p_sigignore = ~0;
        p->p_siglist = 0;
        timeout_del(&p->p_realit_to);
@@ -183,46 +185,52 @@ exit1(struct proc *p, int rv, int flags)
         */
        fdfree(p);
 
+       if ((p->p_flag & P_THREAD) == 0) {
 #ifdef SYSVSEM
-       if ((p->p_flag & P_THREAD) == 0)
-               semexit(p->p_p);
+               semexit(pr);
 #endif
-       if (SESS_LEADER(p)) {
-               struct session *sp = p->p_session;
+               if (SESS_LEADER(pr)) {
+                       struct session *sp = pr->ps_session;
 
-               if (sp->s_ttyvp) {
-                       /*
-                        * Controlling process.
-                        * Signal foreground pgrp,
-                        * drain controlling terminal
-                        * and revoke access to controlling terminal.
-                        */
-                       if (sp->s_ttyp->t_session == sp) {
-                               if (sp->s_ttyp->t_pgrp)
-                                       pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
-                               (void) ttywait(sp->s_ttyp);
+                       if (sp->s_ttyvp) {
                                /*
-                                * The tty could have been revoked
-                                * if we blocked.
+                                * Controlling process.
+                                * Signal foreground pgrp,
+                                * drain controlling terminal
+                                * and revoke access to controlling terminal.
                                 */
+                               if (sp->s_ttyp->t_session == sp) {
+                                       if (sp->s_ttyp->t_pgrp)
+                                               pgsignal(sp->s_ttyp->t_pgrp,
+                                                   SIGHUP, 1);
+                                       (void) ttywait(sp->s_ttyp);
+                                       /*
+                                        * The tty could have been revoked
+                                        * if we blocked.
+                                        */
+                                       if (sp->s_ttyvp)
+                                               VOP_REVOKE(sp->s_ttyvp,
+                                                   REVOKEALL);
+                               }
                                if (sp->s_ttyvp)
-                                       VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
+                                       vrele(sp->s_ttyvp);
+                               sp->s_ttyvp = NULL;
+                               /*
+                                * s_ttyp is not zero'd; we use this to
+                                * indicate that the session once had a
+                                * controlling terminal.  (for logging and
+                                * informational purposes)
+                                */
                        }
-                       if (sp->s_ttyvp)
-                               vrele(sp->s_ttyvp);
-                       sp->s_ttyvp = NULL;
-                       /*
-                        * s_ttyp is not zero'd; we use this to indicate
-                        * that the session once had a controlling terminal.
-                        * (for logging and informational purposes)
-                        */
+                       sp->s_leader = NULL;
                }
-               sp->s_leader = NULL;
-       }
-       fixjobc(p, p->p_pgrp, 0);
+               fixjobc(pr, pr->ps_pgrp, 0);
+
 #ifdef ACCOUNTING
-       (void)acct_process(p);
+               (void)acct_process(p);
 #endif
+       }
+
 #ifdef KTRACE
        /* 
         * release trace file
@@ -254,19 +262,22 @@ exit1(struct proc *p, int rv, int flags)
        /*
         * Give orphaned children to init(8).
         */
-       q = LIST_FIRST(&p->p_children);
-       if (q)          /* only need this if any child is S_ZOMB */
-               wakeup(initproc);
-       for (; q != 0; q = nq) {
-               nq = LIST_NEXT(q, p_sibling);
-               proc_reparent(q, initproc);
-               /*
-                * Traced processes are killed
-                * since their existence means someone is screwing up.
-                */
-               if (q->p_flag & P_TRACED) {
-                       atomic_clearbits_int(&q->p_flag, P_TRACED);
-                       psignal(q, SIGKILL);
+       if ((p->p_flag & P_THREAD) == 0) {
+               qr = LIST_FIRST(&pr->ps_children);
+               if (qr)         /* only need this if any child is S_ZOMB */
+                       wakeup(initproc->p_p);
+               for (; qr != 0; qr = nqr) {
+                       nqr = LIST_NEXT(qr, ps_sibling);
+                       proc_reparent(qr, initproc->p_p);
+                       /*
+                        * Traced processes are killed
+                        * since their existence means someone is screwing up.
+                        */
+                       if (qr->ps_mainproc->p_flag & P_TRACED) {
+                               atomic_clearbits_int(&qr->ps_mainproc->p_flag,
+                                   P_TRACED);
+                               prsignal(qr, SIGKILL);
+                       }
                }
        }
 
@@ -286,27 +297,27 @@ exit1(struct proc *p, int rv, int flags)
         */
        p->p_pctcpu = 0;
 
-       /*
-        * notify interested parties of our demise.
-        */
-       if (p == p->p_p->ps_mainproc)
-               KNOTE(&p->p_p->ps_klist, NOTE_EXIT);
+       if ((p->p_flag & P_THREAD) == 0) {
+               /* notify interested parties of our demise */
+               KNOTE(&pr->ps_klist, NOTE_EXIT);
 
-       /*
-        * Notify parent that we're gone.  If we have P_NOZOMBIE or parent has
-        * the P_NOCLDWAIT flag set, notify process 1 instead (and hope it
-        * will handle this situation).
-        */
-       if ((p->p_flag & P_NOZOMBIE) || (p->p_pptr->p_flag & P_NOCLDWAIT)) {
-               struct proc *pp = p->p_pptr;
-               proc_reparent(p, initproc);
                /*
-                * If this was the last child of our parent, notify
-                * parent, so in case he was wait(2)ing, he will
-                * continue.
+                * Notify parent that we're gone.  If we have P_NOZOMBIE
+                * or parent has the P_NOCLDWAIT flag set, notify process 1
+                * instead (and hope it will handle this situation).
                 */
-               if (LIST_EMPTY(&pp->p_children))
-                       wakeup(pp);
+               if ((p->p_flag & P_NOZOMBIE) ||
+                   (pr->ps_pptr->ps_mainproc->p_flag & P_NOCLDWAIT)) {
+                       struct process *ppr = pr->ps_pptr;
+                       proc_reparent(pr, initproc->p_p);
+                       /*
+                        * If this was the last child of our parent, notify
+                        * parent, so in case he was wait(2)ing, he will
+                        * continue.
+                        */
+                       if (LIST_EMPTY(&ppr->ps_children))
+                               wakeup(ppr);
+               }
        }
 
        /*
@@ -407,9 +418,9 @@ reaper(void)
                        p->p_stat = SZOMB;
 
                        if (P_EXITSIG(p) != 0)
-                               psignal(p->p_pptr, P_EXITSIG(p));
+                               prsignal(p->p_p->ps_pptr, P_EXITSIG(p));
                        /* Wake up the parent so it can get exit status. */
-                       wakeup(p->p_pptr);
+                       wakeup(p->p_p->ps_pptr);
                } else {
                        /* Noone will wait for us. Just zap the process now */
                        proc_zap(p);
@@ -429,21 +440,23 @@ sys_wait4(struct proc *q, void *v, register_t *retval)
                syscallarg(struct rusage *) rusage;
        } */ *uap = v;
        int nfound;
+       struct process *pr;
        struct proc *p;
        int status, error;
 
        if (SCARG(uap, pid) == 0)
-               SCARG(uap, pid) = -q->p_pgid;
+               SCARG(uap, pid) = -q->p_p->ps_pgid;
        if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG|WALTSIG|WCONTINUED))
                return (EINVAL);
 
 loop:
        nfound = 0;
-       LIST_FOREACH(p, &q->p_children, p_sibling) {
+       LIST_FOREACH(pr, &q->p_p->ps_children, ps_sibling) {
+               p = pr->ps_mainproc;
                if ((p->p_flag & P_NOZOMBIE) ||
                    (SCARG(uap, pid) != WAIT_ANY &&
                    p->p_pid != SCARG(uap, pid) &&
-                   p->p_pgid != -SCARG(uap, pid)))
+                   pr->ps_pgid != -SCARG(uap, pid)))
                        continue;
 
                /*
@@ -505,7 +518,7 @@ loop:
                retval[0] = 0;
                return (0);
        }
-       if ((error = tsleep(q, PWAIT | PCATCH, "wait", 0)) != 0)
+       if ((error = tsleep(q->p_p, PWAIT | PCATCH, "wait", 0)) != 0)
                return (error);
        goto loop;
 }
@@ -513,19 +526,19 @@ loop:
 void
 proc_finish_wait(struct proc *waiter, struct proc *p)
 {
-       struct proc *t;
+       struct process *tr;
 
        /*
         * If we got the child via a ptrace 'attach',
         * we need to give it back to the old parent.
         */
-       if (p->p_oppid && (t = pfind(p->p_oppid))) {
+       if (p->p_oppid && (tr = prfind(p->p_oppid))) {
                atomic_clearbits_int(&p->p_flag, P_TRACED);
                p->p_oppid = 0;
-               proc_reparent(p, t);
+               proc_reparent(p->p_p, tr);
                if (p->p_exitsig != 0)
-                       psignal(t, p->p_exitsig);
-               wakeup(t);
+                       prsignal(tr, p->p_exitsig);
+               wakeup(tr);
        } else {
                scheduler_wait_hook(waiter, p);
                p->p_xstat = 0;
@@ -538,24 +551,24 @@ proc_finish_wait(struct proc *waiter, struct proc *p)
  * make process 'parent' the new parent of process 'child'.
  */
 void
-proc_reparent(struct proc *child, struct proc *parent)
+proc_reparent(struct process *child, struct process *parent)
 {
 
-       if (child->p_pptr == parent)
+       if (child->ps_pptr == parent)
                return;
 
-       if (parent == initproc)
-               child->p_exitsig = SIGCHLD;
+       if (parent == initproc->p_p)
+               child->ps_mainproc->p_exitsig = SIGCHLD;
 
-       LIST_REMOVE(child, p_sibling);
-       LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
-       child->p_pptr = parent;
+       LIST_REMOVE(child, ps_sibling);
+       LIST_INSERT_HEAD(&parent->ps_children, child, ps_sibling);
+       child->ps_pptr = parent;
 }
 
 void
 proc_zap(struct proc *p)
 {
-       struct process *pr;
+       struct process *pr = p->p_p;
 
        pool_put(&rusage_pool, p->p_ru);
        if (p->p_ptstat)
@@ -565,9 +578,11 @@ proc_zap(struct proc *p)
         * Finally finished with old proc entry.
         * Unlink it from its process group and free it.
         */
-       leavepgrp(p);
+       if ((p->p_flag & P_THREAD) == 0)
+               leavepgrp(pr);
        LIST_REMOVE(p, p_list); /* off zombproc */
-       LIST_REMOVE(p, p_sibling);
+       if ((p->p_flag & P_THREAD) == 0)
+               LIST_REMOVE(pr, ps_sibling);
 
        /*
         * Decrement the count of procs running with this uid.
@@ -584,7 +599,6 @@ proc_zap(struct proc *p)
         * Remove us from our process list, possibly killing the process
         * in the process (pun intended).
         */
-       pr = p->p_p;
        if (--pr->ps_refcnt == 0) {
                KASSERT(TAILQ_EMPTY(&pr->ps_threads));
                limfree(pr->ps_limit);
@@ -596,4 +610,3 @@ proc_zap(struct proc *p)
        pool_put(&proc_pool, p);
        nprocs--;
 }
-
index 07b8b1b..b92ea4a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_fork.c,v 1.121 2010/07/23 14:19:02 miod Exp $    */
+/*     $OpenBSD: kern_fork.c,v 1.122 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $  */
 
 /*
@@ -158,12 +158,16 @@ process_new(struct proc *newproc, struct proc *parentproc)
 
        pr = pool_get(&process_pool, PR_WAITOK);
        pr->ps_mainproc = newproc;
+       parent = parentproc->p_p;
+
        TAILQ_INIT(&pr->ps_threads);
        TAILQ_INSERT_TAIL(&pr->ps_threads, newproc, p_thr_link);
+       LIST_INSERT_AFTER(parent, pr, ps_pglist);
+       pr->ps_pptr = parent;
+       LIST_INSERT_HEAD(&parent->ps_children, pr, ps_sibling);
+       LIST_INIT(&pr->ps_children);
        pr->ps_refcnt = 1;
 
-       parent = parentproc->p_p;
-
        /*
         * Make a process structure for the new process.
         * Start by zeroing the section of proc that is zero-initialized,
@@ -180,6 +184,10 @@ process_new(struct proc *newproc, struct proc *parentproc)
        crhold(parent->ps_cred->pc_ucred);
        pr->ps_limit->p_refcnt++;
 
+       if (parent->ps_session->s_ttyvp != NULL &&
+           parent->ps_flags & PS_CONTROLT)
+               atomic_setbits_int(&pr->ps_flags, PS_CONTROLT);
+
        newproc->p_p = pr;
 }
 
@@ -311,14 +319,10 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
        else
                p2->p_fd = fdcopy(p1);
 
-       if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
-               atomic_setbits_int(&p2->p_flag, P_CONTROLT);
        if (flags & FORK_PPWAIT)
                atomic_setbits_int(&p2->p_flag, P_PPWAIT);
-       p2->p_pptr = p1;
        if (flags & FORK_NOZOMBIE)
                atomic_setbits_int(&p2->p_flag, P_NOZOMBIE);
-       LIST_INIT(&p2->p_children);
 
 #ifdef KTRACE
        /*
@@ -396,12 +400,12 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
 
        LIST_INSERT_HEAD(&allproc, p2, p_list);
        LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
-       LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
-       LIST_INSERT_AFTER(p1, p2, p_pglist);
+
        if (p2->p_flag & P_TRACED) {
                p2->p_oppid = p1->p_pid;
-               if (p2->p_pptr != p1->p_pptr)
-                       proc_reparent(p2, p1->p_pptr);
+               if ((flags & FORK_THREAD) == 0 &&
+                   p2->p_p->ps_pptr != p1->p_p->ps_pptr)
+                       proc_reparent(p2->p_p, p1->p_p->ps_pptr);
 
                /*
                 * Set ptrace status.
@@ -459,11 +463,11 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
        /*
         * Preserve synchronization semantics of vfork.  If waiting for
         * child to exec or exit, set P_PPWAIT on child, and sleep on our
-        * proc (in case of exit).
+        * process (in case of exit).
         */
        if (flags & FORK_PPWAIT)
                while (p2->p_flag & P_PPWAIT)
-                       tsleep(p1, PWAIT, "ppwait", 0);
+                       tsleep(p1->p_p, PWAIT, "ppwait", 0);
 
        /*
         * If we're tracing the child, alert the parent too.
@@ -494,9 +498,10 @@ pidtaken(pid_t pid)
                return (1);
        if (pgfind(pid) != NULL)
                return (1);
-       LIST_FOREACH(p, &zombproc, p_list)
-               if (p->p_pid == pid || (p->p_pgrp && p->p_pgrp->pg_id == pid))
+       LIST_FOREACH(p, &zombproc, p_list) {
+               if (p->p_pid == pid || (p->p_p->ps_pgrp && p->p_p->ps_pgrp->pg_id == pid))
                        return (1);
+       }
        return (0);
 }
 
index f0f8d6d..a531256 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_ktrace.c,v 1.48 2009/10/31 12:00:08 fgsch Exp $  */
+/*     $OpenBSD: kern_ktrace.c,v 1.49 2010/07/26 01:56:27 guenther Exp $       */
 /*     $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $        */
 
 /*
@@ -54,7 +54,7 @@
 
 void ktrinitheader(struct ktr_header *, struct proc *, int);
 int ktrops(struct proc *, struct proc *, int, int, struct vnode *);
-int ktrsetchildren(struct proc *, struct proc *, int, int,
+int ktrsetchildren(struct proc *, struct process *, int, int,
                        struct vnode *);
 int ktrwrite(struct proc *, struct ktr_header *);
 int ktrcanset(struct proc *, struct proc *);
@@ -290,6 +290,7 @@ sys_ktrace(struct proc *curp, void *v, register_t *retval)
        } */ *uap = v;
        struct vnode *vp = NULL;
        struct proc *p = NULL;
+       struct process *pr = NULL;
        struct pgrp *pg;
        int facs = SCARG(uap, facs) & ~((unsigned) KTRFAC_ROOT);
        int ops = KTROP(SCARG(uap, ops));
@@ -352,25 +353,29 @@ sys_ktrace(struct proc *curp, void *v, register_t *retval)
                        error = ESRCH;
                        goto done;
                }
-               LIST_FOREACH(p, &pg->pg_members, p_pglist)
+               LIST_FOREACH(pr, &pg->pg_members, ps_pglist) {
                        if (descend)
-                               ret |= ktrsetchildren(curp, p, ops, facs, vp);
+                               ret |= ktrsetchildren(curp, pr, ops, facs, vp);
                        else 
-                               ret |= ktrops(curp, p, ops, facs, vp);
+                               TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link)
+                                       ret |= ktrops(curp, p, ops, facs, vp);
+               }
                                        
        } else {
                /*
                 * by pid
                 */
-               p = pfind(SCARG(uap, pid));
-               if (p == NULL) {
+               pr = prfind(SCARG(uap, pid));
+               if (pr == NULL) {
                        error = ESRCH;
                        goto done;
                }
                if (descend)
-                       ret |= ktrsetchildren(curp, p, ops, facs, vp);
+                       ret |= ktrsetchildren(curp, pr, ops, facs, vp);
                else
-                       ret |= ktrops(curp, p, ops, facs, vp);
+                       TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
+                               ret |= ktrops(curp, p, ops, facs, vp);
+               }
        }
        if (!ret)
                error = EPERM;
@@ -412,30 +417,32 @@ ktrops(struct proc *curp, struct proc *p, int ops, int facs, struct vnode *vp)
 }
 
 int
-ktrsetchildren(struct proc *curp, struct proc *top, int ops, int facs,
+ktrsetchildren(struct proc *curp, struct process *top, int ops, int facs,
     struct vnode *vp)
 {
+       struct process *pr;
        struct proc *p;
        int ret = 0;
 
-       p = top;
+       pr = top;
        for (;;) {
-               ret |= ktrops(curp, p, ops, facs, vp);
+               TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link)
+                       ret |= ktrops(curp, p, ops, facs, vp);
                /*
                 * If this process has children, descend to them next,
                 * otherwise do any siblings, and if done with this level,
                 * follow back up the tree (but not past top).
                 */
-               if (!LIST_EMPTY(&p->p_children))
-                       p = LIST_FIRST(&p->p_children);
+               if (!LIST_EMPTY(&pr->ps_children))
+                       pr = LIST_FIRST(&pr->ps_children);
                else for (;;) {
-                       if (p == top)
+                       if (pr == top)
                                return (ret);
-                       if (LIST_NEXT(p, p_sibling) != NULL) {
-                               p = LIST_NEXT(p, p_sibling);
+                       if (LIST_NEXT(pr, ps_sibling) != NULL) {
+                               pr = LIST_NEXT(pr, ps_sibling);
                                break;
                        }
-                       p = p->p_pptr;
+                       pr = pr->ps_pptr;
                }
        }
        /*NOTREACHED*/
index 96276b5..d609994 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_proc.c,v 1.44 2010/07/19 23:00:15 guenther Exp $ */
+/*     $OpenBSD: kern_proc.c,v 1.45 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $  */
 
 /*
@@ -135,7 +135,7 @@ uid_find(uid_t uid)
 }
 
 /*
- * Change the count associated with number of processes
+ * Change the count associated with number of threads
  * a given user is using.
  */
 int
@@ -154,17 +154,17 @@ chgproccnt(uid_t uid, int diff)
  * Is p an inferior of parent?
  */
 int
-inferior(struct proc *p, struct proc *parent)
+inferior(struct process *pr, struct process *parent)
 {
 
-       for (; p != parent; p = p->p_pptr)
-               if (p->p_pid == 0 || p->p_pid == 1)
+       for (; pr != parent; pr = pr->ps_pptr)
+               if (pr->ps_pid == 0 || pr->ps_pid == 1)
                        return (0);
        return (1);
 }
 
 /*
- * Locate a process by number
+ * Locate a proc (thread) by number
  */
 struct proc *
 pfind(pid_t pid)
@@ -177,6 +177,20 @@ pfind(pid_t pid)
        return (NULL);
 }
 
+/*
+ * Locate a process by number
+ */
+struct process *
+prfind(pid_t pid)
+{
+       struct proc *p;
+
+       LIST_FOREACH(p, PIDHASH(pid), p_hash)
+               if (p->p_pid == pid)
+                       return (p->p_flag & P_THREAD ? NULL : p->p_p);
+       return (NULL);
+}
+
 /*
  * Locate a process group by number
  */
@@ -195,9 +209,10 @@ pgfind(pid_t pgid)
  * Move p to a new or existing process group (and session)
  * Caller provides a pre-allocated pgrp and session that should
  * be freed if they are not used.
+ * XXX need proctree lock
  */
 int
-enterpgrp(struct proc *p, pid_t pgid, struct pgrp *newpgrp,
+enterpgrp(struct process *pr, pid_t pgid, struct pgrp *newpgrp,
     struct session *newsess)
 {
        struct pgrp *pgrp = pgfind(pgid);
@@ -205,52 +220,44 @@ enterpgrp(struct proc *p, pid_t pgid, struct pgrp *newpgrp,
 #ifdef DIAGNOSTIC
        if (pgrp != NULL && newsess)    /* firewalls */
                panic("enterpgrp: setsid into non-empty pgrp");
-       if (SESS_LEADER(p))
+       if (SESS_LEADER(pr))
                panic("enterpgrp: session leader attempted setpgrp");
 #endif
        if (pgrp == NULL) {
-               struct proc *np;
                /*
                 * new process group
                 */
 #ifdef DIAGNOSTIC
-               if (p->p_pid != pgid)
+               if (pr->ps_pid != pgid)
                        panic("enterpgrp: new pgrp and pid != pgid");
 #endif
 
-               if ((np = pfind(p->p_pid)) == NULL || np != p) {
-                       pool_put(&pgrp_pool, newpgrp);
-                       if (newsess)
-                               pool_put(&session_pool, newsess);
-                       return (ESRCH);
-               }
-
                pgrp = newpgrp;
                if (newsess) {
                        /*
                         * new session
                         */
-                       newsess->s_leader = p;
+                       newsess->s_leader = pr;
                        newsess->s_count = 1;
                        newsess->s_ttyvp = NULL;
                        newsess->s_ttyp = NULL;
-                       bcopy(p->p_session->s_login, newsess->s_login,
+                       bcopy(pr->ps_session->s_login, newsess->s_login,
                            sizeof(newsess->s_login));
-                       atomic_clearbits_int(&p->p_flag, P_CONTROLT);
+                       atomic_clearbits_int(&pr->ps_flags, PS_CONTROLT);
                        pgrp->pg_session = newsess;
 #ifdef DIAGNOSTIC
-                       if (p != curproc)
-                               panic("enterpgrp: mksession and p != curproc");
+                       if (pr != curproc->p_p)
+                               panic("enterpgrp: mksession but not curproc");
 #endif
                } else {
-                       pgrp->pg_session = p->p_session;
+                       pgrp->pg_session = pr->ps_session;
                        pgrp->pg_session->s_count++;
                }
                pgrp->pg_id = pgid;
                LIST_INIT(&pgrp->pg_members);
                LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
                pgrp->pg_jobc = 0;
-       } else if (pgrp == p->p_pgrp) {
+       } else if (pgrp == pr->ps_pgrp) {
                if (newsess)
                        pool_put(&session_pool, newsess);
                pool_put(&pgrp_pool, newpgrp);
@@ -266,29 +273,28 @@ enterpgrp(struct proc *p, pid_t pgid, struct pgrp *newpgrp,
         * Increment eligibility counts before decrementing, otherwise we
         * could reach 0 spuriously during the first call.
         */
-       fixjobc(p, pgrp, 1);
-       fixjobc(p, p->p_pgrp, 0);
-
-       LIST_REMOVE(p, p_pglist);
-       if (LIST_EMPTY(&p->p_pgrp->pg_members))
-               pgdelete(p->p_pgrp);
-       p->p_pgrp = pgrp;
-       LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
+       fixjobc(pr, pgrp, 1);
+       fixjobc(pr, pr->ps_pgrp, 0);
+
+       LIST_REMOVE(pr, ps_pglist);
+       if (LIST_EMPTY(&pr->ps_pgrp->pg_members))
+               pgdelete(pr->ps_pgrp);
+       pr->ps_pgrp = pgrp;
+       LIST_INSERT_HEAD(&pgrp->pg_members, pr, ps_pglist);
        return (0);
 }
 
 /*
  * remove process from process group
  */
-int
-leavepgrp(struct proc *p)
+void
+leavepgrp(struct process *pr)
 {
 
-       LIST_REMOVE(p, p_pglist);
-       if (LIST_EMPTY(&p->p_pgrp->pg_members))
-               pgdelete(p->p_pgrp);
-       p->p_pgrp = 0;
-       return (0);
+       LIST_REMOVE(pr, ps_pglist);
+       if (LIST_EMPTY(&pr->ps_pgrp->pg_members))
+               pgdelete(pr->ps_pgrp);
+       pr->ps_pgrp = 0;
 }
 
 /*
@@ -313,20 +319,21 @@ pgdelete(struct pgrp *pgrp)
  * process group of the same session).  If that count reaches zero, the
  * process group becomes orphaned.  Check both the specified process'
  * process group and that of its children.
- * entering == 0 => p is leaving specified group.
- * entering == 1 => p is entering specified group.
+ * entering == 0 => pr is leaving specified group.
+ * entering == 1 => pr is entering specified group.
+ * XXX need proctree lock
  */
 void
-fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
+fixjobc(struct process *pr, struct pgrp *pgrp, int entering)
 {
        struct pgrp *hispgrp;
        struct session *mysession = pgrp->pg_session;
 
        /*
-        * Check p's parent to see whether p qualifies its own process
-        * group; if so, adjust count for p's process group.
+        * Check pr's parent to see whether pr qualifies its own process
+        * group; if so, adjust count for pr's process group.
         */
-       if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
+       if ((hispgrp = pr->ps_pptr->ps_pgrp) != pgrp &&
            hispgrp->pg_session == mysession) {
                if (entering)
                        pgrp->pg_jobc++;
@@ -339,10 +346,10 @@ fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
         * their process groups; if so, adjust counts for children's
         * process groups.
         */
-       LIST_FOREACH(p, &p->p_children, p_sibling)
-               if ((hispgrp = p->p_pgrp) != pgrp &&
+       LIST_FOREACH(pr, &pr->ps_children, ps_sibling)
+               if ((hispgrp = pr->ps_pgrp) != pgrp &&
                    hispgrp->pg_session == mysession &&
-                   P_ZOMBIE(p) == 0) {
+                   P_ZOMBIE(pr->ps_mainproc) == 0) {
                        if (entering)
                                hispgrp->pg_jobc++;
                        else if (--hispgrp->pg_jobc == 0)
@@ -358,13 +365,13 @@ fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
 static void
 orphanpg(struct pgrp *pg)
 {
-       struct proc *p;
+       struct process *pr;
 
-       LIST_FOREACH(p, &pg->pg_members, p_pglist) {
-               if (p->p_stat == SSTOP) {
-                       LIST_FOREACH(p, &pg->pg_members, p_pglist) {
-                               psignal(p, SIGHUP);
-                               psignal(p, SIGCONT);
+       LIST_FOREACH(pr, &pg->pg_members, ps_pglist) {
+               if (pr->ps_mainproc->p_stat == SSTOP) {
+                       LIST_FOREACH(pr, &pg->pg_members, ps_pglist) {
+                               prsignal(pr, SIGHUP);
+                               prsignal(pr, SIGCONT);
                        }
                        return;
                }
@@ -381,6 +388,7 @@ proc_printit(struct proc *p, const char *modif, int (*pr)(const char *, ...))
        char pstbuf[5];
        const char *pst = pstbuf;
 
+
        if (p->p_stat < 1 || p->p_stat > sizeof(pstat) / sizeof(pstat[0]))
                snprintf(pstbuf, sizeof(pstbuf), "%d", p->p_stat);
        else
@@ -392,8 +400,8 @@ proc_printit(struct proc *p, const char *modif, int (*pr)(const char *, ...))
            p->p_priority, p->p_usrpri, p->p_nice);
        (*pr)("    forw=%p, list=%p,%p\n",
            TAILQ_NEXT(p, p_runq), p->p_list.le_next, p->p_list.le_prev);
-       (*pr)("    user=%p, vmspace=%p\n",
-           p->p_addr, p->p_vmspace);
+       (*pr)("    process=%p user=%p, vmspace=%p\n",
+           p->p_p, p->p_addr, p->p_vmspace);
        (*pr)("    estcpu=%u, cpticks=%d, pctcpu=%u.%u%, swtime=%u\n",
            p->p_estcpu, p->p_cpticks, p->p_pctcpu / 100, p->p_pctcpu % 100,
            p->p_swtime);
@@ -410,7 +418,8 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
 {
        char *mode;
        int doingzomb = 0;
-       struct proc *p, *pp;
+       struct proc *p;
+       struct process *pr, *ppr;
     
        if (modif[0] == 0)
                modif[0] = 'n';                 /* default == normal mode */
@@ -445,7 +454,8 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
        }
 
        while (p != 0) {
-               pp = p->p_pptr;
+               pr = p->p_p;
+               ppr = pr->ps_pptr;
                if (p->p_stat) {
 
                        db_printf("%c%5d  ", p == curproc ? '*' : ' ',
@@ -461,9 +471,9 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
                        case 'n':
                                db_printf("%5d  %5d  %5d  %d  %#10x  "
                                    "%-12.12s  %-16s\n",
-                                   pp ? pp->p_pid : -1,
-                                   p->p_pgrp ? p->p_pgrp->pg_id : -1,
-                                   p->p_cred->p_ruid, p->p_stat, p->p_flag,
+                                   ppr ? ppr->ps_pid : -1,
+                                   pr->ps_pgrp ? pr->ps_pgrp->pg_id : -1,
+                                   pr->ps_cred->p_ruid, p->p_stat, p->p_flag,
                                    (p->p_wchan && p->p_wmesg) ?
                                        p->p_wmesg : "", p->p_comm);
                                break;
@@ -491,7 +501,7 @@ void
 pgrpdump(void)
 {
        struct pgrp *pgrp;
-       struct proc *p;
+       struct process *pr;
        int i;
 
        for (i = 0; i <= pgrphash; i++) {
@@ -502,9 +512,9 @@ pgrpdump(void)
                                    pgrp, pgrp->pg_id, pgrp->pg_session,
                                    pgrp->pg_session->s_count,
                                    LIST_FIRST(&pgrp->pg_members));
-                               LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
+                               LIST_FOREACH(pr, &pgrp->pg_members, ps_pglist) {
                                        printf("\t\tpid %d addr %p pgrp %p\n", 
-                                           p->p_pid, p, p->p_pgrp);
+                                           pr->ps_pid, pr, pr->ps_pgrp);
                                }
                        }
                }
index 3f49186..a34714c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_prot.c,v 1.45 2010/07/01 02:41:12 guenther Exp $ */
+/*     $OpenBSD: kern_prot.c,v 1.46 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $  */
 
 /*
@@ -59,8 +59,8 @@ int
 sys_getpid(struct proc *p, void *v, register_t *retval)
 {
 
-       retval[0] = p->p_p->ps_mainproc->p_pid;
-       retval[1] = p->p_p->ps_mainproc->p_pptr->p_pid;
+       retval[0] = p->p_p->ps_pid;
+       retval[1] = p->p_p->ps_pptr->ps_pid;
        return (0);
 }
 
@@ -80,7 +80,7 @@ int
 sys_getppid(struct proc *p, void *v, register_t *retval)
 {
 
-       *retval = p->p_p->ps_mainproc->p_pptr->p_pid;
+       *retval = p->p_p->ps_pptr->ps_pid;
        return (0);
 }
 
@@ -89,7 +89,7 @@ int
 sys_getpgrp(struct proc *p, void *v, register_t *retval)
 {
 
-       *retval = p->p_pgrp->pg_id;
+       *retval = p->p_p->ps_pgrp->pg_id;
        return (0);
 }
 
@@ -102,16 +102,16 @@ sys_getpgid(struct proc *curp, void *v, register_t *retval)
        struct sys_getpgid_args /* {
                syscallarg(pid_t) pid;
        } */ *uap = v;
-       struct proc *targp = curp;
+       struct process *targpr = curp->p_p;
 
-       if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == curp->p_pid)
+       if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == targpr->ps_pid)
                goto found;
-       if ((targp = pfind(SCARG(uap, pid))) == NULL)
+       if ((targpr = prfind(SCARG(uap, pid))) == NULL)
                return (ESRCH);
-       if (targp->p_session != curp->p_session)
+       if (targpr->ps_session != curp->p_p->ps_session)
                return (EPERM);
 found:
-       *retval = targp->p_pgid;
+       *retval = targpr->ps_pgid;
        return (0);
 }
 
@@ -121,19 +121,19 @@ sys_getsid(struct proc *curp, void *v, register_t *retval)
        struct sys_getsid_args /* {
                syscallarg(pid_t) pid;
        } */ *uap = v;
-       struct proc *targp = curp;
+       struct process *targpr = curp->p_p;
 
-       if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == curp->p_pid)
+       if (SCARG(uap, pid) == 0 || SCARG(uap, pid) == targpr->ps_pid)
                goto found;
-       if ((targp = pfind(SCARG(uap, pid))) == NULL)
+       if ((targpr = prfind(SCARG(uap, pid))) == NULL)
                return (ESRCH);
-       if (targp->p_session != curp->p_session)
+       if (targpr->ps_session != curp->p_p->ps_session)
                return (EPERM);
 found:
        /* Skip exiting processes */
-       if (targp->p_pgrp->pg_session->s_leader == NULL)
+       if (targpr->ps_pgrp->pg_session->s_leader == NULL)
                return (ESRCH);
-       *retval = targp->p_pgrp->pg_session->s_leader->p_pid;
+       *retval = targpr->ps_pgrp->pg_session->s_leader->ps_pid;
        return (0);
 }
 
@@ -223,17 +223,19 @@ sys_setsid(struct proc *p, void *v, register_t *retval)
 {
        struct session *newsess;
        struct pgrp *newpgrp;
+       struct process *pr = p->p_p;
+       pid_t pid = pr->ps_pid;
 
        newsess = pool_get(&session_pool, PR_WAITOK);
        newpgrp = pool_get(&pgrp_pool, PR_WAITOK);
 
-       if (p->p_pgid == p->p_pid || pgfind(p->p_pid)) {
+       if (pr->ps_pgid == pid || pgfind(pid)) {
                pool_put(&pgrp_pool, newpgrp);
                pool_put(&session_pool, newsess);
                return (EPERM);
        } else {
-               (void) enterpgrp(p, p->p_pid, newpgrp, newsess);
-               *retval = p->p_pid;
+               (void) enterpgrp(pr, pid, newpgrp, newsess);
+               *retval = pid;
                return (0);
        }
 }
@@ -259,7 +261,8 @@ sys_setpgid(struct proc *curp, void *v, register_t *retval)
                syscallarg(pid_t) pid;
                syscallarg(int) pgid;
        } */ *uap = v;
-       struct proc *targp;             /* target process */
+       struct process *curpr = curp->p_p;
+       struct process *targpr;         /* target process */
        struct pgrp *pgrp, *newpgrp;    /* target pgrp */
        pid_t pid;
        int pgid, error;
@@ -272,34 +275,34 @@ sys_setpgid(struct proc *curp, void *v, register_t *retval)
 
        newpgrp = pool_get(&pgrp_pool, PR_WAITOK);
 
-       if (pid != 0 && pid != curp->p_pid) {
-               if ((targp = pfind(pid)) == 0 || !inferior(targp, curp)) {
+       if (pid != 0 && pid != curpr->ps_pid) {
+               if ((targpr = prfind(pid)) == 0 || !inferior(targpr, curpr)) {
                        error = ESRCH;
                        goto out;
                }
-               if (targp->p_session != curp->p_session) {
+               if (targpr->ps_session != curpr->ps_session) {
                        error = EPERM;
                        goto out;
                }
-               if (targp->p_flag & P_EXEC) {
+               if (targpr->ps_mainproc->p_flag & P_EXEC) {
                        error = EACCES;
                        goto out;
                }
        } else
-               targp = curp;
-       if (SESS_LEADER(targp)) {
+               targpr = curpr;
+       if (SESS_LEADER(targpr)) {
                error = EPERM;
                goto out;
        }
        if (pgid == 0)
-               pgid = targp->p_pid;
-       else if (pgid != targp->p_pid)
+               pgid = targpr->ps_pid;
+       else if (pgid != targpr->ps_pid)
                if ((pgrp = pgfind(pgid)) == 0 ||
-                   pgrp->pg_session != curp->p_session) {
+                   pgrp->pg_session != curpr->ps_session) {
                        error = EPERM;
                        goto out;
                }
-       return (enterpgrp(targp, pgid, newpgrp, NULL));
+       return (enterpgrp(targpr, pgid, newpgrp, NULL));
 out:
        pool_put(&pgrp_pool, newpgrp);
        return (error);
@@ -843,11 +846,12 @@ sys_getlogin(struct proc *p, void *v, register_t *retval)
                syscallarg(char *) namebuf;
                syscallarg(u_int) namelen;
        } */ *uap = v;
+       struct session *s = p->p_p->ps_pgrp->pg_session;
 
-       if (SCARG(uap, namelen) > sizeof (p->p_pgrp->pg_session->s_login))
-               SCARG(uap, namelen) = sizeof (p->p_pgrp->pg_session->s_login);
-       return (copyout((caddr_t) p->p_pgrp->pg_session->s_login,
-           (caddr_t) SCARG(uap, namebuf), SCARG(uap, namelen)));
+       if (SCARG(uap, namelen) > sizeof(s->s_login))
+               SCARG(uap, namelen) = sizeof(s->s_login);
+       return (copyout((caddr_t)s->s_login,
+           (caddr_t)SCARG(uap, namebuf), SCARG(uap, namelen)));
 }
 
 /*
@@ -860,13 +864,13 @@ sys_setlogin(struct proc *p, void *v, register_t *retval)
        struct sys_setlogin_args /* {
                syscallarg(const char *) namebuf;
        } */ *uap = v;
+       struct session *s = p->p_p->ps_pgrp->pg_session;
        int error;
 
        if ((error = suser(p, 0)) != 0)
                return (error);
-       error = copyinstr((caddr_t) SCARG(uap, namebuf),
-           (caddr_t) p->p_pgrp->pg_session->s_login,
-           sizeof (p->p_pgrp->pg_session->s_login), (size_t *)0);
+       error = copyinstr((caddr_t)SCARG(uap, namebuf), (caddr_t)s->s_login,
+           sizeof(s->s_login), NULL);
        if (error == ENAMETOOLONG)
                error = EINVAL;
        return (error);
index 9bf4e2e..76a078d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_resource.c,v 1.35 2010/06/29 20:14:46 guenther Exp $     */
+/*     $OpenBSD: kern_resource.c,v 1.36 2010/07/26 01:56:27 guenther Exp $     */
 /*     $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $      */
 
 /*-
@@ -68,6 +68,7 @@ sys_getpriority(struct proc *curp, void *v, register_t *retval)
                syscallarg(int) which;
                syscallarg(id_t) who;
        } */ *uap = v;
+       struct process *pr;
        struct proc *p;
        int low = NZERO + PRIO_MAX + 1;
 
@@ -75,25 +76,29 @@ sys_getpriority(struct proc *curp, void *v, register_t *retval)
 
        case PRIO_PROCESS:
                if (SCARG(uap, who) == 0)
-                       p = curp;
+                       pr = curp->p_p;
                else
-                       p = pfind(SCARG(uap, who));
-               if (p == 0)
+                       pr = prfind(SCARG(uap, who));
+               if (pr == NULL)
                        break;
-               low = p->p_nice;
+               TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
+                       if (p->p_nice < low)
+                               low = p->p_nice;
+               }
                break;
 
        case PRIO_PGRP: {
                struct pgrp *pg;
 
                if (SCARG(uap, who) == 0)
-                       pg = curp->p_pgrp;
+                       pg = curp->p_p->ps_pgrp;
                else if ((pg = pgfind(SCARG(uap, who))) == NULL)
                        break;
-               LIST_FOREACH(p, &pg->pg_members, p_pglist) {
-                       if (p->p_nice < low)
-                               low = p->p_nice;
-               }
+               LIST_FOREACH(pr, &pg->pg_members, ps_pglist)
+                       TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
+                               if (p->p_nice < low)
+                                       low = p->p_nice;
+                       }
                break;
        }
 
@@ -124,19 +129,19 @@ sys_setpriority(struct proc *curp, void *v, register_t *retval)
                syscallarg(id_t) who;
                syscallarg(int) prio;
        } */ *uap = v;
-       struct proc *p;
+       struct process *pr;
        int found = 0, error = 0;
 
        switch (SCARG(uap, which)) {
 
        case PRIO_PROCESS:
                if (SCARG(uap, who) == 0)
-                       p = curp;
+                       pr = curp->p_p;
                else
-                       p = pfind(SCARG(uap, who));
-               if (p == 0)
+                       pr = prfind(SCARG(uap, who));
+               if (pr == NULL)
                        break;
-               error = donice(curp, p, SCARG(uap, prio));
+               error = donice(curp, pr, SCARG(uap, prio));
                found++;
                break;
 
@@ -144,25 +149,28 @@ sys_setpriority(struct proc *curp, void *v, register_t *retval)
                struct pgrp *pg;
                 
                if (SCARG(uap, who) == 0)
-                       pg = curp->p_pgrp;
+                       pg = curp->p_p->ps_pgrp;
                else if ((pg = pgfind(SCARG(uap, who))) == NULL)
                        break;
-               LIST_FOREACH(p, &pg->pg_members, p_pglist) {
-                       error = donice(curp, p, SCARG(uap, prio));
+               LIST_FOREACH(pr, &pg->pg_members, ps_pglist) {
+                       error = donice(curp, pr, SCARG(uap, prio));
                        found++;
                }
                break;
        }
 
-       case PRIO_USER:
+       case PRIO_USER: {
+               struct proc *p;
                if (SCARG(uap, who) == 0)
                        SCARG(uap, who) = curp->p_ucred->cr_uid;
                LIST_FOREACH(p, &allproc, p_list)
-                       if (p->p_ucred->cr_uid == SCARG(uap, who)) {
-                               error = donice(curp, p, SCARG(uap, prio));
+                       if ((p->p_flag & P_THREAD) == 0 &&
+                           p->p_ucred->cr_uid == SCARG(uap, who)) {
+                               error = donice(curp, p->p_p, SCARG(uap, prio));
                                found++;
                        }
                break;
+       }
 
        default:
                return (EINVAL);
@@ -173,25 +181,28 @@ sys_setpriority(struct proc *curp, void *v, register_t *retval)
 }
 
 int
-donice(struct proc *curp, struct proc *chgp, int n)
+donice(struct proc *curp, struct process *chgpr, int n)
 {
        struct pcred *pcred = curp->p_cred;
+       struct proc *p;
        int s;
 
        if (pcred->pc_ucred->cr_uid && pcred->p_ruid &&
-           pcred->pc_ucred->cr_uid != chgp->p_ucred->cr_uid &&
-           pcred->p_ruid != chgp->p_ucred->cr_uid)
+           pcred->pc_ucred->cr_uid != chgpr->ps_cred->pc_ucred->cr_uid &&
+           pcred->p_ruid != chgpr->ps_cred->pc_ucred->cr_uid)
                return (EPERM);
        if (n > PRIO_MAX)
                n = PRIO_MAX;
        if (n < PRIO_MIN)
                n = PRIO_MIN;
        n += NZERO;
-       if (n < chgp->p_nice && suser(curp, 0))
+       /* XXX wrong: p_nice should be in process */
+       if (n < chgpr->ps_mainproc->p_nice && suser(curp, 0))
                return (EACCES);
-       chgp->p_nice = n;
+       chgpr->ps_mainproc->p_nice = n;
        SCHED_LOCK(s);
-       (void)resetpriority(chgp);
+       TAILQ_FOREACH(p, &chgpr->ps_threads, p_thr_link)
+               (void)resetpriority(p);
        SCHED_UNLOCK(s);
        return (0);
 }
@@ -364,13 +375,40 @@ sys_getrusage(struct proc *p, void *v, register_t *retval)
                syscallarg(int) who;
                syscallarg(struct rusage *) rusage;
        } */ *uap = v;
+       struct process *pr = p->p_p;
+       struct rusage ru;
        struct rusage *rup;
 
        switch (SCARG(uap, who)) {
 
        case RUSAGE_SELF:
+               calcru(p, &p->p_stats->p_ru.ru_utime,
+                   &p->p_stats->p_ru.ru_stime, NULL);
+               ru = p->p_stats->p_ru;
+               rup = &ru;
+
+               /* XXX add on already dead threads */
+
+               /* add on other living threads */
+               {
+                       struct proc *q;
+
+                       TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) {
+                               if (q == p || P_ZOMBIE(q))
+                                       continue;
+                               /*
+                                * XXX this is approximate: no call
+                                * to calcru in other running threads
+                                */
+                               ruadd(rup, &q->p_stats->p_ru);
+                       }
+               }
+               break;
+
+       case RUSAGE_THREAD:
                rup = &p->p_stats->p_ru;
                calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
+               ru = *rup;
                break;
 
        case RUSAGE_CHILDREN:
index eaff0b9..a672064 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_sig.c,v 1.115 2010/07/02 19:57:15 tedu Exp $     */
+/*     $OpenBSD: kern_sig.c,v 1.116 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $   */
 
 /*
@@ -96,7 +96,7 @@ cansignal(struct proc *p, struct pcred *pc, struct proc *q, int signum)
        if (p == q)
                return (1);             /* process can always signal itself */
 
-       if (signum == SIGCONT && q->p_session == p->p_session)
+       if (signum == SIGCONT && q->p_p->ps_session == p->p_p->ps_session)
                return (1);             /* SIGCONT in session */
 
        /*
@@ -620,6 +620,7 @@ int
 killpg1(struct proc *cp, int signum, int pgid, int all)
 {
        struct proc *p;
+       struct process *pr;
        struct pcred *pc = cp->p_cred;
        struct pgrp *pgrp;
        int nfound = 0;
@@ -641,13 +642,14 @@ killpg1(struct proc *cp, int signum, int pgid, int all)
                        /*
                         * zero pgid means send to my process group.
                         */
-                       pgrp = cp->p_pgrp;
+                       pgrp = cp->p_p->ps_pgrp;
                else {
                        pgrp = pgfind(pgid);
                        if (pgrp == NULL)
                                return (ESRCH);
                }
-               LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
+               LIST_FOREACH(pr, &pgrp->pg_members, ps_pglist) {
+                       p = pr->ps_mainproc;
                        if (p->p_pid <= 1 || p->p_flag & (P_SYSTEM|P_THREAD) ||
                            !cansignal(cp, pc, p, signum))
                                continue;
@@ -659,14 +661,14 @@ killpg1(struct proc *cp, int signum, int pgid, int all)
        return (nfound ? 0 : ESRCH);
 }
 
-#define CANDELIVER(uid, euid, p) \
+#define CANDELIVER(uid, euid, pr) \
        (euid == 0 || \
-       (uid) == (p)->p_cred->p_ruid || \
-       (uid) == (p)->p_cred->p_svuid || \
-       (uid) == (p)->p_ucred->cr_uid || \
-       (euid) == (p)->p_cred->p_ruid || \
-       (euid) == (p)->p_cred->p_svuid || \
-       (euid) == (p)->p_ucred->cr_uid)
+       (uid) == (pr)->ps_cred->p_ruid || \
+       (uid) == (pr)->ps_cred->p_svuid || \
+       (uid) == (pr)->ps_cred->pc_ucred->cr_uid || \
+       (euid) == (pr)->ps_cred->p_ruid || \
+       (euid) == (pr)->ps_cred->p_svuid || \
+       (euid) == (pr)->ps_cred->pc_ucred->cr_uid)
 
 /*
  * Deliver signum to pgid, but first check uid/euid against each
@@ -676,7 +678,7 @@ void
 csignal(pid_t pgid, int signum, uid_t uid, uid_t euid)
 {
        struct pgrp *pgrp;
-       struct proc *p;
+       struct process *pr;
 
        if (pgid == 0)
                return;
@@ -684,14 +686,14 @@ csignal(pid_t pgid, int signum, uid_t uid, uid_t euid)
                pgid = -pgid;
                if ((pgrp = pgfind(pgid)) == NULL)
                        return;
-               LIST_FOREACH(p, &pgrp->pg_members, p_pglist)
-                       if (CANDELIVER(uid, euid, p))
-                               psignal(p, signum);
+               LIST_FOREACH(pr, &pgrp->pg_members, ps_pglist)
+                       if (CANDELIVER(uid, euid, pr))
+                               prsignal(pr, signum);
        } else {
-               if ((p = pfind(pgid)) == NULL)
+               if ((pr = prfind(pgid)) == NULL)
                        return;
-               if (CANDELIVER(uid, euid, p))
-                       psignal(p, signum);
+               if (CANDELIVER(uid, euid, pr))
+                       prsignal(pr, signum);
        }
 }
 
@@ -714,13 +716,12 @@ gsignal(int pgid, int signum)
 void
 pgsignal(struct pgrp *pgrp, int signum, int checkctty)
 {
-       struct proc *p;
+       struct process *pr;
 
        if (pgrp)
-               LIST_FOREACH(p, &pgrp->pg_members, p_pglist)
-                       if ((checkctty == 0 || p->p_flag & P_CONTROLT) &&
-                           (p->p_flag & P_THREAD) == 0)
-                               psignal(p, signum);
+               LIST_FOREACH(pr, &pgrp->pg_members, ps_pglist)
+                       if (checkctty == 0 || pr->ps_flags & PS_CONTROLT)
+                               prsignal(pr, signum);
 }
 
 /*
@@ -866,7 +867,7 @@ ptsignal(struct proc *p, int signum, enum signal_type type)
                         * the action is default; don't stop the process below
                         * if sleeping, and don't clear any pending SIGCONT.
                         */
-                       if (prop & SA_TTYSTOP && p->p_pgrp->pg_jobc == 0)
+                       if (prop & SA_TTYSTOP && p->p_p->ps_pgrp->pg_jobc == 0)
                                return;
                }
        }
@@ -1031,7 +1032,7 @@ run:
 out:
        SCHED_UNLOCK(s);
        if (wakeparent)
-               wakeup(p->p_pptr);
+               wakeup(p->p_p->ps_pptr);
 }
 
 /*
@@ -1136,7 +1137,7 @@ issignal(struct proc *p)
                         */
                        if (prop & SA_STOP) {
                                if (p->p_flag & P_TRACED ||
-                                   (p->p_pgrp->pg_jobc == 0 &&
+                                   (p->p_p->ps_pgrp->pg_jobc == 0 &&
                                    prop & SA_TTYSTOP))
                                        break;  /* == ignore */
                                p->p_xstat = signum;
@@ -1226,9 +1227,9 @@ proc_stop_sweep(void *v)
                        continue;
                atomic_clearbits_int(&p->p_flag, P_STOPPED);
 
-               if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0)
-                       psignal(p->p_pptr, SIGCHLD);
-               wakeup(p->p_pptr);
+               if ((p->p_p->ps_pptr->ps_mainproc->p_flag & P_NOCLDSTOP) == 0)
+                       prsignal(p->p_p->ps_pptr, SIGCHLD);
+               wakeup(p->p_p->ps_pptr);
        }
 }
 
index 2e78801..4973cf6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_sysctl.c,v 1.190 2010/07/19 23:00:15 guenther Exp $      */
+/*     $OpenBSD: kern_sysctl.c,v 1.191 2010/07/26 01:56:27 guenther Exp $      */
 /*     $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $     */
 
 /*-
@@ -1316,6 +1316,7 @@ sysctl_doproc(int *name, u_int namelen, char *where, size_t *sizep)
        struct kinfo_proc2 *kproc2 = NULL;
        struct eproc *eproc = NULL;
        struct proc *p;
+       struct process *pr;
        char *dp;
        int arg, buflen, doingzomb, elem_size, elem_count;
        int error, needed, type, op;
@@ -1354,7 +1355,8 @@ again:
                        continue;
 
                /* XXX skip processes in the middle of being zapped */
-               if (p->p_pgrp == NULL)
+               pr = p->p_p;
+               if (pr->ps_pgrp == NULL)
                        continue;
 
                /*
@@ -1370,20 +1372,20 @@ again:
 
                case KERN_PROC_PGRP:
                        /* could do this by traversing pgrp */
-                       if (p->p_pgrp->pg_id != (pid_t)arg)
+                       if (pr->ps_pgrp->pg_id != (pid_t)arg)
                                continue;
                        break;
 
                case KERN_PROC_SESSION:
-                       if (p->p_session->s_leader == NULL ||
-                           p->p_session->s_leader->p_pid != (pid_t)arg)
+                       if (pr->ps_session->s_leader == NULL ||
+                           pr->ps_session->s_leader->ps_pid != (pid_t)arg)
                                continue;
                        break;
 
                case KERN_PROC_TTY:
-                       if ((p->p_flag & P_CONTROLT) == 0 ||
-                           p->p_session->s_ttyp == NULL ||
-                           p->p_session->s_ttyp->t_dev != (dev_t)arg)
+                       if ((pr->ps_flags & PS_CONTROLT) == 0 ||
+                           pr->ps_session->s_ttyp == NULL ||
+                           pr->ps_session->s_ttyp->t_dev != (dev_t)arg)
                                continue;
                        break;
 
@@ -1475,7 +1477,7 @@ fill_eproc(struct proc *p, struct eproc *ep)
        struct tty *tp;
 
        ep->e_paddr = p;
-       ep->e_sess = p->p_pgrp->pg_session;
+       ep->e_sess = p->p_p->ps_pgrp->pg_session;
        ep->e_pcred = *p->p_cred;
        ep->e_ucred = *p->p_ucred;
        if (p->p_stat == SIDL || P_ZOMBIE(p)) {
@@ -1495,13 +1497,13 @@ fill_eproc(struct proc *p, struct eproc *ep)
                ep->e_pstats = *p->p_stats;
                ep->e_pstats_valid = 1;
        }
-       if (p->p_pptr)
-               ep->e_ppid = p->p_pptr->p_pid;
+       if (p->p_p->ps_pptr)
+               ep->e_ppid = p->p_p->ps_pptr->ps_pid;
        else
                ep->e_ppid = 0;
-       ep->e_pgid = p->p_pgrp->pg_id;
-       ep->e_jobc = p->p_pgrp->pg_jobc;
-       if ((p->p_flag & P_CONTROLT) &&
+       ep->e_pgid = p->p_p->ps_pgrp->pg_id;
+       ep->e_jobc = p->p_p->ps_pgrp->pg_jobc;
+       if ((p->p_p->ps_flags & PS_CONTROLT) &&
             (tp = ep->e_sess->s_ttyp)) {
                ep->e_tdev = tp->t_dev;
                ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
@@ -1509,7 +1511,7 @@ fill_eproc(struct proc *p, struct eproc *ep)
        } else
                ep->e_tdev = NODEV;
        ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
-       if (SESS_LEADER(p))
+       if (SESS_LEADER(p->p_p))
                ep->e_flag |= EPROC_SLEADER;
        strncpy(ep->e_wmesg, p->p_wmesg ? p->p_wmesg : "", WMESGLEN);
        ep->e_wmesg[WMESGLEN] = '\0';
@@ -1529,19 +1531,21 @@ fill_eproc(struct proc *p, struct eproc *ep)
 void
 fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
 {
+       struct process *pr = p->p_p;
+       struct session *s = pr->ps_session;
        struct tty *tp;
        struct timeval ut, st;
 
-       FILL_KPROC2(ki, strlcpy, p, p->p_p, p->p_cred, p->p_ucred, p->p_pgrp,
-           p, p->p_session, p->p_vmspace, p->p_p->ps_limit, p->p_stats);
+       FILL_KPROC2(ki, strlcpy, p, pr, p->p_cred, p->p_ucred, pr->ps_pgrp,
+           p, pr, s, p->p_vmspace, pr->ps_limit, p->p_stats);
 
        /* stuff that's too painful to generalize into the macros */
-       if (p->p_pptr)
-               ki->p_ppid = p->p_pptr->p_pid;
-       if (p->p_session->s_leader)
-               ki->p_sid = p->p_session->s_leader->p_pid;
+       if (pr->ps_pptr)
+               ki->p_ppid = pr->ps_pptr->ps_pid;
+       if (s->s_leader)
+               ki->p_sid = s->s_leader->ps_pid;
 
-       if ((p->p_flag & P_CONTROLT) && (tp = p->p_session->s_ttyp)) {
+       if ((pr->ps_flags & PS_CONTROLT) && (tp = s->s_ttyp)) {
                ki->p_tdev = tp->t_dev;
                ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : -1;
                ki->p_tsess = PTRTOINT64(tp->t_session);
index c1816c5..11fde4c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: spec_vnops.c,v 1.57 2010/05/18 04:41:14 dlg Exp $     */
+/*     $OpenBSD: spec_vnops.c,v 1.58 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: spec_vnops.c,v 1.29 1996/04/22 01:42:38 christos Exp $ */
 
 /*
@@ -500,9 +500,9 @@ spec_close(void *v)
                 * plus the session), release the reference from the session.
                 */
                if (vcount(vp) == 2 && ap->a_p &&
-                   vp == ap->a_p->p_session->s_ttyvp) {
+                   vp == ap->a_p->p_p->ps_session->s_ttyvp) {
                        vrele(vp);
-                       ap->a_p->p_session->s_ttyvp = NULL;
+                       ap->a_p->p_p->ps_session->s_ttyvp = NULL;
                }
                if (cdevsw[major(dev)].d_flags & D_CLONE)
                        return (spec_close_clone(ap));
index 5d18a97..30e7dce 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: subr_prf.c,v 1.74 2008/06/27 17:23:24 miod Exp $      */
+/*     $OpenBSD: subr_prf.c,v 1.75 2010/07/26 01:56:27 guenther Exp $  */
 /*     $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $      */
 
 /*-
@@ -357,12 +357,12 @@ kputchar(int c, int flags, struct tty *tp)
 void
 uprintf(const char *fmt, ...)
 {
-       struct proc *p = curproc;
+       struct process *pr = curproc->p_p;
        va_list ap;
 
-       if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
+       if (pr->ps_flags & PS_CONTROLT && pr->ps_session->s_ttyvp) {
                va_start(ap, fmt);
-               kprintf(fmt, TOTTY, p->p_session->s_ttyp, NULL, ap);
+               kprintf(fmt, TOTTY, pr->ps_session->s_ttyp, NULL, ap);
                va_end(ap);
        }
 }
@@ -380,6 +380,7 @@ uprintf(const char *fmt, ...)
 
 /*
  * tprintf_open: get a tprintf handle on a process "p"
+ * XXX change s/proc/process
  *
  * => returns NULL if process can't be printed to
  */
@@ -387,10 +388,11 @@ uprintf(const char *fmt, ...)
 tpr_t
 tprintf_open(struct proc *p)
 {
+       struct process *pr = p->p_p;
 
-       if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
-               SESSHOLD(p->p_session);
-               return ((tpr_t) p->p_session);
+       if (pr->ps_flags & PS_CONTROLT && pr->ps_session->s_ttyvp) {
+               SESSHOLD(pr->ps_session);
+               return ((tpr_t)pr->ps_session);
        }
        return ((tpr_t) NULL);
 }
index 73e30f6..9e49c7f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_generic.c,v 1.69 2010/07/08 20:15:03 deraadt Exp $        */
+/*     $OpenBSD: sys_generic.c,v 1.70 2010/07/26 01:56:27 guenther Exp $       */
 /*     $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $     */
 
 /*
@@ -476,12 +476,12 @@ sys_ioctl(struct proc *p, void *v, register_t *retval)
                if (tmp <= 0) {
                        tmp = -tmp;
                } else {
-                       struct proc *p1 = pfind(tmp);
-                       if (p1 == 0) {
+                       struct process *pr = prfind(tmp);
+                       if (pr == NULL) {
                                error = ESRCH;
                                break;
                        }
-                       tmp = p1->p_pgrp->pg_id;
+                       tmp = pr->ps_pgrp->pg_id;
                }
                error = (*fp->f_ops->fo_ioctl)
                        (fp, TIOCSPGRP, (caddr_t)&tmp, p);
index d3944c4..e38e673 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_process.c,v 1.46 2010/06/26 23:24:45 guenther Exp $       */
+/*     $OpenBSD: sys_process.c,v 1.47 2010/07/26 01:56:27 guenther Exp $       */
 /*     $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $     */
 
 /*-
@@ -172,7 +172,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
                 *          not init (because that would create a loop in
                 *          the process graph).
                 */
-               if (t->p_pid != 1 && inferior(p, t))
+               if (t->p_pid != 1 && inferior(p->p_p, t->p_p))
                        return (EINVAL);
                break;
 
@@ -217,7 +217,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
                /*
                 *      (2) it's not being traced by _you_, or
                 */
-               if (t->p_pptr != p)
+               if (t->p_p->ps_pptr != p->p_p)
                        return (EBUSY);
 
                /*
@@ -242,7 +242,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
        case  PT_TRACE_ME:
                /* Just set the trace flag. */
                atomic_setbits_int(&t->p_flag, P_TRACED);
-               t->p_oppid = t->p_pptr->p_pid;
+               t->p_oppid = t->p_p->ps_pptr->ps_pid;
                if (t->p_ptstat == NULL)
                        t->p_ptstat = malloc(sizeof(*t->p_ptstat),
                            M_SUBPROC, M_WAITOK);
@@ -387,11 +387,11 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
 #endif
 
                /* give process back to original parent or init */
-               if (t->p_oppid != t->p_pptr->p_pid) {
-                       struct proc *pp;
+               if (t->p_oppid != t->p_p->ps_pptr->ps_pid) {
+                       struct process *ppr;
 
-                       pp = pfind(t->p_oppid);
-                       proc_reparent(t, pp ? pp : initproc);
+                       ppr = prfind(t->p_oppid);
+                       proc_reparent(t->p_p, ppr ? ppr : initproc->p_p);
                }
 
                /* not being traced any more */
@@ -432,9 +432,9 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
                 * Stop the target.
                 */
                atomic_setbits_int(&t->p_flag, P_TRACED);
-               t->p_oppid = t->p_pptr->p_pid;
-               if (t->p_pptr != p)
-                       proc_reparent(tp);
+               t->p_oppid = t->p_p->ps_pptr->ps_pid;
+               if (t->p_p->ps_pptr != p->p_p)
+                       proc_reparent(t->p_p, p->p_p);
                if (t->p_ptstat == NULL)
                        t->p_ptstat = malloc(sizeof(*t->p_ptstat),
                            M_SUBPROC, M_WAITOK);
index d946e0d..c8120bf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tty.c,v 1.87 2010/07/02 17:27:01 nicm Exp $   */
+/*     $OpenBSD: tty.c,v 1.88 2010/07/26 01:56:27 guenther Exp $       */
 /*     $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $     */
 
 /*-
@@ -719,6 +719,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
 {
        extern struct tty *constty;     /* Temporary virtual console. */
        extern int nlinesw;
+       struct process *pr = p->p_p;
        int s, error;
 
        /* If the ioctl involves modification, hang if in the background. */
@@ -747,13 +748,13 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
        case  TIOCSETP:
        case  TIOCSLTC:
 #endif
-               while (isbackground(p, tp) &&
+               while (isbackground(pr, tp) &&
                    (p->p_flag & P_PPWAIT) == 0 &&
                    (p->p_sigignore & sigmask(SIGTTOU)) == 0 &&
                    (p->p_sigmask & sigmask(SIGTTOU)) == 0) {
-                       if (p->p_pgrp->pg_jobc == 0)
+                       if (pr->ps_pgrp->pg_jobc == 0)
                                return (EIO);
-                       pgsignal(p->p_pgrp, SIGTTOU, 1);
+                       pgsignal(pr->ps_pgrp, SIGTTOU, 1);
                        error = ttysleep(tp, &lbolt, TTOPRI | PCATCH,
                            ttybg, 0);
                        if (error)
@@ -841,7 +842,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
                splx(s);
                break;
        case TIOCGPGRP:                 /* get pgrp of tty */
-               if (!isctty(p, tp) && suser(p, 0))
+               if (!isctty(pr, tp) && suser(p, 0))
                        return (ENOTTY);
                *(int *)data = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
                break;
@@ -901,7 +902,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
                                tp->t_ospeed = t->c_ospeed;
                                if (t->c_ospeed == 0 && tp->t_session &&
                                    tp->t_session->s_leader)
-                                       psignal(tp->t_session->s_leader,
+                                       prsignal(tp->t_session->s_leader,
                                            SIGHUP);
                        }
                        ttsetwater(tp);
@@ -970,7 +971,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
        case TIOCSTI:                   /* simulate terminal input */
                if (p->p_ucred->cr_uid && (flag & FREAD) == 0)
                        return (EPERM);
-               if (p->p_ucred->cr_uid && !isctty(p, tp))
+               if (p->p_ucred->cr_uid && !isctty(pr, tp))
                        return (EACCES);
                (*linesw[tp->t_line].l_rint)(*(u_char *)data, tp);
                break;
@@ -984,26 +985,26 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
                break;
        case TIOCSCTTY:                 /* become controlling tty */
                /* Session ctty vnode pointer set in vnode layer. */
-               if (!SESS_LEADER(p) ||
-                   ((p->p_session->s_ttyvp || tp->t_session) &&
-                    (tp->t_session != p->p_session)))
+               if (!SESS_LEADER(pr) ||
+                   ((pr->ps_session->s_ttyvp || tp->t_session) &&
+                    (tp->t_session != pr->ps_session)))
                        return (EPERM);
                if (tp->t_session)
                        SESSRELE(tp->t_session);
-               SESSHOLD(p->p_session);
-               tp->t_session = p->p_session;
-               tp->t_pgrp = p->p_pgrp;
-               p->p_session->s_ttyp = tp;
-               atomic_setbits_int(&p->p_flag, P_CONTROLT);
+               SESSHOLD(pr->ps_session);
+               tp->t_session = pr->ps_session;
+               tp->t_pgrp = pr->ps_pgrp;
+               pr->ps_session->s_ttyp = tp;
+               atomic_setbits_int(&pr->ps_flags, PS_CONTROLT);
                break;
        case TIOCSPGRP: {               /* set pgrp of tty */
                struct pgrp *pgrp = pgfind(*(int *)data);
 
-               if (!isctty(p, tp))
+               if (!isctty(pr, tp))
                        return (ENOTTY);
                else if (pgrp == NULL)
                        return (EINVAL);
-               else if (pgrp->pg_session != p->p_session)
+               else if (pgrp->pg_session != pr->ps_session)
                        return (EPERM);
                tp->t_pgrp = pgrp;
                break;
@@ -1363,7 +1364,7 @@ ttymodem(struct tty *tp, int flag)
                if (ISSET(tp->t_state, TS_ISOPEN) &&
                    !ISSET(tp->t_cflag, CLOCAL)) {
                        if (tp->t_session && tp->t_session->s_leader)
-                               psignal(tp->t_session->s_leader, SIGHUP);
+                               prsignal(tp->t_session->s_leader, SIGHUP);
                        ttyflush(tp, FREAD | FWRITE);
                        return (0);
                }
@@ -1392,7 +1393,7 @@ nullmodem(struct tty *tp, int flag)
                if (ISSET(tp->t_state, TS_ISOPEN) &&
                    !ISSET(tp->t_cflag, CLOCAL)) {
                        if (tp->t_session && tp->t_session->s_leader)
-                               psignal(tp->t_session->s_leader, SIGHUP);
+                               prsignal(tp->t_session->s_leader, SIGHUP);
                        ttyflush(tp, FREAD | FWRITE);
                        return (0);
                }
@@ -1440,6 +1441,7 @@ ttread(struct tty *tp, struct uio *uio, int flag)
 {
        struct timeout *stime = NULL;
        struct proc *p = curproc;
+       struct process *pr = p->p_p;
        int s, first, error = 0;
        u_char *cc = tp->t_cc;
        struct clist *qp;
@@ -1459,14 +1461,14 @@ loop:   lflag = tp->t_lflag;
        /*
         * Hang process if it's in the background.
         */
-       if (isbackground(p, tp)) {
+       if (isbackground(pr, tp)) {
                if ((p->p_sigignore & sigmask(SIGTTIN)) ||
                   (p->p_sigmask & sigmask(SIGTTIN)) ||
-                   p->p_flag & P_PPWAIT || p->p_pgrp->pg_jobc == 0) {
+                   p->p_flag & P_PPWAIT || pr->ps_pgrp->pg_jobc == 0) {
                        error = EIO;
                        goto out;
                }
-               pgsignal(p->p_pgrp, SIGTTIN, 1);
+               pgsignal(pr->ps_pgrp, SIGTTIN, 1);
                error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0);
                if (error)
                        goto out;
@@ -1678,6 +1680,7 @@ ttwrite(struct tty *tp, struct uio *uio, int flag)
        u_char *cp = NULL;
        int cc, ce, obufcc = 0;
        struct proc *p;
+       struct process *pr;
        int i, hiwat, error, s;
        size_t cnt;
        u_char obuf[OBUFSIZ];
@@ -1713,15 +1716,16 @@ loop:
         * Hang the process if it's in the background.
         */
        p = curproc;
-       if (isbackground(p, tp) &&
+       pr = p->p_p;
+       if (isbackground(pr, tp) &&
            ISSET(tp->t_lflag, TOSTOP) && (p->p_flag & P_PPWAIT) == 0 &&
            (p->p_sigignore & sigmask(SIGTTOU)) == 0 &&
            (p->p_sigmask & sigmask(SIGTTOU)) == 0) {
-               if (p->p_pgrp->pg_jobc == 0) {
+               if (pr->ps_pgrp->pg_jobc == 0) {
                        error = EIO;
                        goto out;
                }
-               pgsignal(p->p_pgrp, SIGTTOU, 1);
+               pgsignal(pr->ps_pgrp, SIGTTOU, 1);
                error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0);
                if (error)
                        goto out;
@@ -2079,7 +2083,8 @@ ttsetwater(struct tty *tp)
 void
 ttyinfo(struct tty *tp)
 {
-       struct proc *p, *pick;
+       struct process *pr;
+       struct proc *pick;
        struct timeval utime, stime;
        int tmp;
 
@@ -2094,16 +2099,16 @@ ttyinfo(struct tty *tp)
                ttyprintf(tp, "not a controlling terminal\n");
        else if (tp->t_pgrp == NULL)
                ttyprintf(tp, "no foreground process group\n");
-       else if ((p = LIST_FIRST(&tp->t_pgrp->pg_members)) == NULL)
+       else if ((pr = LIST_FIRST(&tp->t_pgrp->pg_members)) == NULL)
                ttyprintf(tp, "empty foreground process group\n");
        else {
                int pctcpu;
                long rss;
 
                /* Pick interesting process. */
-               for (pick = NULL; p != 0; p = LIST_NEXT(p, p_pglist))
-                       if (proc_compare(pick, p))
-                               pick = p;
+               for (pick = NULL; pr != NULL; pr = LIST_NEXT(pr, ps_pglist))
+                       if (proc_compare(pick, pr->ps_mainproc))
+                               pick = pr->ps_mainproc;
 
                /* Calculate percentage cpu, resident set size. */
                pctcpu = (pick->p_pctcpu * 10000 + FSCALE / 2) >> FSHIFT;
index 810ddff..5ea88c1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tty_pty.c,v 1.49 2010/07/21 18:48:01 nicm Exp $       */
+/*     $OpenBSD: tty_pty.c,v 1.50 2010/07/26 01:56:27 guenther Exp $   */
 /*     $NetBSD: tty_pty.c,v 1.33.4.1 1996/06/02 09:08:11 mrg Exp $     */
 
 /*
@@ -283,19 +283,20 @@ int
 ptsread(dev_t dev, struct uio *uio, int flag)
 {
        struct proc *p = curproc;
+       struct process *pr = p->p_p;
        struct pt_softc *pti = pt_softc[minor(dev)];
        struct tty *tp = pti->pt_tty;
        int error = 0;
 
 again:
        if (pti->pt_flags & PF_REMOTE) {
-               while (isbackground(p, tp)) {
+               while (isbackground(pr, tp)) {
                        if ((p->p_sigignore & sigmask(SIGTTIN)) ||
                            (p->p_sigmask & sigmask(SIGTTIN)) ||
-                           p->p_pgrp->pg_jobc == 0 ||
+                           pr->ps_pgrp->pg_jobc == 0 ||
                            p->p_flag & P_PPWAIT)
                                return (EIO);
-                       pgsignal(p->p_pgrp, SIGTTIN, 1);
+                       pgsignal(pr->ps_pgrp, SIGTTIN, 1);
                        error = ttysleep(tp, &lbolt,
                            TTIPRI | PCATCH, ttybg, 0);
                        if (error)
index e2a4b4a..2a410b1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tty_tty.c,v 1.10 2007/03/15 10:22:30 art Exp $        */
+/*     $OpenBSD: tty_tty.c,v 1.11 2010/07/26 01:56:27 guenther Exp $   */
 /*     $NetBSD: tty_tty.c,v 1.13 1996/03/30 22:24:46 christos Exp $    */
 
 /*-
@@ -45,7 +45,9 @@
 #include <sys/conf.h>
 
 
-#define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL)
+#define cttyvp(p) \
+       ((p)->p_p->ps_flags & PS_CONTROLT ? \
+           (p)->p_p->ps_session->s_ttyvp : NULL)
 
 /*ARGSUSED*/
 int
@@ -118,8 +120,8 @@ cttyioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
        if (cmd == TIOCSCTTY)           /* XXX */
                return (EINVAL);
        if (cmd == TIOCNOTTY) {
-               if (!SESS_LEADER(p)) {
-                       atomic_clearbits_int(&p->p_flag, P_CONTROLT);
+               if (!SESS_LEADER(p->p_p)) {
+                       atomic_clearbits_int(&p->p_p->ps_flags, PS_CONTROLT);
                        return (0);
                } else
                        return (EINVAL);
index f6f5e28..d92dd34 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vfs_vnops.c,v 1.64 2010/01/08 19:18:21 stsp Exp $     */
+/*     $OpenBSD: vfs_vnops.c,v 1.65 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $  */
 
 /*
@@ -435,9 +435,10 @@ vn_ioctl(struct file *fp, u_long com, caddr_t data, struct proc *p)
        case VBLK:
                error = VOP_IOCTL(vp, com, data, fp->f_flag, p->p_ucred, p);
                if (error == 0 && com == TIOCSCTTY) {
-                       if (p->p_session->s_ttyvp)
-                               vrele(p->p_session->s_ttyvp);
-                       p->p_session->s_ttyvp = vp;
+                       struct session *s = p->p_p->ps_session;
+                       if (s->s_ttyvp)
+                               vrele(s->s_ttyvp);
+                       s->s_ttyvp = vp;
                        vref(vp);
                }
                return (error);
index b2d5a1c..0fed64e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: procfs_ctl.c,v 1.21 2007/06/18 08:30:07 jasper Exp $  */
+/*     $OpenBSD: procfs_ctl.c,v 1.22 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: procfs_ctl.c,v 1.14 1996/02/09 22:40:48 christos Exp $ */
 
 /*
@@ -57,7 +57,7 @@
  */
 #define TRACE_WAIT_P(curp, p) \
        ((p)->p_stat == SSTOP && \
-        (p)->p_pptr == (curp) && \
+        (p)->p_p->ps_pptr == (curp)->p_p && \
         ISSET((p)->p_flag, P_TRACED))
 
 #ifdef PTRACE
@@ -137,9 +137,9 @@ procfs_control(struct proc *curp, struct proc *p, int op)
                 */
                atomic_setbits_int(&p->p_flag, P_TRACED);
                p->p_xstat = 0;         /* XXX ? */
-               if (p->p_pptr != curp) {
-                       p->p_oppid = p->p_pptr->p_pid;
-                       proc_reparent(p, curp);
+               if (p->p_p->ps_pptr != curp->p_p) {
+                       p->p_oppid = p->p_p->ps_pptr->ps_pid;
+                       proc_reparent(p->p_p, curp->p_p);
                }
                psignal(p, SIGSTOP);
                return (0);
@@ -187,12 +187,12 @@ procfs_control(struct proc *curp, struct proc *p, int op)
                atomic_clearbits_int(&p->p_flag, P_TRACED);
 
                /* give process back to original parent */
-               if (p->p_oppid != p->p_pptr->p_pid) {
-                       struct proc *pp;
+               if (p->p_oppid != p->p_p->ps_pptr->ps_pid) {
+                       struct process *ppr;
 
-                       pp = pfind(p->p_oppid);
-                       if (pp)
-                               proc_reparent(p, pp);
+                       ppr = prfind(p->p_oppid);
+                       if (ppr)
+                               proc_reparent(p->p_p, ppr);
                }
 
                p->p_oppid = 0;
@@ -232,7 +232,7 @@ procfs_control(struct proc *curp, struct proc *p, int op)
                        while (error == 0 &&
                                        (p->p_stat != SSTOP) &&
                                        ISSET(p->p_flag, P_TRACED) &&
-                                       (p->p_pptr == curp)) {
+                                       (p->p_p->ps_pptr == curp->p_p)) {
                                error = tsleep(p, PWAIT|PCATCH, "procfsx", 0);
                        }
                        if (error == 0 && !TRACE_WAIT_P(curp, p))
index 0a6fbb4..0a629e9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: procfs_status.c,v 1.10 2007/06/18 08:30:07 jasper Exp $       */
+/*     $OpenBSD: procfs_status.c,v 1.11 2010/07/26 01:56:27 guenther Exp $     */
 /*     $NetBSD: procfs_status.c,v 1.11 1996/03/16 23:52:50 christos Exp $      */
 
 /*
@@ -64,6 +64,7 @@ int   procfs_stat_gen(struct proc *, char *s, int);
 int
 procfs_stat_gen(struct proc *p, char *s, int l)
 {
+       struct process *pr = p->p_p;
        struct session *sess;
        struct tty *tp;
        struct ucred *cr;
@@ -72,11 +73,11 @@ procfs_stat_gen(struct proc *p, char *s, int l)
        char ps[256], *sep;
        int i, n;
 
-       pid = p->p_pid;
-       ppid = p->p_pptr ? p->p_pptr->p_pid : 0;
-       pgid = p->p_pgrp->pg_id;
-       sess = p->p_pgrp->pg_session;
-       sid = sess->s_leader ? sess->s_leader->p_pid : 0;
+       pid = pr->ps_pid;
+       ppid = pr->ps_pptr ? pr->ps_pptr->ps_pid : 0;
+       pgid = pr->ps_pgrp->pg_id;
+       sess = pr->ps_pgrp->pg_session;
+       sid = sess->s_leader ? sess->s_leader->ps_pid : 0;
 
        n = 0;
        if (s)
@@ -90,7 +91,7 @@ procfs_stat_gen(struct proc *p, char *s, int l)
            pid, ppid, pgid, sid);
        COUNTORCAT(s, l, ps, n);
 
-       if ((p->p_flag&P_CONTROLT) && (tp = sess->s_ttyp))
+       if ((pr->ps_flags & PS_CONTROLT) && (tp = sess->s_ttyp))
                snprintf(ps, sizeof(ps), "%d,%d ",
                    major(tp->t_dev), minor(tp->t_dev));
        else
@@ -105,7 +106,7 @@ procfs_stat_gen(struct proc *p, char *s, int l)
                COUNTORCAT(s, l, ps, n);
        }
 
-       if (SESS_LEADER(p)) {
+       if (SESS_LEADER(pr)) {
                snprintf(ps, sizeof(ps), "%ssldr", sep);
                sep = ",";
                COUNTORCAT(s, l, ps, n);
index c1816c5..11fde4c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: spec_vnops.c,v 1.57 2010/05/18 04:41:14 dlg Exp $     */
+/*     $OpenBSD: spec_vnops.c,v 1.58 2010/07/26 01:56:27 guenther Exp $        */
 /*     $NetBSD: spec_vnops.c,v 1.29 1996/04/22 01:42:38 christos Exp $ */
 
 /*
@@ -500,9 +500,9 @@ spec_close(void *v)
                 * plus the session), release the reference from the session.
                 */
                if (vcount(vp) == 2 && ap->a_p &&
-                   vp == ap->a_p->p_session->s_ttyvp) {
+                   vp == ap->a_p->p_p->ps_session->s_ttyvp) {
                        vrele(vp);
-                       ap->a_p->p_session->s_ttyvp = NULL;
+                       ap->a_p->p_p->ps_session->s_ttyvp = NULL;
                }
                if (cdevsw[major(dev)].d_flags & D_CLONE)
                        return (spec_close_clone(ap));
index 3e857da..b04820e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: proc.h,v 1.131 2010/07/19 23:00:15 guenther Exp $     */
+/*     $OpenBSD: proc.h,v 1.132 2010/07/26 01:56:27 guenther Exp $     */
 /*     $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $       */
 
 /*-
@@ -41,9 +41,9 @@
 #define        _SYS_PROC_H_
 
 #include <machine/proc.h>              /* Machine-dependent proc substruct. */
-#include <sys/selinfo.h>                       /* For struct selinfo. */
+#include <sys/selinfo.h>               /* For struct selinfo */
 #include <sys/queue.h>
-#include <sys/timeout.h>               /* For struct timeout. */
+#include <sys/timeout.h>               /* For struct timeout */
 #include <sys/event.h>                 /* For struct klist */
 #include <sys/mutex.h>                 /* For struct mutex */
 #include <machine/atomic.h>
 /*
  * One structure allocated per session.
  */
+struct process;
 struct session {
        int     s_count;                /* Ref cnt; pgrps in session. */
-       struct  proc *s_leader;         /* Session leader. */
+       struct  process *s_leader;      /* Session leader. */
        struct  vnode *s_ttyvp;         /* Vnode of controlling terminal. */
        struct  tty *s_ttyp;            /* Controlling terminal. */
        char    s_login[MAXLOGNAME];    /* Setlogin() name. */
@@ -68,7 +69,7 @@ struct        session {
  */
 struct pgrp {
        LIST_ENTRY(pgrp) pg_hash;       /* Hash chain. */
-       LIST_HEAD(, proc) pg_members;   /* Pointer to pgrp members. */
+       LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */
        struct  session *pg_session;    /* Pointer to session. */
        pid_t   pg_id;                  /* Pgrp id. */
        int     pg_jobc;        /* # procs qualifying pgrp for job control */
@@ -78,6 +79,7 @@ struct        pgrp {
  * One structure allocated per emulation.
  */
 struct exec_package;
+struct proc;
 struct ps_strings;
 struct uvm_object;
 union sigval;
@@ -138,14 +140,20 @@ struct process {
         * the pid of the process. This is gross, but considering the horrible
         * pid semantics we have right now, it's unavoidable.
         */
-       struct proc *ps_mainproc;
+       struct  proc *ps_mainproc;
        struct  pcred *ps_cred;         /* Process owner's identity. */
 
        TAILQ_HEAD(,proc) ps_threads;   /* Threads in this process. */
 
+       LIST_ENTRY(process) ps_pglist;  /* List of processes in pgrp. */
+       struct  process *ps_pptr;       /* Pointer to parent process. */
+       LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */
+       LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
+
 /* The following fields are all zeroed upon creation in process_new. */
 #define        ps_startzero    ps_klist
        struct  klist ps_klist;         /* knotes attached to this process */
+       int     ps_flags;               /* PS_* flags. */
 
 /* End area that is zeroed on creation. */
 #define        ps_endzero      ps_startcopy
@@ -154,6 +162,7 @@ struct process {
 #define        ps_startcopy    ps_limit
 
        struct  plimit *ps_limit;       /* Process limits. */
+       struct  pgrp *ps_pgrp;          /* Pointer to process group. */
        u_int   ps_rtableid;            /* Process routing table/domain. */
 
 /* End area that is copied on creation. */
@@ -161,9 +170,35 @@ struct process {
 
        int     ps_refcnt;              /* Number of references. */
 };
-#else
-struct process;
-#endif
+
+#define        ps_pid          ps_mainproc->p_pid
+#define        ps_session      ps_pgrp->pg_session
+#define        ps_pgid         ps_pgrp->pg_id
+
+/*
+ * These flags are kept in ps_flags, but they used to be in proc's p_flag
+ * and were exported to userspace via the KERN_PROC2 sysctl.  We'll retain
+ * compat by using non-overlapping bits for PS_* and P_* flags and just
+ * OR them together for export.
+ */
+#define        PS_CONTROLT     _P_CONTROLT
+#define        PS_NOCLDSTOP    _P_NOCLDSTOP
+#define        PS_PPWAIT       _P_PPWAIT
+#define        PS_PROFIL       _P_PROFIL
+#define        PS_SUGID        _P_SUGID
+#define        PS_SYSTEM       _P_SYSTEM
+#define        PS_TRACED       _P_TRACED
+#define        PS_WAITED       _P_WAITED
+#define        PS_EXEC         _P_EXEC
+#define        PS_SUGIDEXEC    _P_SUGIDEXEC
+#define        PS_NOCLDWAIT    _P_NOCLDWAIT
+#define        PS_NOZOMBIE     _P_NOZOMBIE
+#define        PS_INEXEC       _P_INEXEC
+#define        PS_SYSTRACE     _P_SYSTRACE
+#define        PS_CONTINUED    _P_CONTINUED
+#define        PS_STOPPED      _P_STOPPED
+
+#endif /* __need_process */
 
 struct proc {
        TAILQ_ENTRY(proc) p_runq;
@@ -190,10 +225,6 @@ struct proc {
 
        pid_t   p_pid;                  /* Process identifier. */
        LIST_ENTRY(proc) p_hash;        /* Hash chain. */
-       LIST_ENTRY(proc) p_pglist;      /* List of processes in pgrp. */
-       struct  proc *p_pptr;           /* Pointer to parent process. */
-       LIST_ENTRY(proc) p_sibling;     /* List of sibling processes. */
-       LIST_HEAD(, proc) p_children;   /* Pointer to list of children. */
 
 /* The following fields are all zeroed upon creation in fork. */
 #define        p_startzero     p_oppid
@@ -256,7 +287,6 @@ struct proc {
        char    p_comm[MAXCOMLEN+1];
 
        struct  emul *p_emul;           /* Emulation information */
-       struct  pgrp *p_pgrp;   /* Pointer to process group. */
        vaddr_t p_sigcode;      /* user pointer to the signal code. */
 
 /* End area that is copied on creation. */
@@ -270,9 +300,6 @@ struct proc {
        struct  rusage *p_ru;   /* Exit information. XXX */
 };
 
-#define        p_session       p_pgrp->pg_session
-#define        p_pgid          p_pgrp->pg_id
-
 /* Status values. */
 #define        SIDL    1               /* Process being created by fork. */
 #define        SRUN    2               /* Currently runnable. */
@@ -284,8 +311,11 @@ struct proc {
 
 #define P_ZOMBIE(p)    ((p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
 
-/* These flags are kept in p_flag. */
-#define        P_CONTROLT      0x000002        /* Has a controlling terminal. */
+/*
+ * These flags are kept in p_flag, except those with a leading underbar,
+ * which are in process's ps_flags
+ */
+#define        _P_CONTROLT     0x000002        /* Has a controlling terminal. */
 #define        P_INMEM         0x000004        /* Loaded into memory. UNUSED */
 #define        P_NOCLDSTOP     0x000008        /* No SIGCHLD when children stop. */
 #define        P_PPWAIT        0x000010        /* Parent waits for child exec/exit. */
@@ -320,6 +350,10 @@ struct proc {
 #define P_STOPPED      0x20000000      /* Just stopped. */
 #define P_CPUPEG       0x40000000      /* Do not move to another cpu. */
 
+#ifndef _KERNEL
+#define        P_CONTROLT      _P_CONTROLT
+#endif
+
 #define        P_BITS \
     ("\20\02CONTROLT\03INMEM\04NOCLDSTOP\05PPWAIT\06PROFIL\07SELECT" \
      "\010SINTR\011SUGID\012SYSTEM\013TIMEOUT\014TRACED\015WAITED\016WEXIT" \
@@ -366,7 +400,7 @@ struct uidinfo *uid_find(uid_t);
 #define        NO_PID          (PID_MAX+1)
 #define        THREAD_PID_OFFSET       1000000
 
-#define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
+#define SESS_LEADER(pr)        ((pr)->ps_session->s_leader == (pr))
 #define        SESSHOLD(s)     ((s)->s_count++)
 #define        SESSRELE(s) do {                                                \
        if (--(s)->s_count == 0)                                        \
@@ -420,19 +454,19 @@ extern struct pool pcred_pool;            /* memory pool for pcreds */
 
 struct simplelock;
 
-struct proc *pfind(pid_t);     /* Find process by id. */
+struct process *prfind(pid_t); /* Find process by id. */
+struct proc *pfind(pid_t);     /* Find thread by id. */
 struct pgrp *pgfind(pid_t);    /* Find process group by id. */
 void   proc_printit(struct proc *p, const char *modif,
     int (*pr)(const char *, ...));
 
 int    chgproccnt(uid_t uid, int diff);
-int    enterpgrp(struct proc *p, pid_t pgid, struct pgrp *newpgrp,
-           struct session *newsess);
-void   fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
-int    inferior(struct proc *, struct proc *);
-int    leavepgrp(struct proc *p);
+int    enterpgrp(struct process *, pid_t, struct pgrp *, struct session *);
+void   fixjobc(struct process *, struct pgrp *, int);
+int    inferior(struct process *, struct process *);
+void   leavepgrp(struct process *);
 void   preempt(struct proc *);
-void   pgdelete(struct pgrp *pgrp);
+void   pgdelete(struct pgrp *);
 void   procinit(void);
 void   resetpriority(struct proc *);
 void   setrunnable(struct proc *);
index 78599a2..4baebcd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ptrace.h,v 1.11 2008/09/16 19:41:06 kettenis Exp $    */
+/*     $OpenBSD: ptrace.h,v 1.12 2010/07/26 01:56:27 guenther Exp $    */
 /*     $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $     */
 
 /*-
@@ -96,7 +96,7 @@ struct reg;
 struct fpreg;
 #endif
 
-void   proc_reparent(struct proc *child, struct proc *newparent);
+void   proc_reparent(struct process *child, struct process *newparent);
 #ifdef PT_GETFPREGS
 int    process_read_fpregs(struct proc *p, struct fpreg *regs);
 #endif
index 46577ee..0e112a8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: resource.h,v 1.7 2003/12/11 23:02:30 millert Exp $    */
+/*     $OpenBSD: resource.h,v 1.8 2010/07/26 01:56:27 guenther Exp $   */
 /*     $NetBSD: resource.h,v 1.14 1996/02/09 18:25:27 christos Exp $   */
 
 /*
@@ -51,6 +51,7 @@
 
 #define        RUSAGE_SELF     0
 #define        RUSAGE_CHILDREN -1
+#define        RUSAGE_THREAD   1
 
 struct rusage {
        struct timeval ru_utime;        /* user time used */
@@ -110,8 +111,9 @@ struct loadavg {
 
 #ifdef _KERNEL
 extern struct loadavg averunnable;
+struct process;
 int    dosetrlimit(struct proc *, u_int, struct rlimit *);
-int    donice(struct proc *, struct proc *, int);
+int    donice(struct proc *, struct process *, int);
 
 #else
 #include <sys/cdefs.h>
index 5fa4ef6..27b2293 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: signalvar.h,v 1.18 2009/11/27 19:47:45 guenther Exp $ */
+/*     $OpenBSD: signalvar.h,v 1.19 2010/07/26 01:56:27 guenther Exp $ */
 /*     $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $  */
 
 /*
@@ -164,6 +164,7 @@ void        pgsignal(struct pgrp *pgrp, int sig, int checkctty);
 void   postsig(int sig);
 void   psignal(struct proc *p, int sig);
 void   ptsignal(struct proc *p, int sig, enum signal_type type);
+#define prsignal(pr,sig)       ptsignal((pr)->ps_mainproc, (sig), SPROCESS)
 void   siginit(struct proc *p);
 void   trapsignal(struct proc *p, int sig, u_long code, int type,
            union sigval val);
index 14c23d1..4eec998 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sysctl.h,v 1.104 2010/06/29 00:28:14 tedu Exp $       */
+/*     $OpenBSD: sysctl.h,v 1.105 2010/07/26 01:56:27 guenther Exp $   */
 /*     $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $  */
 
 /*
@@ -499,7 +499,7 @@ struct kinfo_proc2 {
 
 #define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
 
-#define FILL_KPROC2(kp, copy_str, p, pr, pc, uc, pg, paddr, sess, vm, lim, ps) \
+#define FILL_KPROC2(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, ps) \
 do {                                                                   \
        memset((kp), 0, sizeof(*(kp)));                                 \
                                                                        \
@@ -509,11 +509,11 @@ do {                                                                      \
        (kp)->p_limit = PTRTOINT64((pr)->ps_limit);                     \
        (kp)->p_vmspace = PTRTOINT64((p)->p_vmspace);                   \
        (kp)->p_sigacts = PTRTOINT64((p)->p_sigacts);                   \
-       (kp)->p_sess = PTRTOINT64((p)->p_session);                      \
+       (kp)->p_sess = PTRTOINT64((pr)->ps_session);                    \
        (kp)->p_ru = PTRTOINT64((p)->p_ru);                             \
                                                                        \
        (kp)->p_exitsig = (p)->p_exitsig;                               \
-       (kp)->p_flag = (p)->p_flag | P_INMEM;                           \
+       (kp)->p_flag = (p)->p_flag | (pr)->ps_flags | P_INMEM;          \
                                                                        \
        (kp)->p_pid = (p)->p_pid;                                       \
        (kp)->p__pgid = (pg)->pg_id;                                    \
@@ -564,7 +564,7 @@ do {                                                                        \
                                                                        \
        if ((sess)->s_ttyvp)                                            \
                (kp)->p_eflag |= EPROC_CTTY;                            \
-       if ((sess)->s_leader == (paddr))                                \
+       if ((sess)->s_leader == (praddr))                               \
                (kp)->p_eflag |= EPROC_SLEADER;                         \
                                                                        \
        if ((p)->p_stat != SIDL && !P_ZOMBIE(p)) {                      \
index d288a68..4ddc153 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tty.h,v 1.28 2010/07/02 19:57:15 tedu Exp $   */
+/*     $OpenBSD: tty.h,v 1.29 2010/07/26 01:56:27 guenther Exp $       */
 /*     $NetBSD: tty.h,v 1.30.4.1 1996/06/02 09:08:13 mrg Exp $ */
 
 /*-
@@ -228,13 +228,13 @@ struct speedtab {
 #define        TTY_FE          0x01000000      /* Framing error or BREAK condition */
 #define        TTY_PE          0x02000000      /* Parity error */
 
-/* Is tp controlling terminal for p? */
-#define        isctty(p, tp)                                                   \
-       ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
+/* Is tp controlling terminal for pr? */
+#define        isctty(pr, tp)                                                  \
+       ((pr)->ps_session == (tp)->t_session && (pr)->ps_flags & PS_CONTROLT)
 
-/* Is p in background of tp? */
-#define        isbackground(p, tp)                                             \
-       (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
+/* Is pr in background of tp? */
+#define        isbackground(pr, tp)                                            \
+       (isctty((pr), (tp)) && (pr)->ps_pgrp != (tp)->t_pgrp)
 
 /*
  * ttylist_head is defined here so that user-land has access to it.
index c05b348..e6e2676 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uio.h,v 1.14 2009/06/04 00:24:01 blambert Exp $       */
+/*     $OpenBSD: uio.h,v 1.15 2010/07/26 01:56:27 guenther Exp $       */
 /*     $NetBSD: uio.h,v 1.12 1996/02/09 18:25:45 christos Exp $        */
 
 /*
@@ -56,7 +56,7 @@ struct uio {
        size_t  uio_resid;      /* residual i/o count */
        enum    uio_seg uio_segflg; /* see above */
        enum    uio_rw uio_rw;  /* see above */
-       struct  proc *uio_procp;/* associated process or NULL */
+       struct  proc *uio_procp;/* associated thread or NULL */
 };
 
 /*