From f8c10dd1fc55e60f35286475356e48c4f642eb63 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 6 Feb 2023 00:18:47 +0800 Subject: import(life): linux-run: Reap child when timeout. --- works/life/linux-run/linux-run.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'works/life') 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 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) { -- cgit v1.2.3