summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/exec_elf.c15
-rw-r--r--sys/kern/init_main.c13
-rw-r--r--sys/kern/kern_acct.c7
-rw-r--r--sys/kern/kern_descrip.c8
-rw-r--r--sys/kern/kern_exec.c8
-rw-r--r--sys/kern/kern_exit.c227
-rw-r--r--sys/kern/kern_fork.c35
-rw-r--r--sys/kern/kern_ktrace.c43
-rw-r--r--sys/kern/kern_proc.c138
-rw-r--r--sys/kern/kern_prot.c78
-rw-r--r--sys/kern/kern_resource.c92
-rw-r--r--sys/kern/kern_sig.c59
-rw-r--r--sys/kern/kern_sysctl.c48
-rw-r--r--sys/kern/spec_vnops.c6
-rw-r--r--sys/kern/subr_prf.c16
-rw-r--r--sys/kern/sys_generic.c8
-rw-r--r--sys/kern/sys_process.c22
-rw-r--r--sys/kern/tty.c65
-rw-r--r--sys/kern/tty_pty.c9
-rw-r--r--sys/kern/tty_tty.c10
-rw-r--r--sys/kern/vfs_vnops.c9
21 files changed, 506 insertions, 410 deletions
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index e962f9fb0f0..10993c60152 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -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);
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index e3d5d4c3ee2..14afa2af599 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -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;
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index 52f002b1a29..0051d4fe1c5 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -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;
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 12c44f0294d..e669c3e365a 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -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));
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 3bd0efe326e..5afdacd42d9 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -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);
}
/*
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index bf36116bd53..3302bc6eb00 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -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--;
}
-
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 07b8b1bc2c7..b92ea4a2cdb 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -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);
}
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index f0f8d6da6f8..a5312566288 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -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*/
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 96276b58303..d609994c930 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -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)
@@ -178,6 +178,20 @@ pfind(pid_t pid)
}
/*
+ * 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
*/
struct pgrp *
@@ -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);
}
}
}
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 3f49186d5c2..a34714c4ba5 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -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);
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 9bf4e2eab72..76a078d9e03 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -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:
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index eaff0b94351..a672064a4d1 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -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);
}
}
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 2e78801663c..4973cf62f25 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -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);
diff --git a/sys/kern/spec_vnops.c b/sys/kern/spec_vnops.c
index c1816c58186..11fde4c819b 100644
--- a/sys/kern/spec_vnops.c
+++ b/sys/kern/spec_vnops.c
@@ -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));
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 5d18a97b55a..30e7dcef6be 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -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);
}
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index 73e30f60fa7..9e49c7fa74f 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -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);
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index d3944c41811..e38e673e7e5 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -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(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);
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index d946e0d11cd..c8120bf02c6 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -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;
diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c
index 810ddff7070..5ea88c167fd 100644
--- a/sys/kern/tty_pty.c
+++ b/sys/kern/tty_pty.c
@@ -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)
diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c
index e2a4b4accbb..2a410b10456 100644
--- a/sys/kern/tty_tty.c
+++ b/sys/kern/tty_tty.c
@@ -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);
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index f6f5e28d1f3..d92dd347348 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -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);