Explorar o código

Shell: Handle signals asynchronously

Fixes #2717
Tom %!s(int64=5) %!d(string=hai) anos
pai
achega
6dfd503518
Modificáronse 3 ficheiros con 7 adicións e 17 borrados
  1. 0 3
      Shell/Shell.cpp
  2. 0 3
      Shell/Shell.h
  3. 7 11
      Shell/main.cpp

+ 0 - 3
Shell/Shell.cpp

@@ -516,9 +516,6 @@ void Shell::restore_stdin()
 
 void Shell::block_on_job(RefPtr<Job> job)
 {
-    ScopedValueRollback accepting_signal_rollback(m_is_accepting_signals);
-    m_is_accepting_signals = false;
-
     if (!job)
         return;
 

+ 0 - 3
Shell/Shell.h

@@ -72,8 +72,6 @@ public:
     constexpr static auto local_init_file_path = "~/.shellrc";
     constexpr static auto global_init_file_path = "/etc/shellrc";
 
-    bool is_accepting_signals() const { return m_is_accepting_signals; }
-
     int run_command(const StringView&);
     RefPtr<Job> run_command(AST::Command&);
     bool run_file(const String&, bool explicitly_invoked = true);
@@ -183,7 +181,6 @@ private:
 
     StringBuilder m_complete_line_builder;
     bool m_should_ignore_jobs_on_next_exit { false };
-    bool m_is_accepting_signals { true };
     pid_t m_pid { 0 };
 
     HashMap<String, RefPtr<AST::Value>> m_local_variables;

+ 7 - 11
Shell/main.cpp

@@ -60,26 +60,22 @@ int main(int argc, char** argv)
 {
     Core::EventLoop loop;
 
-    signal(SIGINT, [](int) {
-        if (!s_shell->is_accepting_signals())
-            return;
+    Core::EventLoop::register_signal(SIGINT, [](int) {
         editor->interrupted();
     });
 
-    signal(SIGWINCH, [](int) {
+    Core::EventLoop::register_signal(SIGWINCH, [](int) {
         editor->resized();
     });
 
-    signal(SIGTTIN, [](int) {});
-    signal(SIGTTOU, [](int) {});
+    Core::EventLoop::register_signal(SIGTTIN, [](int) {});
+    Core::EventLoop::register_signal(SIGTTOU, [](int) {});
 
-    signal(SIGHUP, [](int) {
-        if (!s_shell->is_accepting_signals())
-            return;
+    Core::EventLoop::register_signal(SIGHUP, [](int) {
         s_shell->save_history();
     });
 
-    signal(SIGCHLD, [](int) {
+    Core::EventLoop::register_signal(SIGCHLD, [](int) {
         auto& jobs = s_shell->jobs;
         Vector<u64> disowned_jobs;
         for (auto& job : jobs) {
@@ -116,7 +112,7 @@ int main(int argc, char** argv)
     });
 
     // Ignore SIGTSTP as the shell should not be suspended with ^Z.
-    signal(SIGTSTP, [](auto) {});
+    Core::EventLoop::register_signal(SIGTSTP, [](auto) {});
 
 #ifndef __serenity__
     sigset_t blocked;