mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 20:59:45 +01:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user