Return non-zero from ProcessHandle::wait if killed by signal

Currently, ProcessHandle::wait (and transitively Process::wait) on *NIX
return zero if process was terminated as a result of unhandled signal.
Check if this is the case and return negative signal number instead to
indicate non-graceful process termination.
This commit is contained in:
Mike Gelfand
2015-10-03 13:07:59 +03:00
parent df060cecbf
commit 3abdb1fc23
4 changed files with 36 additions and 1 deletions

View File

@@ -18,6 +18,7 @@
#include "Poco/Exception.h"
#include "Poco/NumberFormatter.h"
#include "Poco/Pipe.h"
#include <limits>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
@@ -68,7 +69,12 @@ int ProcessHandleImpl::wait() const
while (rc < 0 && errno == EINTR);
if (rc != _pid)
throw SystemException("Cannot wait for process", NumberFormatter::format(_pid));
return WEXITSTATUS(status);
if (WIFEXITED(status))
return WEXITSTATUS(status);
if (WIFSIGNALED(status))
return -WTERMSIG(status);
// This line should never be reached.
return std::numeric_limits<int>::max();
}