fix(runtime): grab terminal even if error occured

This commit is contained in:
buffet 2022-09-23 22:03:10 +00:00
parent f0698457ed
commit 924a7462bd

View file

@ -101,8 +101,9 @@ impl Shell {
&mut self,
pipeline: &ast::Pipeline,
) -> Result<Status, RuntimeError> {
let mut cmds = pipeline.0.iter().map(PreparedCommand::from);
let mut pgid = Pid::from_raw(0);
let status = (|| {
let mut cmds = pipeline.0.iter().map(PreparedCommand::from);
let mut last_cmd = cmds.next().expect("pipelines need to have >1 commands");
for mut cmd in cmds {
@ -121,12 +122,12 @@ impl Shell {
last_cmd.spawn(&mut pgid)?;
// TODO: kill children if error occured
wait_pgid(pgid)
})();
let status = wait_pgid(pgid)?;
let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpgid(None).unwrap());
Ok(status)
status
}
}