From: Eduardo Ramos Testillano Date: Sat, 19 Sep 2015 20:09:26 +0000 (+0200) Subject: Ignore ECHILD during system call on thread X-Git-Tag: REFACTORING_TESTING_LIBRARY~112 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=f92f99bd9a76474ef38c0437a181bfb0a0e14262;p=anna.git Ignore ECHILD during system call on thread --- diff --git a/example/diameter/launcher/testing/TestStep.cpp b/example/diameter/launcher/testing/TestStep.cpp index 605407e..b1da8fb 100644 --- a/example/diameter/launcher/testing/TestStep.cpp +++ b/example/diameter/launcher/testing/TestStep.cpp @@ -10,6 +10,7 @@ #include #include #include +#include // Project #include @@ -34,7 +35,21 @@ namespace { void cmdRunOnThread (TestStepCmd *step, const std::string &cmd) { step->setThreadRunning(true); int rc = system(cmd.c_str()); - if (rc != -1) rc >>= 8; // divide by 256 + if (rc < 0 && errno == ECHILD) rc = 0; // ignore, it could happens + // I know one reason for this is that SICCHLD is set to SIG_IGN but this + // should not be the case here. SIGCHLD is explicity set to SIG_DFL + // using a sigaction before the call to system(). (Although it is + // normally set to SIG_IGN). There should not be any other threads + // messing about with SIGCHLD. + + if (rc < 0) { + step->setErrorMsg(anna::functions::asString("errno = %d", errno)); + //std::terminate; + } + else { + rc >>= 8; // divide by 256 + } + step->setResultCode(rc); step->complete(); // TODO: timeout the system call @@ -422,6 +437,7 @@ throw() { result->createAttribute("Script", (a_script != "") ? a_script:""); result->createAttribute("Parameters", (a_parameters != "") ? a_parameters:""); result->createAttribute("CommandInProgress", a_threadRunning ? "yes":"no"); + if (a_errorMsg != "") result->createAttribute("ErrorMessage", a_errorMsg); if (!a_threadRunning && a_resultCode != -2) { result->createAttribute("ResultCode", a_resultCode); //if (a_output != "") result->createAttribute("Output", a_output); diff --git a/example/diameter/launcher/testing/TestStep.hpp b/example/diameter/launcher/testing/TestStep.hpp index aa2f575..38f40b6 100644 --- a/example/diameter/launcher/testing/TestStep.hpp +++ b/example/diameter/launcher/testing/TestStep.hpp @@ -212,10 +212,11 @@ class TestStepCmd : public TestStep { bool a_threadRunning; bool a_threadDeprecated; int a_resultCode; + std::string a_errorMsg; //std::string a_output; public: - TestStepCmd(TestCase *testCase) : TestStep(testCase), a_threadRunning(false), a_threadDeprecated(false), a_resultCode(-2)/*, a_output("")*/ { a_type = Type::Cmd; } + TestStepCmd(TestCase *testCase) : TestStep(testCase), a_threadRunning(false), a_threadDeprecated(false), a_resultCode(-2)/*, a_output("")*/, a_errorMsg("") { a_type = Type::Cmd; } // setter & getters void setThreadRunning(bool running) throw() { a_threadRunning = running; } @@ -225,6 +226,8 @@ class TestStepCmd : public TestStep { void setResultCode(int rc) throw() { a_resultCode = rc; } int getResultCode() const throw() { return a_resultCode; } + void setErrorMsg(const std::string &em) throw() { a_errorMsg = em; } + const std::string &getErrorMsg() const throw() { return a_errorMsg; } //void setOutput(const std::string &output) throw() { a_output = output; } //const std::string &getOutput() const throw() { return a_output; }