From 6e2a383f25b1d25e04571f794d84bb309948fffb Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 28 Oct 2020 17:45:17 +0330 Subject: [PATCH] Shell: Wait for the rest of the members of a pipeline when one exits Assuming we were blocking on one to begin with. --- Shell/Shell.cpp | 15 +++++++++++++++ Shell/Shell.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 5313ac52c4..3eaeccec4b 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -950,6 +950,17 @@ void Shell::restore_ios() tcsetpgrp(STDIN_FILENO, m_pid); } +void Shell::block_on_pipeline(RefPtr pipeline) +{ + if (!pipeline) + return; + + for (auto& it : jobs) { + if (auto cmd = it.value->command_ptr(); cmd->pipeline == pipeline && cmd->is_pipe_source) + block_on_job(it.value); + } +} + void Shell::block_on_job(RefPtr job) { TemporaryChange current_job { m_current_job, job.ptr() }; @@ -977,6 +988,10 @@ void Shell::block_on_job(RefPtr job) return; loop.exec(); + + // If the job is part of a pipeline, wait for the rest of the members too. + if (auto command = job->command_ptr()) + block_on_pipeline(command->pipeline); } String Shell::get_history_path() diff --git a/Shell/Shell.h b/Shell/Shell.h index fc0b5258dd..65d49cff91 100644 --- a/Shell/Shell.h +++ b/Shell/Shell.h @@ -89,6 +89,7 @@ public: bool run_builtin(const AST::Command&, const NonnullRefPtrVector&, int& retval); bool has_builtin(const StringView&) const; void block_on_job(RefPtr); + void block_on_pipeline(RefPtr); String prompt() const; static String expand_tilde(const String&);