This commit is contained in:
Alexey Milovidov 2021-01-07 21:36:38 +03:00
parent 80d88a7b17
commit 32d8785a26
3 changed files with 9 additions and 6 deletions

View File

@ -493,8 +493,9 @@ void BaseDaemon::kill()
{
dumpCoverageReportIfPossible();
pid_file.reset();
if (::raise(SIGKILL) != 0)
throw Poco::SystemException("cannot kill process");
/// Exit with the same code as it is usually set by shell when process is terminated by SIGKILL.
/// It's better than doing 'raise' or 'kill', because they have no effect for 'init' process (with pid = 0, usually in Docker).
_exit(128 + SIGKILL);
}
std::string BaseDaemon::getDefaultCorePath() const

View File

@ -60,7 +60,7 @@ public:
static void terminate();
/// Forceful shutdown
void kill();
[[noreturn]] void kill();
/// Cancellation request has been received.
bool isCancelled() const

View File

@ -227,9 +227,11 @@ BlockIO InterpreterSystemQuery::execute()
break;
case Type::KILL:
context.checkAccess(AccessType::SYSTEM_SHUTDOWN);
if (kill(0, SIGKILL))
throwFromErrno("System call kill(0, SIGKILL) failed", ErrorCodes::CANNOT_KILL);
break;
/// Exit with the same code as it is usually set by shell when process is terminated by SIGKILL.
/// It's better than doing 'raise' or 'kill', because they have no effect for 'init' process (with pid = 0, usually in Docker).
LOG_INFO(log, "Exit immediately as the SYSTEM KILL command has been issued.");
_exit(128 + SIGKILL);
// break; /// unreachable
case Type::DROP_DNS_CACHE:
context.checkAccess(AccessType::SYSTEM_DROP_DNS_CACHE);
DNSResolver::instance().dropCache();