From c45529b40709c07e7915639de16b9c8d1778ec31 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 5 May 2017 17:31:14 +0200 Subject: [PATCH 1/2] Report failure to kill check command after exceeding timeout refs #4981 --- lib/base/process.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 03d217ce8..94ee94d95 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -34,6 +34,7 @@ #ifndef _WIN32 # include # include +# include # ifndef __APPLE__ extern char **environ; @@ -209,10 +210,12 @@ static Value ProcessKillImpl(struct msghdr *msgh, const Dictionary::Ptr& request pid_t pid = request->Get("pid"); int signum = request->Get("signum"); - int rc = kill(pid, signum); + errno = 0; + kill(pid, signum); + int error = errno; Dictionary::Ptr response = new Dictionary(); - response->Set("rc", rc); + response->Set("errno", error); return response; } @@ -452,7 +455,7 @@ send_message: String jresponse = String(buf, buf + rc); Dictionary::Ptr response = JsonDecode(jresponse); - return response->Get("rc"); + return response->Get("errno"); } static int ProcessWaitPID(pid_t pid, int *status) @@ -1020,7 +1023,11 @@ bool Process::DoEvents(void) #ifdef _WIN32 TerminateProcess(m_Process, 1); #else /* _WIN32 */ - ProcessKill(-m_Process, SIGKILL); + int error = ProcessKill(-m_Process, SIGKILL); + if (error) + Log(LogWarning, "Process") + << "Couldn't kill the process group " << m_PID << " (" << PrettyPrintArguments(m_Arguments) + << "): [errno " << error << "] " << strerror(error); #endif /* _WIN32 */ is_timeout = true; From 8bf3ab0285ceaa628bb3a52a0ec8e535c5e7607e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 12 May 2017 15:25:22 +0200 Subject: [PATCH 2/2] Produce an unknown check result if we failed to kill the process refs #4981 --- lib/base/process.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 94ee94d95..09c6a3436 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -1010,6 +1010,9 @@ void Process::Run(const boost::function& callback) bool Process::DoEvents(void) { bool is_timeout = false; +#ifndef _WIN32 + bool could_not_kill = false; +#endif /* _WIN32 */ if (m_Timeout != 0) { double timeout = m_Result.ExecutionStart + m_Timeout; @@ -1024,10 +1027,12 @@ bool Process::DoEvents(void) TerminateProcess(m_Process, 1); #else /* _WIN32 */ int error = ProcessKill(-m_Process, SIGKILL); - if (error) + if (error) { Log(LogWarning, "Process") << "Couldn't kill the process group " << m_PID << " (" << PrettyPrintArguments(m_Arguments) << "): [errno " << error << "] " << strerror(error); + could_not_kill = true; + } #endif /* _WIN32 */ is_timeout = true; @@ -1073,7 +1078,9 @@ bool Process::DoEvents(void) << "PID " << m_PID << " (" << PrettyPrintArguments(m_Arguments) << ") terminated with exit code " << exitcode; #else /* _WIN32 */ int status, exitcode; - if (ProcessWaitPID(m_Process, &status) != m_Process) { + if (could_not_kill) { + exitcode = 128; + } else if (ProcessWaitPID(m_Process, &status) != m_Process) { exitcode = 128; Log(LogWarning, "Process")