Merge pull request #47973 from socketpair/exitcode

Fix #36971: Watchdog: exit with non-zero code if child process exits
This commit is contained in:
Alexander Gololobov 2023-03-24 22:26:44 +01:00 committed by GitHub
commit 3eb2a1cc5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1125,16 +1125,21 @@ void BaseDaemon::setupWatchdog()
logger().information("Child process no longer exists.");
_exit(WEXITSTATUS(status));
}
else if (WIFEXITED(status))
if (WIFEXITED(status))
{
logger().information(fmt::format("Child process exited normally with code {}.", WEXITSTATUS(status)));
_exit(WEXITSTATUS(status));
}
int exit_code;
if (WIFSIGNALED(status))
{
int sig = WTERMSIG(status);
exit_code = 128 + sig;
if (sig == SIGKILL)
{
logger().fatal(fmt::format("Child process was terminated by signal {} (KILL)."
@ -1146,12 +1151,14 @@ void BaseDaemon::setupWatchdog()
logger().fatal(fmt::format("Child process was terminated by signal {}.", sig));
if (sig == SIGINT || sig == SIGTERM || sig == SIGQUIT)
_exit(128 + sig);
_exit(exit_code);
}
}
else
{
// According to POSIX, this should never happen.
logger().fatal("Child process was not exited normally by unknown reason.");
exit_code = 42;
}
if (restart)
@ -1161,7 +1168,7 @@ void BaseDaemon::setupWatchdog()
memcpy(argv0, original_process_name.c_str(), original_process_name.size());
}
else
_exit(WEXITSTATUS(status));
_exit(exit_code);
}
}