From c1881bb7b233244968ab4c5fadea706b4ec58c41 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Fri, 23 Sep 2022 22:04:16 +0000 Subject: [PATCH] feat(runtime): kill existing processes on error --- crates/oyster_runtime/src/pipeline.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/oyster_runtime/src/pipeline.rs b/crates/oyster_runtime/src/pipeline.rs index 347315b..8bc5e0f 100644 --- a/crates/oyster_runtime/src/pipeline.rs +++ b/crates/oyster_runtime/src/pipeline.rs @@ -12,7 +12,10 @@ use nix::{ errno::Errno, fcntl::OFlag, libc, - sys::wait::{self, WaitPidFlag, WaitStatus}, + sys::{ + signal, + wait::{self, WaitPidFlag, WaitStatus}, + }, unistd::{self, Pid}, }; use oyster_parser::ast::{self, Redirect}; @@ -125,6 +128,11 @@ impl Shell { wait_pgid(pgid) })(); + if status.is_err() && pgid != Pid::from_raw(0) { + let _ = signal::killpg(pgid, signal::Signal::SIGTERM); + let _ = signal::killpg(pgid, signal::Signal::SIGCONT); + } + let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpgid(None).unwrap()); status