From d4cdee6a1a776015fa0e00df7f41f92bbd3ea3a2 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 19 Aug 2014 12:58:55 +0200 Subject: [PATCH] Change log level for failed commands fixes #6751 --- lib/base/process.cpp | 30 ++++++++++++++++++++---------- lib/base/process.hpp | 2 ++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 40fbfba5b..bfae2506d 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -280,6 +280,15 @@ void Process::IOThreadProc(int tid) } } +String Process::PrettyPrintArguments(void) const +{ +#ifdef _WIN32 + return "'" + m_Arguments + "'"; +#else /* _WIN32 */ + return "'" + boost::algorithm::join(m_Arguments, "' '") + "'"; +#endif /* _WIN32 */ +} + void Process::Run(const boost::function& callback) { boost::call_once(l_OnceFlag, &Process::ThreadInitialize); @@ -427,8 +436,8 @@ void Process::Run(const boost::function& callback) m_FD = outReadPipe; m_PID = pi.dwProcessId; - Log(LogNotice, "Process", "Running command '" + m_Arguments + - "': PID " + Convert::ToString(m_PID)); + Log(LogNotice, "Process", "Running command " + PrettyPrintArguments() + + ": PID " + Convert::ToString(m_PID)); #else /* _WIN32 */ int fds[2]; @@ -533,10 +542,7 @@ void Process::Run(const boost::function& callback) m_PID = m_Process; - Log(LogNotice, "Process", "Running command '" + boost::algorithm::join(m_Arguments, "', '") + - "': PID " + Convert::ToString(m_PID)); - - m_Arguments.clear(); + Log(LogNotice, "Process", "Running command " + PrettyPrintArguments() + ": PID " + Convert::ToString(m_PID)); // free arguments for (int i = 0; argv[i] != NULL; i++) @@ -585,7 +591,8 @@ bool Process::DoEvents(void) double timeout = m_Result.ExecutionStart + m_Timeout; if (timeout < Utility::GetTime()) { - Log(LogNotice, "Process", "Killing process '" + Convert::ToString(m_PID) + " after timeout of " + Convert::ToString(m_Timeout) + " seconds"); + Log(LogWarning, "Process", "Killing process " + Convert::ToString(m_PID) + + " (" + PrettyPrintArguments() + ") after timeout of " + Convert::ToString(m_Timeout) + " seconds"); m_OutputStream << ""; #ifdef _WIN32 @@ -633,7 +640,8 @@ bool Process::DoEvents(void) DWORD exitcode; GetExitCodeProcess(m_Process, &exitcode); - Log(LogNotice, "Process", "PID " + Convert::ToString(m_PID) + " terminated with exit code " + Convert::ToString(exitcode)); + Log((exitcode == 0) ? LogNotice : LogWarning, "Process", "PID " + Convert::ToString(m_PID) + + " (" + PrettyPrintArguments() + ") terminated with exit code " + Convert::ToString(exitcode)); #else /* _WIN32 */ int status, exitcode; if (waitpid(m_Process, &status, 0) != m_Process) { @@ -645,9 +653,11 @@ bool Process::DoEvents(void) if (WIFEXITED(status)) { exitcode = WEXITSTATUS(status); - Log(LogNotice, "Process", "PID " + Convert::ToString(m_PID) + " terminated with exit code " + Convert::ToString(exitcode)); + Log((exitcode == 0) ? LogNotice : LogWarning, "Process", "PID " + Convert::ToString(m_PID) + + " (" + PrettyPrintArguments() + ") terminated with exit code " + Convert::ToString(exitcode)); } else if (WIFSIGNALED(status)) { - Log(LogNotice, "Process", "PID " + Convert::ToString(m_PID) + " was terminated by signal " + Convert::ToString(WTERMSIG(status))); + Log(LogWarning, "Process", "PID " + Convert::ToString(m_PID) + " was terminated by signal " + + Convert::ToString(WTERMSIG(status))); std::ostringstream outputbuf; outputbuf << ""; diff --git a/lib/base/process.hpp b/lib/base/process.hpp index e0f1806f6..0e31a3ef8 100644 --- a/lib/base/process.hpp +++ b/lib/base/process.hpp @@ -97,6 +97,8 @@ private: static void IOThreadProc(int tid); bool DoEvents(void); int GetTID(void) const; + + String PrettyPrintArguments(void) const; }; } -- 2.40.0