ddollar/foreman — pull request #380 by tomykaira (2013-07-16 12:07:26+00:00)
Title: watch_for_termination until all children stop

`watch_for_termination` is called from `start` without loop. With the old
implementation, `watch_for_termination` exits when the first process is
killed, without waiting other child processes, if
`terminate_gracefully` is already called from signal handler. Other processes
become orphans, under the init process.

To fix this problem, the new implementation calls `wait` repeatedly until
@running is empty. It yields the block in each loop, because the first death
of a child should terminate other children.

Reproduction case is here

Procfile: (a bit tricky)

test1: sh -c "trap 'echo trapped; sleep 5' 1 2 3 15; sleep 100"
test2: sh -c "trap 'echo trapped; sleep 5' 1 2 3 15; sleep 100"
test3: sh -c "trap 'echo trapped; sleep 5' 1 2 3 15; sleep 100"

`foreman start` then terminate with Ctrl+C.

I have checked all behaviors in Ubuntu 12.04 32bit.

I could not find the right place in specs to write a new spec for this issue.