diff options
author | crupest <crupest@outlook.com> | 2023-02-06 00:18:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-02-06 00:18:47 +0800 |
commit | f8c10dd1fc55e60f35286475356e48c4f642eb63 (patch) | |
tree | 19fd087a966fbb7f3abca3df14c8c95acd5b04d5 /works/life | |
parent | 1325a030509f252ba77c1b6787c18d774513bac0 (diff) | |
download | crupest-f8c10dd1fc55e60f35286475356e48c4f642eb63.tar.gz crupest-f8c10dd1fc55e60f35286475356e48c4f642eb63.tar.bz2 crupest-f8c10dd1fc55e60f35286475356e48c4f642eb63.zip |
import(life): linux-run: Reap child when timeout.
Diffstat (limited to 'works/life')
-rw-r--r-- | works/life/linux-run/linux-run.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/works/life/linux-run/linux-run.cpp b/works/life/linux-run/linux-run.cpp index dcb9944..0c3ab15 100644 --- a/works/life/linux-run/linux-run.cpp +++ b/works/life/linux-run/linux-run.cpp @@ -132,6 +132,20 @@ void run(const std::string &program, std::vector<std::string> arguments, if (poll_return == 0) { kill(pid, SIGKILL); + + if (options.stop_reason) { + *options.stop_reason = StopReason::Killed; + } + + if (options.before_reap_callback) { + options.before_reap_callback(pid); + } + + // Reap child process. + if (waitpid(pid, nullptr, 0) == -1) { + throw std::runtime_error("Failed to reap child process. Reason: " + + get_errno_message()); + } throw TimeoutError("Timeout to run command."); } else if (poll_return == -1) { if (errno == EINTR) { |