Some callers of proc_reparent() already have the parent process locked.

Detect the situation and avoid process lock recursion.

Reported by:	Fabian Keil <freebsd-listen fabiankeil de>
This commit is contained in:
Konstantin Belousov 2011-04-10 17:07:02 +00:00
parent a827fe1fdf
commit 2cfd5d3c91

View File

@ -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);