Use find_stopped_child() and proc_free() in compat wait() code to
avoid code duplication. (approved by christos)
This commit is contained in:
parent
db17a870e0
commit
71d53fb2ed
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: irix_signal.c,v 1.24 2003/01/22 12:58:23 rafal Exp $ */
|
||||
/* $NetBSD: irix_signal.c,v 1.25 2003/02/14 10:19:14 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994, 2001-2002 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: irix_signal.c,v 1.24 2003/01/22 12:58:23 rafal Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: irix_signal.c,v 1.25 2003/02/14 10:19:14 dsl Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/signal.h>
|
||||
@ -837,16 +837,17 @@ irix_sys_waitsys(l, v, retval)
|
||||
syscallarg(int) options;
|
||||
syscallarg(struct rusage *) ru;
|
||||
} */ *uap = v;
|
||||
struct proc *p = l->l_proc;
|
||||
int nfound, error, s;
|
||||
struct proc *q, *t;
|
||||
struct proc *parent = l->l_proc;
|
||||
int error;
|
||||
struct proc *child;
|
||||
int options;
|
||||
|
||||
switch (SCARG(uap, type)) {
|
||||
case SVR4_P_PID:
|
||||
break;
|
||||
|
||||
case SVR4_P_PGID:
|
||||
SCARG(uap, pid) = -p->p_pgid;
|
||||
SCARG(uap, pid) = -parent->p_pgid;
|
||||
break;
|
||||
|
||||
case SVR4_P_ALL:
|
||||
@ -863,125 +864,57 @@ irix_sys_waitsys(l, v, retval)
|
||||
SCARG(uap, info), SCARG(uap, options), SCARG(uap, ru));
|
||||
#endif
|
||||
|
||||
loop:
|
||||
nfound = 0;
|
||||
for (q = p->p_children.lh_first; q != 0; q = q->p_sibling.le_next) {
|
||||
if (SCARG(uap, pid) != WAIT_ANY &&
|
||||
q->p_pid != SCARG(uap, pid) &&
|
||||
q->p_pgid != -SCARG(uap, pid)) {
|
||||
/* Translate options */
|
||||
options = 0;
|
||||
if (SCARG(uap, options) & SVR4_WNOWAIT)
|
||||
options |= WNOWAIT;
|
||||
if (SCARG(uap, options) & SVR4_WNOHANG)
|
||||
options |= WNOHANG;
|
||||
if ((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)) == 0)
|
||||
options |= WNOZOMBIE;
|
||||
if (SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED))
|
||||
options |= WUNTRACED;
|
||||
|
||||
error = find_stopped_child(parent, SCARG(uap,pid), options, &child);
|
||||
if (error != 0)
|
||||
return error;
|
||||
*retval = 0;
|
||||
if (child == NULL)
|
||||
return irix_wait_siginfo(NULL, 0, SCARG(uap, info));
|
||||
|
||||
if (child->p_stat == SZOMB) {
|
||||
#ifdef DEBUG_IRIX
|
||||
printf("pid %d pgid %d != %d\n", q->p_pid,
|
||||
q->p_pgid, SCARG(uap, pid));
|
||||
printf("irix_sys_wait(): found %d\n", child->p_pid);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
nfound++;
|
||||
if (q->p_stat == SZOMB &&
|
||||
((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
|
||||
*retval = 0;
|
||||
#ifdef DEBUG_IRIX
|
||||
printf("irix_sys_wait(): found %d\n", q->p_pid);
|
||||
#endif
|
||||
if ((error = irix_wait_siginfo(q, q->p_xstat,
|
||||
if ((error = irix_wait_siginfo(child, child->p_xstat,
|
||||
SCARG(uap, info))) != 0)
|
||||
return error;
|
||||
return error;
|
||||
|
||||
|
||||
if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
|
||||
if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
|
||||
#ifdef DEBUG_IRIX
|
||||
printf(("irix_sys_wait(): Don't wait\n"));
|
||||
printf(("irix_sys_wait(): Don't wait\n"));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
if (SCARG(uap, ru) &&
|
||||
(error = copyout(&(p->p_stats->p_ru),
|
||||
(caddr_t)SCARG(uap, ru), sizeof(struct rusage))))
|
||||
return (error);
|
||||
|
||||
/*
|
||||
* If we got the child via ptrace(2) or procfs, and
|
||||
* the parent is different (meaning the process was
|
||||
* attached, rather than run as a child), then we need
|
||||
* to give it back to the old parent, and send the
|
||||
* parent a SIGCHLD. The rest of the cleanup will be
|
||||
* done when the old parent waits on the child.
|
||||
*/
|
||||
if ((q->p_flag & P_TRACED) && q->p_opptr != q->p_pptr){
|
||||
t = q->p_opptr;
|
||||
proc_reparent(q, t ? t : initproc);
|
||||
q->p_opptr = NULL;
|
||||
q->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
|
||||
psignal(q->p_pptr, SIGCHLD);
|
||||
wakeup((caddr_t)q->p_pptr);
|
||||
return (0);
|
||||
}
|
||||
q->p_xstat = 0;
|
||||
ruadd(&p->p_stats->p_cru, q->p_ru);
|
||||
pool_put(&rusage_pool, q->p_ru);
|
||||
|
||||
/*
|
||||
* Finally finished with old proc entry.
|
||||
* Unlink it from its process group and free it.
|
||||
*/
|
||||
leavepgrp(q);
|
||||
|
||||
s = proclist_lock_write();
|
||||
LIST_REMOVE(q, p_list); /* off zombproc */
|
||||
proclist_unlock_write(s);
|
||||
|
||||
LIST_REMOVE(q, p_sibling);
|
||||
|
||||
/*
|
||||
* Decrement the count of procs running with this uid.
|
||||
*/
|
||||
(void)chgproccnt(q->p_cred->p_ruid, -1);
|
||||
|
||||
/*
|
||||
* Free up credentials.
|
||||
*/
|
||||
if (--q->p_cred->p_refcnt == 0) {
|
||||
crfree(q->p_cred->pc_ucred);
|
||||
pool_put(&pcred_pool, q->p_cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release reference to text vnode
|
||||
*/
|
||||
if (q->p_textvp)
|
||||
vrele(q->p_textvp);
|
||||
|
||||
pool_put(&proc_pool, q);
|
||||
nprocs--;
|
||||
return 0;
|
||||
}
|
||||
if (q->p_stat == SSTOP && (q->p_flag & P_WAITED) == 0 &&
|
||||
(q->p_flag & P_TRACED ||
|
||||
(SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED)))) {
|
||||
#ifdef DEBUG_IRIX
|
||||
printf("jobcontrol %d\n", q->p_pid);
|
||||
#endif
|
||||
if (((SCARG(uap, options) & SVR4_WNOWAIT)) == 0)
|
||||
q->p_flag |= P_WAITED;
|
||||
*retval = 0;
|
||||
return irix_wait_siginfo(q, W_STOPCODE(q->p_xstat),
|
||||
SCARG(uap, info));
|
||||
}
|
||||
}
|
||||
|
||||
if (nfound == 0)
|
||||
return ECHILD;
|
||||
|
||||
if (SCARG(uap, options) & SVR4_WNOHANG) {
|
||||
*retval = 0;
|
||||
if ((error = irix_wait_siginfo(NULL, 0, SCARG(uap, info))) != 0)
|
||||
if (SCARG(uap, ru) &&
|
||||
/* XXX (dsl) is this copying out the right data???
|
||||
child->p_ru would seem more appropriate! */
|
||||
(error = copyout(&(parent->p_stats->p_ru),
|
||||
(caddr_t)SCARG(uap, ru), sizeof(struct rusage))))
|
||||
return error;
|
||||
|
||||
proc_free(child);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((error = tsleep((caddr_t)p, PWAIT | PCATCH, "svr4_wait", 0)) != 0)
|
||||
return error;
|
||||
goto loop;
|
||||
/* Child state must be SSTOP */
|
||||
|
||||
#ifdef DEBUG_IRIX
|
||||
printf("jobcontrol %d\n", child->p_pid);
|
||||
#endif
|
||||
return irix_wait_siginfo(child, W_STOPCODE(child->p_xstat),
|
||||
SCARG(uap, info));
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: netbsd32_wait.c,v 1.5 2003/01/18 08:28:26 thorpej Exp $ */
|
||||
/* $NetBSD: netbsd32_wait.c,v 1.6 2003/02/14 10:19:14 dsl Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.5 2003/01/18 08:28:26 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.6 2003/02/14 10:19:14 dsl Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -58,121 +58,54 @@ netbsd32_wait4(l, v, retval)
|
||||
syscallarg(int) options;
|
||||
syscallarg(netbsd32_rusagep_t) rusage;
|
||||
} */ *uap = v;
|
||||
struct proc *q = l->l_proc;
|
||||
struct proc *parent = l->l_proc;
|
||||
struct netbsd32_rusage ru32;
|
||||
int nfound;
|
||||
struct proc *p, *t;
|
||||
struct proc *child;
|
||||
int status, error;
|
||||
|
||||
if (SCARG(uap, pid) == 0)
|
||||
SCARG(uap, pid) = -q->p_pgid;
|
||||
SCARG(uap, pid) = -parent->p_pgid;
|
||||
if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG))
|
||||
return (EINVAL);
|
||||
|
||||
loop:
|
||||
nfound = 0;
|
||||
for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
|
||||
if (SCARG(uap, pid) != WAIT_ANY &&
|
||||
p->p_pid != SCARG(uap, pid) &&
|
||||
p->p_pgid != -SCARG(uap, pid))
|
||||
continue;
|
||||
nfound++;
|
||||
if (p->p_stat == SZOMB) {
|
||||
retval[0] = p->p_pid;
|
||||
|
||||
if (SCARG(uap, status)) {
|
||||
status = p->p_xstat; /* convert to int */
|
||||
error = copyout((caddr_t)&status,
|
||||
(caddr_t)NETBSD32PTR64(SCARG(uap, status)),
|
||||
sizeof(status));
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
if (SCARG(uap, rusage)) {
|
||||
netbsd32_from_rusage(p->p_ru, &ru32);
|
||||
if ((error = copyout((caddr_t)&ru32,
|
||||
(caddr_t)NETBSD32PTR64(SCARG(uap, rusage)),
|
||||
sizeof(struct netbsd32_rusage))))
|
||||
return (error);
|
||||
}
|
||||
/*
|
||||
* If we got the child via ptrace(2) or procfs, and
|
||||
* the parent is different (meaning the process was
|
||||
* attached, rather than run as a child), then we need
|
||||
* to give it back to the old parent, and send the
|
||||
* parent a SIGCHLD. The rest of the cleanup will be
|
||||
* done when the old parent waits on the child.
|
||||
*/
|
||||
if ((p->p_flag & P_TRACED) && p->p_opptr != p->p_pptr){
|
||||
t = p->p_opptr;
|
||||
proc_reparent(p, t ? t : initproc);
|
||||
p->p_opptr = NULL;
|
||||
p->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
|
||||
psignal(p->p_pptr, SIGCHLD);
|
||||
wakeup((caddr_t)p->p_pptr);
|
||||
return (0);
|
||||
}
|
||||
p->p_xstat = 0;
|
||||
ruadd(&q->p_stats->p_cru, p->p_ru);
|
||||
pool_put(&rusage_pool, p->p_ru);
|
||||
|
||||
/*
|
||||
* Finally finished with old proc entry.
|
||||
* Unlink it from its process group and free it.
|
||||
*/
|
||||
leavepgrp(p);
|
||||
|
||||
LIST_REMOVE(p, p_list); /* off zombproc */
|
||||
|
||||
LIST_REMOVE(p, p_sibling);
|
||||
|
||||
/*
|
||||
* Decrement the count of procs running with this uid.
|
||||
*/
|
||||
(void)chgproccnt(p->p_cred->p_ruid, -1);
|
||||
|
||||
/*
|
||||
* Free up credentials.
|
||||
*/
|
||||
if (--p->p_cred->p_refcnt == 0) {
|
||||
crfree(p->p_cred->pc_ucred);
|
||||
pool_put(&pcred_pool, p->p_cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release reference to text vnode
|
||||
*/
|
||||
if (p->p_textvp)
|
||||
vrele(p->p_textvp);
|
||||
|
||||
pool_put(&proc_pool, p);
|
||||
nprocs--;
|
||||
return (0);
|
||||
}
|
||||
if (p->p_stat == SSTOP && (p->p_flag & P_WAITED) == 0 &&
|
||||
(p->p_flag & P_TRACED || SCARG(uap, options) & WUNTRACED)) {
|
||||
p->p_flag |= P_WAITED;
|
||||
retval[0] = p->p_pid;
|
||||
|
||||
if (SCARG(uap, status)) {
|
||||
status = W_STOPCODE(p->p_xstat);
|
||||
error = copyout((caddr_t)&status,
|
||||
(caddr_t)NETBSD32PTR64(SCARG(uap, status)),
|
||||
sizeof(status));
|
||||
} else
|
||||
error = 0;
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
if (nfound == 0)
|
||||
return (ECHILD);
|
||||
if (SCARG(uap, options) & WNOHANG) {
|
||||
error = find_stopped_child(parent, SCARG(uap,pid), SCARG(uap,options),
|
||||
&child);
|
||||
if (error != 0)
|
||||
return error;
|
||||
if (child == NULL) {
|
||||
retval[0] = 0;
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
if ((error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)) != 0)
|
||||
return (error);
|
||||
goto loop;
|
||||
|
||||
retval[0] = child->p_pid;
|
||||
if (child->p_stat == SZOMB) {
|
||||
if (SCARG(uap, status)) {
|
||||
status = child->p_xstat; /* convert to int */
|
||||
error = copyout((caddr_t)&status,
|
||||
(caddr_t)NETBSD32PTR64(SCARG(uap, status)),
|
||||
sizeof(status));
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
if (SCARG(uap, rusage)) {
|
||||
netbsd32_from_rusage(child->p_ru, &ru32);
|
||||
error = copyout((caddr_t)&ru32,
|
||||
(caddr_t)NETBSD32PTR64(SCARG(uap, rusage)),
|
||||
sizeof(struct netbsd32_rusage));
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
proc_free(child);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (SCARG(uap, status)) {
|
||||
status = W_STOPCODE(child->p_xstat);
|
||||
return copyout((caddr_t)&status,
|
||||
(caddr_t)NETBSD32PTR64(SCARG(uap, status)),
|
||||
sizeof(status));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: svr4_misc.c,v 1.101 2003/01/29 07:00:39 atatat Exp $ */
|
||||
/* $NetBSD: svr4_misc.c,v 1.102 2003/02/14 10:19:15 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
||||
@ -44,7 +44,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.101 2003/01/29 07:00:39 atatat Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.102 2003/02/14 10:19:15 dsl Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -1182,17 +1182,17 @@ svr4_sys_waitsys(l, v, retval)
|
||||
register_t *retval;
|
||||
{
|
||||
struct svr4_sys_waitsys_args *uap = v;
|
||||
int nfound, error, s;
|
||||
struct proc *p = l->l_proc;
|
||||
struct proc *q, *t;
|
||||
|
||||
int options;
|
||||
int error;
|
||||
struct proc *parent = l->l_proc;
|
||||
struct proc *child;
|
||||
|
||||
switch (SCARG(uap, grp)) {
|
||||
case SVR4_P_PID:
|
||||
break;
|
||||
|
||||
case SVR4_P_PGID:
|
||||
SCARG(uap, id) = -p->p_pgid;
|
||||
SCARG(uap, id) = -parent->p_pgid;
|
||||
break;
|
||||
|
||||
case SVR4_P_ALL:
|
||||
@ -1203,116 +1203,47 @@ svr4_sys_waitsys(l, v, retval)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/* Translate options */
|
||||
options = 0;
|
||||
if (SCARG(uap, options) & SVR4_WNOWAIT)
|
||||
options |= WNOWAIT;
|
||||
if (SCARG(uap, options) & SVR4_WNOHANG)
|
||||
options |= WNOHANG;
|
||||
if ((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)) == 0)
|
||||
options |= WNOZOMBIE;
|
||||
if (SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED))
|
||||
options |= WUNTRACED;
|
||||
|
||||
DPRINTF(("waitsys(%d, %d, %p, %x)\n",
|
||||
SCARG(uap, grp), SCARG(uap, id),
|
||||
SCARG(uap, info), SCARG(uap, options)));
|
||||
|
||||
loop:
|
||||
nfound = 0;
|
||||
for (q = p->p_children.lh_first; q != 0; q = q->p_sibling.le_next) {
|
||||
if (SCARG(uap, id) != WAIT_ANY &&
|
||||
q->p_pid != SCARG(uap, id) &&
|
||||
q->p_pgid != -SCARG(uap, id)) {
|
||||
DPRINTF(("pid %d pgid %d != %d\n", q->p_pid,
|
||||
q->p_pgid, SCARG(uap, id)));
|
||||
continue;
|
||||
}
|
||||
nfound++;
|
||||
if (q->p_stat == SZOMB &&
|
||||
((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
|
||||
*retval = 0;
|
||||
DPRINTF(("found %d\n", q->p_pid));
|
||||
if ((error = svr4_setinfo(q, q->p_xstat,
|
||||
SCARG(uap, info))) != 0)
|
||||
return error;
|
||||
error = find_stopped_child(parent, SCARG(uap, id), options, &child);
|
||||
if (error != 0)
|
||||
return error;
|
||||
*retval = 0;
|
||||
if (child == NULL)
|
||||
return svr4_setinfo(NULL, 0, SCARG(uap, info));
|
||||
|
||||
if (child->p_stat == SZOMB) {
|
||||
DPRINTF(("found %d\n", child->p_pid));
|
||||
if ((error = svr4_setinfo(child, child->p_xstat,
|
||||
SCARG(uap, info))) != 0)
|
||||
return error;
|
||||
|
||||
|
||||
if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
|
||||
DPRINTF(("Don't wait\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we got the child via ptrace(2) or procfs, and
|
||||
* the parent is different (meaning the process was
|
||||
* attached, rather than run as a child), then we need
|
||||
* to give it back to the old parent, and send the
|
||||
* parent a SIGCHLD. The rest of the cleanup will be
|
||||
* done when the old parent waits on the child.
|
||||
*/
|
||||
if ((q->p_flag & P_TRACED) && q->p_opptr != q->p_pptr){
|
||||
t = q->p_opptr;
|
||||
proc_reparent(q, t ? t : initproc);
|
||||
q->p_opptr = NULL;
|
||||
q->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
|
||||
psignal(q->p_pptr, SIGCHLD);
|
||||
wakeup((caddr_t)q->p_pptr);
|
||||
return (0);
|
||||
}
|
||||
q->p_xstat = 0;
|
||||
ruadd(&p->p_stats->p_cru, q->p_ru);
|
||||
pool_put(&rusage_pool, q->p_ru);
|
||||
|
||||
/*
|
||||
* Finally finished with old proc entry.
|
||||
* Unlink it from its process group and free it.
|
||||
*/
|
||||
leavepgrp(q);
|
||||
|
||||
s = proclist_lock_write();
|
||||
LIST_REMOVE(q, p_list); /* off zombproc */
|
||||
proclist_unlock_write(s);
|
||||
|
||||
LIST_REMOVE(q, p_sibling);
|
||||
|
||||
/*
|
||||
* Decrement the count of procs running with this uid.
|
||||
*/
|
||||
(void)chgproccnt(q->p_cred->p_ruid, -1);
|
||||
|
||||
/*
|
||||
* Free up credentials.
|
||||
*/
|
||||
if (--q->p_cred->p_refcnt == 0) {
|
||||
crfree(q->p_cred->pc_ucred);
|
||||
pool_put(&pcred_pool, q->p_cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release reference to text vnode
|
||||
*/
|
||||
if (q->p_textvp)
|
||||
vrele(q->p_textvp);
|
||||
|
||||
pool_put(&proc_pool, q);
|
||||
nprocs--;
|
||||
if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
|
||||
DPRINTF(("Don't wait\n"));
|
||||
return 0;
|
||||
}
|
||||
if (q->p_stat == SSTOP && (q->p_flag & P_WAITED) == 0 &&
|
||||
(q->p_flag & P_TRACED ||
|
||||
(SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED)))) {
|
||||
DPRINTF(("jobcontrol %d\n", q->p_pid));
|
||||
if (((SCARG(uap, options) & SVR4_WNOWAIT)) == 0)
|
||||
q->p_flag |= P_WAITED;
|
||||
*retval = 0;
|
||||
return svr4_setinfo(q, W_STOPCODE(q->p_xstat),
|
||||
SCARG(uap, info));
|
||||
}
|
||||
}
|
||||
|
||||
if (nfound == 0)
|
||||
return ECHILD;
|
||||
|
||||
if (SCARG(uap, options) & SVR4_WNOHANG) {
|
||||
*retval = 0;
|
||||
if ((error = svr4_setinfo(NULL, 0, SCARG(uap, info))) != 0)
|
||||
return error;
|
||||
proc_free(child);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((error = tsleep((caddr_t)p, PWAIT | PCATCH, "svr4_wait", 0)) != 0)
|
||||
return error;
|
||||
goto loop;
|
||||
DPRINTF(("jobcontrol %d\n", child->p_pid));
|
||||
return svr4_setinfo(child, W_STOPCODE(child->p_xstat),
|
||||
SCARG(uap, info));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: svr4_32_misc.c,v 1.16 2003/01/29 07:00:40 atatat Exp $ */
|
||||
/* $NetBSD: svr4_32_misc.c,v 1.17 2003/02/14 10:19:15 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
||||
@ -44,7 +44,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.16 2003/01/29 07:00:40 atatat Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.17 2003/02/14 10:19:15 dsl Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -1201,17 +1201,16 @@ svr4_32_sys_waitsys(l, v, retval)
|
||||
register_t *retval;
|
||||
{
|
||||
struct svr4_32_sys_waitsys_args *uap = v;
|
||||
struct proc *p = l->l_proc;
|
||||
int nfound, error, s;
|
||||
struct proc *q, *t;
|
||||
|
||||
struct proc *parent = l->l_proc;
|
||||
int options, error;
|
||||
struct proc *child;
|
||||
|
||||
switch (SCARG(uap, grp)) {
|
||||
case SVR4_P_PID:
|
||||
break;
|
||||
|
||||
case SVR4_P_PGID:
|
||||
SCARG(uap, id) = -p->p_pgid;
|
||||
SCARG(uap, id) = -parent->p_pgid;
|
||||
break;
|
||||
|
||||
case SVR4_P_ALL:
|
||||
@ -1226,112 +1225,42 @@ svr4_32_sys_waitsys(l, v, retval)
|
||||
SCARG(uap, grp), SCARG(uap, id),
|
||||
SCARG(uap, info), SCARG(uap, options)));
|
||||
|
||||
loop:
|
||||
nfound = 0;
|
||||
for (q = p->p_children.lh_first; q != 0; q = q->p_sibling.le_next) {
|
||||
if (SCARG(uap, id) != WAIT_ANY &&
|
||||
q->p_pid != SCARG(uap, id) &&
|
||||
q->p_pgid != -SCARG(uap, id)) {
|
||||
DPRINTF(("pid %d pgid %d != %d\n", q->p_pid,
|
||||
q->p_pgid, SCARG(uap, id)));
|
||||
continue;
|
||||
}
|
||||
nfound++;
|
||||
if (q->p_stat == SZOMB &&
|
||||
((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
|
||||
*retval = 0;
|
||||
DPRINTF(("found %d\n", q->p_pid));
|
||||
if ((error =
|
||||
svr4_32_setinfo(q, q->p_xstat, SCARG(uap, info))) != 0)
|
||||
return error;
|
||||
/* Translate options */
|
||||
options = 0;
|
||||
if (SCARG(uap, options) & SVR4_WNOWAIT)
|
||||
options |= WNOWAIT;
|
||||
if (SCARG(uap, options) & SVR4_WNOHANG)
|
||||
options |= WNOHANG;
|
||||
if ((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)) == 0)
|
||||
options |= WNOZOMBIE;
|
||||
if (SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED))
|
||||
options |= WUNTRACED;
|
||||
|
||||
error = find_stopped_child(parent, SCARG(uap, id), options, &child);
|
||||
if (error != 0)
|
||||
return error;
|
||||
*retval = 0;
|
||||
if (child == NULL)
|
||||
return svr4_32_setinfo(NULL, 0, SCARG(uap, info));
|
||||
|
||||
if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
|
||||
DPRINTF(("Don't wait\n"));
|
||||
return 0;
|
||||
}
|
||||
if (child->p_stat == SZOMB) {
|
||||
DPRINTF(("found %d\n", child->p_pid));
|
||||
error = svr4_32_setinfo(child, child->p_xstat, SCARG(uap,info));
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
/*
|
||||
* If we got the child via ptrace(2) or procfs, and
|
||||
* the parent is different (meaning the process was
|
||||
* attached, rather than run as a child), then we need
|
||||
* to give it back to the old parent, and send the
|
||||
* parent a SIGCHLD. The rest of the cleanup will be
|
||||
* done when the old parent waits on the child.
|
||||
*/
|
||||
if ((q->p_flag & P_TRACED) && q->p_opptr != q->p_pptr){
|
||||
t = q->p_opptr;
|
||||
proc_reparent(q, t ? t : initproc);
|
||||
q->p_opptr = NULL;
|
||||
q->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
|
||||
psignal(q->p_pptr, SIGCHLD);
|
||||
wakeup((caddr_t)q->p_pptr);
|
||||
return (0);
|
||||
}
|
||||
q->p_xstat = 0;
|
||||
ruadd(&p->p_stats->p_cru, q->p_ru);
|
||||
pool_put(&rusage_pool, q->p_ru);
|
||||
|
||||
/*
|
||||
* Finally finished with old proc entry.
|
||||
* Unlink it from its process group and free it.
|
||||
*/
|
||||
leavepgrp(q);
|
||||
|
||||
s = proclist_lock_write();
|
||||
LIST_REMOVE(q, p_list); /* off zombproc */
|
||||
proclist_unlock_write(s);
|
||||
|
||||
LIST_REMOVE(q, p_sibling);
|
||||
|
||||
/*
|
||||
* Decrement the count of procs running with this uid.
|
||||
*/
|
||||
(void)chgproccnt(q->p_cred->p_ruid, -1);
|
||||
|
||||
/*
|
||||
* Free up credentials.
|
||||
*/
|
||||
if (--q->p_cred->p_refcnt == 0) {
|
||||
crfree(q->p_cred->pc_ucred);
|
||||
pool_put(&pcred_pool, q->p_cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release reference to text vnode
|
||||
*/
|
||||
if (q->p_textvp)
|
||||
vrele(q->p_textvp);
|
||||
|
||||
pool_put(&proc_pool, q);
|
||||
nprocs--;
|
||||
if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
|
||||
DPRINTF(("Don't wait\n"));
|
||||
return 0;
|
||||
}
|
||||
if (q->p_stat == SSTOP && (q->p_flag & P_WAITED) == 0 &&
|
||||
(q->p_flag & P_TRACED ||
|
||||
(SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED)))) {
|
||||
DPRINTF(("jobcontrol %d\n", q->p_pid));
|
||||
if (((SCARG(uap, options) & SVR4_WNOWAIT)) == 0)
|
||||
q->p_flag |= P_WAITED;
|
||||
*retval = 0;
|
||||
return svr4_32_setinfo(q, W_STOPCODE(q->p_xstat),
|
||||
SCARG(uap, info));
|
||||
}
|
||||
}
|
||||
|
||||
if (nfound == 0)
|
||||
return ECHILD;
|
||||
|
||||
if (SCARG(uap, options) & SVR4_WNOHANG) {
|
||||
*retval = 0;
|
||||
if ((error = svr4_32_setinfo(NULL, 0, SCARG(uap, info))) != 0)
|
||||
return error;
|
||||
proc_free(child);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((error = tsleep((caddr_t)p, PWAIT | PCATCH, "svr4_32_wait", 0)) != 0)
|
||||
return error;
|
||||
goto loop;
|
||||
DPRINTF(("jobcontrol %d\n", child->p_pid));
|
||||
return svr4_32_setinfo(child, W_STOPCODE(child->p_xstat),
|
||||
SCARG(uap, info));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user