Bug 208188 - multiple identical wait4 results for ptraced processes
Summary: multiple identical wait4 results for ptraced processes
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-03-21 20:38 UTC by joss.upton
Modified: 2016-04-04 20:34 UTC (History)
0 users

See Also:


Attachments
waitx2.c demonstrate the multiple / identical wait4() results. (3.26 KB, text/x-csrc)
2016-03-21 20:38 UTC, joss.upton
no flags Details
patch to not generate multiple SIGCHLDs in some cases (485 bytes, patch)
2016-03-21 20:39 UTC, joss.upton
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description joss.upton 2016-03-21 20:38:30 UTC
Created attachment 168466 [details]
waitx2.c demonstrate the multiple / identical wait4() results.

When ptrace'n a process, wait4() returns the same pid/status multiple times.  This is when a process is ptrace'd, it gets a new parent and saves its old parent (in my case both the new parent and the old are the same process).  Then, in proc_reap() called from, e.g. wait4(), the ptrace'd process is reparented back to its "real" parent and an additional SIGCHLD is generated.

The attached program demonstrates the problem... On 10.2 it produces output like:
0: pid=1348 stopped(5)
1: pid=1348 exited(0)
2: pid=1348 exited(0)

It's impossible to differentiate between 1 & 2 unless I go out of my way to remember that I've already seen process 1348 WIFEXITED or WIFSIGNALED before.

The fix is to catch the superfluous SIGCHLD (when the realparent is the process currently waiting on the process) and stub it out.  Patch and example program attached.
Comment 1 joss.upton 2016-03-21 20:39:30 UTC
Created attachment 168467 [details]
patch to not generate multiple SIGCHLDs in some cases
Comment 2 joss.upton 2016-04-04 20:34:40 UTC
This bug is fixed with r283282.