diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 2d64e422ba8b..4d8e66121f4f 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -719,11 +719,6 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread * if ((fr->fr_flags & RFMEM) == 0 && dtrace_fasttrap_fork) dtrace_fasttrap_fork(p1, p2); #endif - /* - * Hold the process so that it cannot exit after we make it runnable, - * but before we wait for the debugger. - */ - _PHOLD(p2); if (fr->fr_flags & RFPPWAIT) { _PHOLD(p2); td->td_pflags |= TDP_RFPPWAIT; @@ -783,8 +778,12 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread * PROC_UNLOCK(p2); sx_xunlock(&proctree_lock); } - + + racct_proc_fork_done(p2); + if ((fr->fr_flags & RFSTOPPED) == 0) { + if (fr->fr_pidp != NULL) + *fr->fr_pidp = p2->p_pid; /* * If RFSTOPPED not requested, make child runnable and * add to run queue. @@ -793,16 +792,9 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread * TD_SET_CAN_RUN(td2); sched_add(td2, SRQ_BORING); thread_unlock(td2); - if (fr->fr_pidp != NULL) - *fr->fr_pidp = p2->p_pid; } else { *fr->fr_procp = p2; } - - PROC_LOCK(p2); - _PRELE(p2); - racct_proc_fork_done(p2); - PROC_UNLOCK(p2); } int diff --git a/sys/kern/kern_racct.c b/sys/kern/kern_racct.c index d1ec1db880d4..644d514bb08e 100644 --- a/sys/kern/kern_racct.c +++ b/sys/kern/kern_racct.c @@ -967,13 +967,13 @@ racct_proc_fork_done(struct proc *child) if (!racct_enable) return; - PROC_LOCK_ASSERT(child, MA_OWNED); - #ifdef RCTL + PROC_LOCK(child); RACCT_LOCK(); rctl_enforce(child, RACCT_NPROC, 0); rctl_enforce(child, RACCT_NTHR, 0); RACCT_UNLOCK(); + PROC_UNLOCK(child); #endif }