From 0bc758d34a4940796c7f6a2c49e592ff3ef93a6b Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Tue, 27 Oct 2020 18:31:11 +0330 Subject: [PATCH] Shell: Run builtins that cannot be run in the main process in a new child e.g. `$(jobs | wc -l)` would blow up horribly otherwise. (it still does) --- Shell/Shell.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 874d4e0a68..539fd19e84 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -562,13 +562,8 @@ RefPtr Shell::run_command(const AST::Command& command) { FileDescriptionCollector fds; - if (options.verbose) { - fprintf(stderr, "+ "); - for (auto& arg : command.argv) - fprintf(stderr, "%s ", escape_token(arg).characters()); - fprintf(stderr, "\n"); - fflush(stderr); - } + if (options.verbose) + warnln("+ {}", m_pid, command); // If the command is empty, store the redirections and apply them to all later commands. if (command.argv.is_empty() && !command.should_immediately_execute_next) { @@ -642,7 +637,7 @@ RefPtr Shell::run_command(const AST::Command& command) return nullptr; } - if (run_builtin(command, rewirings, last_return_code)) { + if (command.should_wait && run_builtin(command, rewirings, last_return_code)) { for (auto& next_in_chain : command.next_chain) run_tail(command, next_in_chain, last_return_code); return nullptr; @@ -694,7 +689,6 @@ RefPtr Shell::run_command(const AST::Command& command) m_is_subshell = true; m_pid = getpid(); Core::EventLoop::notify_forked(Core::EventLoop::ForkEvent::Child); - jobs.clear(); if (apply_rewirings() == IterationDecision::Break) _exit(126); @@ -732,9 +726,15 @@ RefPtr Shell::run_command(const AST::Command& command) _exit(last_return_code); } + if (run_builtin(command, {}, last_return_code)) + _exit(last_return_code); + if (invoke_function(command, last_return_code)) _exit(last_return_code); + // We no longer need the jobs here. + jobs.clear(); + int rc = execvp(argv[0], const_cast(argv.data())); if (rc < 0) { if (errno == ENOENT) {