fix(runtime): grab terminal even if error occured
This commit is contained in:
parent
f0698457ed
commit
924a7462bd
1 changed files with 17 additions and 16 deletions
|
@ -101,32 +101,33 @@ 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 {
|
||||
let (output, input) = create_pipe()?;
|
||||
cmd.stdin = Some(output);
|
||||
let mut last_cmd = cmds.next().expect("pipelines need to have >1 commands");
|
||||
for mut cmd in cmds {
|
||||
let (output, input) = create_pipe()?;
|
||||
cmd.stdin = Some(output);
|
||||
|
||||
match last_cmd.redirect {
|
||||
Redirect::None => (),
|
||||
Redirect::Stdout => last_cmd.stdout = Some(input),
|
||||
match last_cmd.redirect {
|
||||
Redirect::None => (),
|
||||
Redirect::Stdout => last_cmd.stdout = Some(input),
|
||||
}
|
||||
|
||||
last_cmd.spawn(&mut pgid)?;
|
||||
|
||||
last_cmd = cmd;
|
||||
}
|
||||
|
||||
last_cmd.spawn(&mut pgid)?;
|
||||
|
||||
last_cmd = cmd;
|
||||
}
|
||||
wait_pgid(pgid)
|
||||
})();
|
||||
|
||||
last_cmd.spawn(&mut pgid)?;
|
||||
|
||||
// TODO: kill children if error occured
|
||||
|
||||
let status = wait_pgid(pgid)?;
|
||||
let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpgid(None).unwrap());
|
||||
|
||||
Ok(status)
|
||||
status
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue