Skip to content

Commit

Permalink
Clear P_TRACED before reparenting a detached process back to its
Browse files Browse the repository at this point in the history
original parent. Otherwise the debugee will be set as an orphan of
the debugger.

Add tests for tracing forks via PT_FOLLOW_FORK.

Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D2809
  • Loading branch information
bsdjhb committed Aug 1, 2015
1 parent e83b0ae commit 13db466
Show file tree
Hide file tree
Showing 2 changed files with 536 additions and 56 deletions.
11 changes: 9 additions & 2 deletions sys/kern/sys_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,15 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
}
break;
case PT_DETACH:
/* reset process parent */
/*
* Reset the process parent.
*
* NB: This clears P_TRACED before reparenting
* a detached process back to its original
* parent. Otherwise the debugee will be set
* as an orphan of the debugger.
*/
p->p_flag &= ~(P_TRACED | P_WAITED | P_FOLLOWFORK);
if (p->p_oppid != p->p_pptr->p_pid) {
PROC_LOCK(p->p_pptr);
sigqueue_take(p->p_ksi);
Expand All @@ -963,7 +971,6 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
} else
CTR1(KTR_PTRACE, "PT_DETACH: pid %d", p->p_pid);
p->p_oppid = 0;
p->p_flag &= ~(P_TRACED | P_WAITED | P_FOLLOWFORK);
p->p_stops = 0;

/* should we send SIGCHLD? */
Expand Down
Loading

0 comments on commit 13db466

Please sign in to comment.