do away with wierd process waits

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2024-08-07 10:28:39 -07:00
parent 48178b5a48
commit 1993f39d93

View file

@ -42,9 +42,7 @@ use {
env::set_current_dir, env::set_current_dir,
os::unix::process::CommandExt, os::unix::process::CommandExt,
mem, mem,
thread,
process, process,
time::Duration,
}, },
nix::{ nix::{
unistd, unistd::Pid, unistd, unistd::Pid,
@ -228,31 +226,25 @@ fn make_foreground(pid: u32, state: &mut ShellState) -> Result<(), String> {
loop { loop {
match i.try_wait() { match i.wait() {
Ok(maybe) => { Ok(maybe) => {
if let Some(exit) = maybe { if let Err(e) = unistd::tcsetpgrp(0, state.parent_pid) {
if let Err(e) = unistd::tcsetpgrp(0, state.parent_pid) { return Err(format!(
return Err(format!( "error re-acquiring terminal: {}!", e
"error re-acquiring terminal: {}!", e ));
));
}
// TODO: this could be more elegant
if let Some(ref attr) = state.attr {
tcsetattr(0, SetArg::TCSADRAIN, attr).ok();
} else {
panic!("somehow no attrs")
}
state.last_exit_code = exit
.code()
.unwrap_or(-1);
break;
} else {
// sleep 1 sec
thread::sleep(Duration::from_millis(1000));
} }
if let Some(ref attr) = state.attr {
tcsetattr(0, SetArg::TCSADRAIN, attr).ok();
} else {
panic!("somehow no attrs")
}
state.last_exit_code = maybe
.code()
.unwrap_or(-1);
break;
}, },
Err(e) => { Err(e) => {
return Err(format!("error waiting on child: {}", e)) return Err(format!("error waiting on child: {}", e))