diff --git a/Shell/Builtin.cpp b/Shell/Builtin.cpp index 895c4a3b9c..9c2ab6d06f 100644 --- a/Shell/Builtin.cpp +++ b/Shell/Builtin.cpp @@ -27,6 +27,7 @@ #include "Shell.h" #include #include +#include #include #include #include @@ -830,6 +831,9 @@ bool Shell::run_builtin(const AST::Command& command, const NonnullRefPtrVectorset_is_suspended(true); - job->unblock(); - } - }); + Core::EventLoop::register_signal(SIGTSTP, [this](auto) { + auto job = current_job(); + kill_job(job, SIGTSTP); + if (job) { + job->set_is_suspended(true); + job->unblock(); + } + }); + } } void Shell::print_path(const String& path) @@ -484,6 +486,9 @@ bool Shell::invoke_function(const AST::Command& command, int& retval) argv.take_first(); set_local_variable("ARGV", adopt(*new AST::ListValue(move(argv))), true); + Core::EventLoop loop; + setup_signals(); + function.body->run(*this); retval = last_return_code; @@ -670,6 +675,8 @@ RefPtr Shell::run_command(const AST::Command& command) return IterationDecision::Continue; }; + TemporaryChange signal_handler_install { m_should_reinstall_signal_handlers, false }; + for (auto& redirection : m_global_redirections) { if (resolve_redirection(redirection) == IterationDecision::Break) return nullptr; @@ -732,6 +739,7 @@ RefPtr Shell::run_command(const AST::Command& command) m_is_subshell = true; m_pid = getpid(); Core::EventLoop::notify_forked(Core::EventLoop::ForkEvent::Child); + TemporaryChange signal_handler_install { m_should_reinstall_signal_handlers, true }; if (apply_rewirings() == IterationDecision::Break) _exit(126); @@ -756,12 +764,12 @@ RefPtr Shell::run_command(const AST::Command& command) if (!m_is_subshell && command.should_wait) tcsetattr(0, TCSANOW, &default_termios); - Core::EventLoop mainloop; - setup_signals(); - if (command.should_immediately_execute_next) { ASSERT(command.argv.is_empty()); + Core::EventLoop mainloop; + setup_signals(); + for (auto& next_in_chain : command.next_chain) run_tail(command, next_in_chain, 0); diff --git a/Shell/Shell.h b/Shell/Shell.h index ebe46e1cf8..eca2f47a20 100644 --- a/Shell/Shell.h +++ b/Shell/Shell.h @@ -260,6 +260,7 @@ private: HashMap m_aliases; bool m_is_interactive { true }; bool m_is_subshell { false }; + bool m_should_reinstall_signal_handlers { true }; bool m_should_format_live { false };