mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
Shell: Ensure that jobs going through run_tail() retain should_wait
This allows putting logic in the background as well.
This commit is contained in:
parent
9ad858bcbf
commit
5a4673d468
2 changed files with 10 additions and 8 deletions
|
@ -644,7 +644,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
|
|
||||||
if (run_builtin(command, rewirings, last_return_code)) {
|
if (run_builtin(command, rewirings, last_return_code)) {
|
||||||
for (auto& next_in_chain : command.next_chain)
|
for (auto& next_in_chain : command.next_chain)
|
||||||
run_tail(next_in_chain, last_return_code);
|
run_tail(command, next_in_chain, last_return_code);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,7 +662,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
|
|
||||||
if (invoke_function(command, last_return_code)) {
|
if (invoke_function(command, last_return_code)) {
|
||||||
for (auto& next_in_chain : command.next_chain)
|
for (auto& next_in_chain : command.next_chain)
|
||||||
run_tail(next_in_chain, last_return_code);
|
run_tail(command, next_in_chain, last_return_code);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -727,7 +727,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
ASSERT(command.argv.is_empty());
|
ASSERT(command.argv.is_empty());
|
||||||
|
|
||||||
for (auto& next_in_chain : command.next_chain)
|
for (auto& next_in_chain : command.next_chain)
|
||||||
run_tail(next_in_chain, 0);
|
run_tail(command, next_in_chain, 0);
|
||||||
|
|
||||||
_exit(last_return_code);
|
_exit(last_return_code);
|
||||||
}
|
}
|
||||||
|
@ -825,15 +825,17 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
return *job;
|
return *job;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shell::run_tail(const AST::NodeWithAction& next_in_chain, int head_exit_code)
|
void Shell::run_tail(const AST::Command& invoking_command, const AST::NodeWithAction& next_in_chain, int head_exit_code)
|
||||||
{
|
{
|
||||||
auto evaluate = [&] {
|
auto evaluate = [&] {
|
||||||
if (next_in_chain.node->would_execute()) {
|
if (next_in_chain.node->would_execute()) {
|
||||||
next_in_chain.node->run(*this);
|
next_in_chain.node->run(*this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto commands = next_in_chain.node->to_lazy_evaluated_commands(*this);
|
auto node = next_in_chain.node;
|
||||||
run_commands(commands);
|
if (!invoking_command.should_wait)
|
||||||
|
node = adopt(static_cast<AST::Node&>(*new AST::Background(next_in_chain.node->position(), move(node))));
|
||||||
|
adopt(static_cast<AST::Node&>(*new AST::Execute(next_in_chain.node->position(), move(node))))->run(*this);
|
||||||
};
|
};
|
||||||
switch (next_in_chain.action) {
|
switch (next_in_chain.action) {
|
||||||
case AST::NodeWithAction::And:
|
case AST::NodeWithAction::And:
|
||||||
|
@ -855,7 +857,7 @@ void Shell::run_tail(RefPtr<Job> job)
|
||||||
if (auto cmd = job->command_ptr()) {
|
if (auto cmd = job->command_ptr()) {
|
||||||
deferred_invoke([=, this](auto&) {
|
deferred_invoke([=, this](auto&) {
|
||||||
for (auto& next_in_chain : cmd->next_chain) {
|
for (auto& next_in_chain : cmd->next_chain) {
|
||||||
run_tail(next_in_chain, job->exit_code());
|
run_tail(*cmd, next_in_chain, job->exit_code());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ private:
|
||||||
LocalFrame* find_frame_containing_local_variable(const String& name);
|
LocalFrame* find_frame_containing_local_variable(const String& name);
|
||||||
|
|
||||||
void run_tail(RefPtr<Job>);
|
void run_tail(RefPtr<Job>);
|
||||||
void run_tail(const AST::NodeWithAction&, int head_exit_code);
|
void run_tail(const AST::Command&, const AST::NodeWithAction&, int head_exit_code);
|
||||||
|
|
||||||
virtual void custom_event(Core::CustomEvent&) override;
|
virtual void custom_event(Core::CustomEvent&) override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue