Use waitpid to iterate over all exited child processes. Fixes #116. Closes #117.

This commit is contained in:
Sönke Ludwig 2019-08-21 16:18:30 +02:00
parent e1c6d99798
commit 507fb5a0c9

View file

@ -258,17 +258,26 @@ final class SignalEventDriverProcesses(Loop : PosixEventLoop) : EventDriverProce
private void onSignal(FD fd) private void onSignal(FD fd)
{ {
import core.sys.posix.sys.wait : WNOHANG, WEXITSTATUS, waitpid;
SignalListenID lid = cast(SignalListenID)fd; SignalListenID lid = cast(SignalListenID)fd;
// drain the signalfd - note that multiple signals can be combined into
// a single value, so that individual siginfo results are useless for
// us
signalfd_siginfo nfo; signalfd_siginfo nfo;
do { while (() @trusted { return read(cast(int)fd, &nfo, nfo.sizeof); } () == nfo.sizeof)
auto ret = () @trusted { return read(cast(int)fd, &nfo, nfo.sizeof); } (); {
}
if (ret == -1 && errno.among!(EAGAIN, EINPROGRESS) || ret != nfo.sizeof) // instead, use waitpid to determine all exited processes
return; while (true) {
int status;
auto ret = () @trusted { return waitpid(-1, &status, WNOHANG); } ();
if (ret <= 0) break;
onProcessExit(nfo.ssi_pid, nfo.ssi_status); onProcessExit(ret, () @trusted { return WEXITSTATUS(status); } ());
} while (true); }
} }
private void onProcessExit(int system_pid, int exitCode) private void onProcessExit(int system_pid, int exitCode)