diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs index 2a94989ee07f1b5619ced249eeb70fc8a82ce236..8ef3658c15c4f93a61dcf5a67678caaa1b17aa72 100644 --- a/src/lib/builtins/mod.rs +++ b/src/lib/builtins/mod.rs @@ -666,8 +666,11 @@ DESCRIPTION Wait for the background jobs to finish" )] pub fn wait(args: &[types::Str], shell: &mut Shell<'_>) -> Status { - let _ = shell.wait_for_background(); - Status::SUCCESS + if let Err(err) = shell.wait_for_background() { + Status::error(err.to_string()) + } else { + Status::SUCCESS + } } #[builtin( diff --git a/src/lib/shell/pipe_exec/job_control.rs b/src/lib/shell/pipe_exec/job_control.rs index 4850247eae1273e81f8fb6049f3f5a2b0d16ef0f..d25a9dad7845cc9452f09f51c47d59b59cfbe295 100644 --- a/src/lib/shell/pipe_exec/job_control.rs +++ b/src/lib/shell/pipe_exec/job_control.rs @@ -293,10 +293,10 @@ impl<'a> Shell<'a> { /// Waits until all running background tasks have completed, and listens for signals in the /// event that a signal is sent to kill the running tasks. pub fn wait_for_background(&mut self) -> Result<(), PipelineError> { - while let Some(p) = { self.background_jobs().iter().find(|p| p.is_running()) } { + while { self.background_jobs().iter().any(BackgroundProcess::is_running) } { if let Some(signal) = signals::SignalHandler.find(|&s| s != Signal::SIGTSTP) { self.background_send(signal).map_err(PipelineError::KillFailed)?; - return Err(PipelineError::Interrupted(p.pid(), signal)); + return Err(PipelineError::Interrupted(Pid::this(), signal)); } sleep(Duration::from_millis(100)); }