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

@@ -16,6 +16,7 @@
#include "Poco/Process.h"
#include "Poco/Pipe.h"
#include "Poco/PipeStream.h"
#include <csignal>
using Poco::Process;
@@ -190,6 +191,27 @@ void ProcessTest::testIsRunning()
}
void ProcessTest::testSignalExitCode()
{
#if defined(POCO_OS_FAMILY_UNIX)
std::string name("TestApp");
std::string cmd;
#if defined(_DEBUG)
name += "d";
#endif
cmd = "./";
cmd += name;
std::vector<std::string> args;
args.push_back("-raise-int");
ProcessHandle ph = Process::launch(cmd, args, 0, 0, 0);
int rc = ph.wait();
assert (rc == -SIGINT);
#endif // defined(POCO_OS_FAMILY_UNIX)
}
void ProcessTest::setUp()
{
}
@@ -209,6 +231,7 @@ CppUnit::Test* ProcessTest::suite()
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectOut);
CppUnit_addTest(pSuite, ProcessTest, testLaunchEnv);
CppUnit_addTest(pSuite, ProcessTest, testIsRunning);
CppUnit_addTest(pSuite, ProcessTest, testSignalExitCode);
return pSuite;
}