summaryrefslogtreecommitdiff
path: root/Shell
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-10-26 02:31:29 +0330
committerAndreas Kling <kling@serenityos.org>2020-10-26 14:28:38 +0100
commit5a4673d46855a0fa85381fecd8bd4f49735c1d18 (patch)
tree6ba08bfc9ba1f4e5028ec08f754ccbb9fce695b7 /Shell
parent9ad858bcbf7382062e9e011a1becba171268dbfe (diff)
downloadserenity-5a4673d46855a0fa85381fecd8bd4f49735c1d18.zip
Shell: Ensure that jobs going through run_tail() retain should_wait
This allows putting logic in the background as well.
Diffstat (limited to 'Shell')
-rw-r--r--Shell/Shell.cpp16
-rw-r--r--Shell/Shell.h2
2 files changed, 10 insertions, 8 deletions
diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp
index 7d73eece36..7294d65fa9 100644
--- a/Shell/Shell.cpp
+++ b/Shell/Shell.cpp
@@ -644,7 +644,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
if (run_builtin(command, rewirings, last_return_code)) {
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;
}
@@ -662,7 +662,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
if (invoke_function(command, last_return_code)) {
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;
}
}
@@ -727,7 +727,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
ASSERT(command.argv.is_empty());
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);
}
@@ -825,15 +825,17 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
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 = [&] {
if (next_in_chain.node->would_execute()) {
next_in_chain.node->run(*this);
return;
}
- auto commands = next_in_chain.node->to_lazy_evaluated_commands(*this);
- run_commands(commands);
+ auto node = next_in_chain.node;
+ 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) {
case AST::NodeWithAction::And:
@@ -855,7 +857,7 @@ void Shell::run_tail(RefPtr<Job> job)
if (auto cmd = job->command_ptr()) {
deferred_invoke([=, this](auto&) {
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());
}
});
}
diff --git a/Shell/Shell.h b/Shell/Shell.h
index d485979c73..7b4a37dce3 100644
--- a/Shell/Shell.h
+++ b/Shell/Shell.h
@@ -215,7 +215,7 @@ private:
LocalFrame* find_frame_containing_local_variable(const String& name);
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;