From 82d9750351681d36c0f252428cc56e41f75bb7fc Mon Sep 17 00:00:00 2001 From: Xavier L'Heureux <xavier.lheureux@icloud.com> Date: Tue, 9 Jul 2019 09:39:18 -0400 Subject: [PATCH] improv: Reduce lock contention in wait to make it responsive to ctrl-c --- src/lib/builtins/mod.rs | 7 +++++-- src/lib/shell/pipe_exec/job_control.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs index 2a94989e..8ef3658c 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 4850247e..d25a9dad 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)); } -- GitLab