-/* $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.
* 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;
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);
} 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,
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;
-/* $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.
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;
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)) {
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;
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
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;
#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);
-/* $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 $ */
/*-
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:
-/* $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 $ */
/*
* 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;
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;
-/* $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 $ */
/*-
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;
}
-/* $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 $ */
/*
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;
-/* $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 $ */
/*
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);
}
-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;
}
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() */
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() */
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); */
struct svr4_sys_waitsys_args *uap = v;
int nfound;
int error;
+ struct process *pr;
struct proc *p;
switch (SCARG(uap, grp)) {
break;
case SVR4_P_PGID:
- SCARG(uap, id) = -q->p_pgid;
+ SCARG(uap, id) = -q->p_p->ps_pgid;
break;
case SVR4_P_ALL:
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++;
-/* $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.
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
-/* $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 $ */
/*
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;
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);
}
}
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;
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;
-/* $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 $ */
/*
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 */
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 *);
-/* $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 $ */
/*
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) {
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);
}
-/* $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 $ */
/*
evar = &sc->sc_base.me_evar;
wsevent_init(evar);
- evar->io = p;
+ evar->io = p->p_p;
error = wsmousedoopen(sc, evar);
if (error) {
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);
}
-/* $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 $ */
/*
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
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:
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:
-/* $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
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;
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;
* 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, ¬esize);
-/* $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 $ */
/*
main(void *framep)
{
struct proc *p;
+ struct process *pr;
struct pdevinit *pdev;
struct timeval rtv;
quad_t lim;
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;
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;
-/* $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 $ */
/*-
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;
-/* $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 $ */
/*
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));
-/* $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 $ */
/*-
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);
}
/*
-/* $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 $ */
/*
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);
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);
*/
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
/*
* 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);
+ }
}
}
*/
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);
+ }
}
/*
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);
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;
/*
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;
}
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;
* 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)
* 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.
* 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);
pool_put(&proc_pool, p);
nprocs--;
}
-
-/* $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 $ */
/*
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,
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;
}
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
/*
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.
/*
* 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.
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);
}
-/* $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 $ */
/*
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 *);
} */ *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));
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;
}
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*/
-/* $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 $ */
/*
}
/*
- * Change the count associated with number of processes
+ * Change the count associated with number of threads
* a given user is using.
*/
int
* 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)
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
*/
* 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);
#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);
* 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;
}
/*
* 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++;
* 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)
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;
}
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
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);
{
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 */
}
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 ? '*' : ' ',
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;
pgrpdump(void)
{
struct pgrp *pgrp;
- struct proc *p;
+ struct process *pr;
int i;
for (i = 0; i <= pgrphash; i++) {
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);
}
}
}
-/* $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 $ */
/*
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);
}
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);
}
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);
}
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);
}
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);
}
{
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);
}
}
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;
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);
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)));
}
/*
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);
-/* $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 $ */
/*-
syscallarg(int) which;
syscallarg(id_t) who;
} */ *uap = v;
+ struct process *pr;
struct proc *p;
int low = NZERO + PRIO_MAX + 1;
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;
}
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;
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);
}
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);
}
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:
-/* $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 $ */
/*
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 */
/*
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;
/*
* 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;
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
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;
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);
}
}
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);
}
/*
* 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;
}
}
out:
SCHED_UNLOCK(s);
if (wakeparent)
- wakeup(p->p_pptr);
+ wakeup(p->p_p->ps_pptr);
}
/*
*/
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;
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);
}
}
-/* $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 $ */
/*-
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;
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;
/*
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;
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)) {
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;
} 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';
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);
-/* $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 $ */
/*
* 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));
-/* $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 $ */
/*-
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);
}
}
/*
* tprintf_open: get a tprintf handle on a process "p"
+ * XXX change s/proc/process
*
* => returns NULL if process can't be printed to
*/
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);
}
-/* $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 $ */
/*
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);
-/* $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 $ */
/*-
* 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;
/*
* (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);
/*
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);
#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 */
* 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(t, p);
+ 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);
-/* $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 $ */
/*-
{
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. */
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)
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;
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);
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;
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;
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);
}
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);
}
{
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;
/*
* 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;
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];
* 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;
void
ttyinfo(struct tty *tp)
{
- struct proc *p, *pick;
+ struct process *pr;
+ struct proc *pick;
struct timeval utime, stime;
int tmp;
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;
-/* $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 $ */
/*
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)
-/* $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 $ */
/*-
#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
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);
-/* $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 $ */
/*
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);
-/* $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 $ */
/*
*/
#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
*/
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);
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;
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))
-/* $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 $ */
/*
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;
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)
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
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);
-/* $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 $ */
/*
* 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));
-/* $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 $ */
/*-
#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. */
*/
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 */
* One structure allocated per emulation.
*/
struct exec_package;
+struct proc;
struct ps_strings;
struct uvm_object;
union sigval;
* 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
#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. */
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;
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
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. */
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. */
#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. */
#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" \
#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) \
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 *);
-/* $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 $ */
/*-
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
-/* $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 $ */
/*
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
+#define RUSAGE_THREAD 1
struct rusage {
struct timeval ru_utime; /* user time used */
#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>
-/* $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 $ */
/*
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);
-/* $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 $ */
/*
#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))); \
\
(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; \
\
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)) { \
-/* $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 $ */
/*-
#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.
-/* $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 $ */
/*
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 */
};
/*