Index: sys/compat/linux/linux_fork.c =================================================================== --- sys/compat/linux/linux_fork.c +++ sys/compat/linux/linux_fork.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,9 @@ TD_SET_CAN_RUN(td2); sched_add(td2, SRQ_BORING); thread_unlock(td2); - + + fork_finish(p2, td2); + return (0); } @@ -132,7 +135,9 @@ TD_SET_CAN_RUN(td2); sched_add(td2, SRQ_BORING); thread_unlock(td2); - + + fork_finish(p2, td2); + return (0); } @@ -251,7 +256,9 @@ TD_SET_CAN_RUN(td2); sched_add(td2, SRQ_BORING); thread_unlock(td2); - + + fork_finish(p2, td2); + td->td_retval[0] = p2->p_pid; return (0); @@ -350,6 +357,9 @@ thread_unlock(td); if (P_SHOULDSTOP(p)) newtd->td_flags |= TDF_ASTPENDING | TDF_NEEDSUSPCHK; + + if (p->p_ptevents & PTRACE_LWP) + newtd->td_dbgflags |= TDB_BORN; PROC_UNLOCK(p); tidhash_add(newtd); Index: sys/kern/kern_fork.c =================================================================== --- sys/kern/kern_fork.c +++ sys/kern/kern_fork.c @@ -384,6 +384,19 @@ return (error); } +void fork_finish(struct proc *p2, struct thread *td2) +{ + PROC_LOCK(p2); + /* + * Wait until debugger is attached to child. + */ + while (td2->td_proc == p2 && (td2->td_dbgflags & TDB_STOPATFORK) != 0) + cv_wait(&p2->p_dbgwait, &p2->p_mtx); + _PRELE(p2); + racct_proc_fork_done(p2); + PROC_UNLOCK(p2); +} + static void do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *td2, struct vmspace *vm2, struct file *fp_procdesc) @@ -768,19 +781,11 @@ thread_unlock(td2); if (fr->fr_pidp != NULL) *fr->fr_pidp = p2->p_pid; + + fork_finish(p2, td2); } else { *fr->fr_procp = p2; } - - PROC_LOCK(p2); - /* - * Wait until debugger is attached to child. - */ - while (td2->td_proc == p2 && (td2->td_dbgflags & TDB_STOPATFORK) != 0) - cv_wait(&p2->p_dbgwait, &p2->p_mtx); - _PRELE(p2); - racct_proc_fork_done(p2); - PROC_UNLOCK(p2); } int Index: sys/sys/proc.h =================================================================== --- sys/sys/proc.h +++ sys/sys/proc.h @@ -1036,6 +1036,7 @@ void faultin(struct proc *p); void fixjobc(struct proc *p, struct pgrp *pgrp, int entering); int fork1(struct thread *, struct fork_req *); +void fork_finish(struct proc *, struct thread *); void fork_exit(void (*)(void *, struct trapframe *), void *, struct trapframe *); void fork_return(struct thread *, struct trapframe *);