From a55939e46266a54d7fd5c4ec2df0f69e48eea545 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Tue, 27 Jul 2021 09:26:38 +0200 Subject: [PATCH] Override exit code on process timeout As Icinga first sends a SIGTERM to a check plugin on timeout to allow it to terminate gracefully, this is not really part of the plugin API specification and we cannot assume that plugins will handle this correctly and still exit with an exit code that maps to UNKNOWN. Therefore, once Icinga decides to kill a process, force its exit code to 128 to be sure the state will be UNKNOWN after a timeout. --- lib/base/process.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 53af4ffd2..7aa7972cb 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -1133,8 +1133,14 @@ bool Process::DoEvents() } else if (WIFEXITED(status)) { exitcode = WEXITSTATUS(status); - Log(LogNotice, "Process") - << "PID " << m_PID << " (" << PrettyPrintArguments(m_Arguments) << ") terminated with exit code " << exitcode; + Log msg(LogNotice, "Process"); + msg << "PID " << m_PID << " (" << PrettyPrintArguments(m_Arguments) + << ") terminated with exit code " << exitcode; + + if (m_SentSigterm) { + exitcode = 128; + msg << " after sending SIGTERM"; + } } else if (WIFSIGNALED(status)) { int signum = WTERMSIG(status); const char *zsigname = strsignal(signum);