1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

Shell: Wait for the rest of the members of a pipeline when one exits

Assuming we were blocking on one to begin with.
This commit is contained in:
AnotherTest 2020-10-28 17:45:17 +03:30 committed by Andreas Kling
parent c92865bd05
commit 6e2a383f25
2 changed files with 16 additions and 0 deletions

View file

@ -950,6 +950,17 @@ void Shell::restore_ios()
tcsetpgrp(STDIN_FILENO, m_pid); tcsetpgrp(STDIN_FILENO, m_pid);
} }
void Shell::block_on_pipeline(RefPtr<AST::Pipeline> 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> job) void Shell::block_on_job(RefPtr<Job> job)
{ {
TemporaryChange<const Job*> current_job { m_current_job, job.ptr() }; TemporaryChange<const Job*> current_job { m_current_job, job.ptr() };
@ -977,6 +988,10 @@ void Shell::block_on_job(RefPtr<Job> job)
return; return;
loop.exec(); 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() String Shell::get_history_path()

View file

@ -89,6 +89,7 @@ public:
bool run_builtin(const AST::Command&, const NonnullRefPtrVector<AST::Rewiring>&, int& retval); bool run_builtin(const AST::Command&, const NonnullRefPtrVector<AST::Rewiring>&, int& retval);
bool has_builtin(const StringView&) const; bool has_builtin(const StringView&) const;
void block_on_job(RefPtr<Job>); void block_on_job(RefPtr<Job>);
void block_on_pipeline(RefPtr<AST::Pipeline>);
String prompt() const; String prompt() const;
static String expand_tilde(const String&); static String expand_tilde(const String&);