aboutsummaryrefslogtreecommitdiff
path: root/linux-run/linux-run.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-02-06 00:18:47 +0800
committercrupest <crupest@outlook.com>2023-02-06 00:18:47 +0800
commit56f5591ce51b37098d8829f805f0778b36ec18cb (patch)
tree0c5ffd9d86ce4a002a7c70899eef5a39b4d2efac /linux-run/linux-run.cpp
parent9322433fa910acace9b6bd1687cabde25f7c14f9 (diff)
downloadlife-56f5591ce51b37098d8829f805f0778b36ec18cb.tar.gz
life-56f5591ce51b37098d8829f805f0778b36ec18cb.tar.bz2
life-56f5591ce51b37098d8829f805f0778b36ec18cb.zip
linux-run: Reap child when timeout.main
Diffstat (limited to 'linux-run/linux-run.cpp')
-rw-r--r--linux-run/linux-run.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/linux-run/linux-run.cpp b/linux-run/linux-run.cpp
index dcb9944..0c3ab15 100644
--- a/linux-run/linux-run.cpp
+++ b/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) {