I have just encountered the race condition which the provided recipe tries
to avoid :-(. The code looks similar to one in the article:
1. SIGCHLD is blocked
2. Then two child processes are invoked (in a "pipe" i.e. output of one
is the input of another).
3. A SIGCHLD handler similar to one described in
info '(libc)Merged Signals' is installed
4. So far so good. Then I start to wait in pselect
Logs show that the first child exits, its termination signal is caught by
the handler and pselect returns with exitcode=-1, errno=EINTR. Ok.
The code performs all necessary actions and returns back to
pselect(). But when the second child exits there's a *possibility* that
pselect won't return after signal is caught and processed in the handler.
I put a simple check that right before pselect() SIGCHLD is blocked
(and it is). Logs show that the handler is invoked (that is the signal was
unblocked in pselect) but strace'ing the process shows that it's hanging
on select() :-(. It seems I missed some magic :-(.
Debian-4.0 under VZ-enabled 2.6.18 kernel.