diff options
author | antervis <antervis@yandex-team.com> | 2023-09-15 00:10:15 +0300 |
---|---|---|
committer | antervis <antervis@yandex-team.com> | 2023-09-15 00:33:34 +0300 |
commit | 0ab3867bbe71ae4307ff4d22ae48c4a097d3eb7f (patch) | |
tree | be14d445618b0e4806264a7dc0a11c8ef11869ea /util | |
parent | 09cfb2c95783f076ce68a8995125d73fbffcf0d9 (diff) | |
download | ydb-0ab3867bbe71ae4307ff4d22ae48c4a097d3eb7f.tar.gz |
util/system/shellcommand: customize signal to terminate process with
Diffstat (limited to 'util')
-rw-r--r-- | util/system/shellcommand.cpp | 16 | ||||
-rw-r--r-- | util/system/shellcommand.h | 2 |
2 files changed, 9 insertions, 9 deletions
diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index 025a3ffd2f..6742f46c64 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -355,18 +355,18 @@ public: // start child process void Run(); - inline void Terminate() { + inline void Terminate(int signal) { if (!!Pid && (ExecutionStatus.load(std::memory_order_acquire) == SHELL_RUNNING)) { - bool ok = #if defined(_unix_) - kill(Options_.DetachSession ? -1 * Pid : Pid, SIGTERM) == 0; + bool ok = kill(Options_.DetachSession ? -1 * Pid : Pid, signal) == 0; if (!ok && (errno == ESRCH) && Options_.DetachSession) { // this could fail when called before child proc completes setsid(). - ok = kill(Pid, SIGTERM) == 0; - kill(-Pid, SIGTERM); // between a failed kill(-Pid) and a successful kill(Pid) a grandchild could have been spawned + ok = kill(Pid, signal) == 0; + kill(-Pid, signal); // between a failed kill(-Pid) and a successful kill(Pid) a grandchild could have been spawned } #else - TerminateProcess(Pid, 1 /* exit code */); + Y_UNUSED(signal); + bool ok = TerminateProcess(Pid, 1 /* exit code */); #endif if (!ok) { ythrow TSystemError() << "cannot terminate " << Pid; @@ -1146,8 +1146,8 @@ TShellCommand& TShellCommand::Run() { return *this; } -TShellCommand& TShellCommand::Terminate() { - Impl->Terminate(); +TShellCommand& TShellCommand::Terminate(int signal) { + Impl->Terminate(signal); return *this; } diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index 1b1f2bc927..6c2b9e276c 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -466,7 +466,7 @@ public: * * @return self */ - TShellCommand& Terminate(); + TShellCommand& Terminate(int signal = SIGTERM); /** * @brief wait until the execution is finished |