Change log level for failed commands

fixes #6751
This commit is contained in:
Gunnar Beutner 2014-08-19 12:58:55 +02:00
parent 91a7d0afb1
commit d4cdee6a1a
2 changed files with 22 additions and 10 deletions

View File

@ -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<void(const ProcessResult&)>& callback) void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
{ {
boost::call_once(l_OnceFlag, &Process::ThreadInitialize); boost::call_once(l_OnceFlag, &Process::ThreadInitialize);
@ -427,8 +436,8 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
m_FD = outReadPipe; m_FD = outReadPipe;
m_PID = pi.dwProcessId; m_PID = pi.dwProcessId;
Log(LogNotice, "Process", "Running command '" + m_Arguments + Log(LogNotice, "Process", "Running command " + PrettyPrintArguments() +
"': PID " + Convert::ToString(m_PID)); ": PID " + Convert::ToString(m_PID));
#else /* _WIN32 */ #else /* _WIN32 */
int fds[2]; int fds[2];
@ -533,10 +542,7 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
m_PID = m_Process; m_PID = m_Process;
Log(LogNotice, "Process", "Running command '" + boost::algorithm::join(m_Arguments, "', '") + Log(LogNotice, "Process", "Running command " + PrettyPrintArguments() + ": PID " + Convert::ToString(m_PID));
"': PID " + Convert::ToString(m_PID));
m_Arguments.clear();
// free arguments // free arguments
for (int i = 0; argv[i] != NULL; i++) for (int i = 0; argv[i] != NULL; i++)
@ -585,7 +591,8 @@ bool Process::DoEvents(void)
double timeout = m_Result.ExecutionStart + m_Timeout; double timeout = m_Result.ExecutionStart + m_Timeout;
if (timeout < Utility::GetTime()) { 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 << "<Timeout exceeded.>"; m_OutputStream << "<Timeout exceeded.>";
#ifdef _WIN32 #ifdef _WIN32
@ -633,7 +640,8 @@ bool Process::DoEvents(void)
DWORD exitcode; DWORD exitcode;
GetExitCodeProcess(m_Process, &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 */ #else /* _WIN32 */
int status, exitcode; int status, exitcode;
if (waitpid(m_Process, &status, 0) != m_Process) { if (waitpid(m_Process, &status, 0) != m_Process) {
@ -645,9 +653,11 @@ bool Process::DoEvents(void)
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(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)) { } 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; std::ostringstream outputbuf;
outputbuf << "<Terminated by signal " << WTERMSIG(status) << ".>"; outputbuf << "<Terminated by signal " << WTERMSIG(status) << ".>";

View File

@ -97,6 +97,8 @@ private:
static void IOThreadProc(int tid); static void IOThreadProc(int tid);
bool DoEvents(void); bool DoEvents(void);
int GetTID(void) const; int GetTID(void) const;
String PrettyPrintArguments(void) const;
}; };
} }