mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Merge pull request #47973 from socketpair/exitcode
Fix #36971: Watchdog: exit with non-zero code if child process exits
This commit is contained in:
commit
3eb2a1cc5b
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user