This is an archive of the discontinued LLVM Phabricator instance.

Processes that spawn other processes should wait for their children to exit before exiting due to a signal.
Needs ReviewPublic

Authored by beanz on Apr 30 2015, 3:05 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

If a process that spawns other processes (like the clang driver) gets killed via a SIGINT, it should wait until its children exit before returning from the signal handler. This prevents the child processes from getting re-parented, which causes problems for build systems that are the parent of clang processes.

Diff Detail

Event Timeline

beanz updated this revision to Diff 24774.Apr 30 2015, 3:05 PM
beanz retitled this revision from to Processes that spawn other processes should wait for their children to exit before exiting due to a signal..
beanz updated this object.
beanz edited the test plan for this revision. (Show Details)
beanz added a reviewer: ddunbar.
beanz added a subscriber: Unknown Object (MLST).
silvas added a subscriber: silvas.Apr 30 2015, 3:13 PM
silvas added inline comments.
lib/Support/Unix/Program.inc
72

Do pids ever get pushed onto here? or is that an upcoming patch?

ddunbar edited edge metadata.Apr 30 2015, 3:17 PM

It doesn't look like ChildPIDs is ever added to?

This implementation can possibly call free() from ChildPIDs->clear(), and
while sys::Wait() looks safe as invoked, I could see how someone might
change it in a way that would cause it to break. It might be safer to call
waitpid() directly, or at least to add a comment to sys::Wait() noting that
it needs to stay signal safe when WaitUntilTerminates == 0 && ErrMsg ==
nullptr.

Also, I think you should take care not to register WaitForChildren()
multiple times.

Probably also good to include a note about why we are waiting for children.

  • Daniel
majnemer added inline comments.
lib/Support/Unix/Program.inc
188

You need a space between the if and the paren.

190

Might be nice to do something like:

Wait(PI, /*SecondsUntilTerminate=*/0, /*WaitUntilTerminate=*/true, /*ErrMsg=*/nullptr);

I find that bare constants in function parameters can be confusing without a little context.

beanz updated this revision to Diff 24778.Apr 30 2015, 3:51 PM
beanz edited edge metadata.

Updating based on feedback from majnemer, ddunbar, and silvas.

ddunbar added inline comments.May 14 2015, 9:12 AM
lib/Support/Unix/Program.inc
209

This can race on ProgramSignalHandlerAdded.

342

Shouldn't we also make sure to remove (or maybe just clear to 0, to indicate it is gone?) the PID when the child goes away?

352

This comment should be adjusted to not this is only necessary when ErrMsg=0, since the code trivially fails the comment if not.

ddunbar resigned from this revision.Sep 1 2016, 8:22 PM
ddunbar removed a reviewer: ddunbar.