feat(runtime): kill existing processes on error

This commit is contained in:
buffet 2022-09-23 22:04:16 +00:00
parent 924a7462bd
commit c1881bb7b2

View file

@ -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