From 1993f39d933531696c86a4aaf055602974673995 Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Wed, 7 Aug 2024 10:28:39 -0700 Subject: [PATCH] do away with wierd process waits Signed-off-by: Ava Affine --- shell/src/posix.rs | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/shell/src/posix.rs b/shell/src/posix.rs index a5d022c..0676436 100644 --- a/shell/src/posix.rs +++ b/shell/src/posix.rs @@ -42,9 +42,7 @@ use { env::set_current_dir, os::unix::process::CommandExt, mem, - thread, process, - time::Duration, }, nix::{ unistd, unistd::Pid, @@ -228,31 +226,25 @@ fn make_foreground(pid: u32, state: &mut ShellState) -> Result<(), String> { loop { - match i.try_wait() { + match i.wait() { Ok(maybe) => { - if let Some(exit) = maybe { - if let Err(e) = unistd::tcsetpgrp(0, state.parent_pid) { - return Err(format!( - "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 Err(e) = unistd::tcsetpgrp(0, state.parent_pid) { + return Err(format!( + "error re-acquiring terminal: {}!", e + )); } + + 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) => { return Err(format!("error waiting on child: {}", e))