diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 5fec31b060b2..2d35ed524f59 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -903,15 +903,19 @@ kern_wait(struct thread *td, pid_t pid, int *status, int options, void proc_reparent(struct proc *child, struct proc *parent) { + int locked; sx_assert(&proctree_lock, SX_XLOCKED); PROC_LOCK_ASSERT(child, MA_OWNED); if (child->p_pptr == parent) return; - PROC_LOCK(parent); + locked = PROC_LOCKED(parent); + if (!locked) + PROC_LOCK(parent); racct_add_force(parent, RACCT_NPROC, 1); - PROC_UNLOCK(parent); + if (!locked) + PROC_UNLOCK(parent); PROC_LOCK(child->p_pptr); racct_sub(child->p_pptr, RACCT_NPROC, 1); sigqueue_take(child->p_ksi);