diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-05-26 18:45:19 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-27 11:13:02 +0200 |
commit | d5e9213683591edb394b5252b418695650e07dc8 (patch) | |
tree | 3b80c1f8513f5d1d66e840e101148a04bce24d89 | |
parent | 70a213a6ec19aeee99af6a747c5b12890c038690 (diff) | |
download | serenity-d5e9213683591edb394b5252b418695650e07dc8.zip |
Shell: Avoid messing with sigaction while waiting for a child
-rw-r--r-- | Shell/Shell.cpp | 14 | ||||
-rw-r--r-- | Shell/Shell.h | 3 | ||||
-rw-r--r-- | Shell/main.cpp | 4 |
3 files changed, 10 insertions, 11 deletions
diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index aa13648db5..960e698340 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -1024,21 +1024,15 @@ ContinuationRequest Shell::is_complete(const Vector<Command>& commands) IterationDecision Shell::wait_for_pid(const Shell::SpawnedProcess& process, bool is_first_command_in_chain, int& return_value) { - // Disable signal handler for the first command, as we actively wait for it - sighandler_t chld_handler = nullptr; - if (is_first_command_in_chain) { - chld_handler = signal(SIGCHLD, nullptr); - dbg() << "Waiting for " << process.name; - } + if (is_first_command_in_chain) + m_waiting_for_pid = process.pid; int wstatus = 0; int rc = waitpid(process.pid, &wstatus, WSTOPPED); auto errno_save = errno; - if (is_first_command_in_chain) { - signal(SIGCHLD, chld_handler); - dbg() << process.name << " is probably dead now (" << rc << ", " << strerror(errno_save) << ") -> exited " << WIFEXITED(wstatus) << " stopped " << WIFSTOPPED(wstatus); - } + if (is_first_command_in_chain) + m_waiting_for_pid = -1; errno = errno_save; if (rc < 0 && errno != EINTR) { diff --git a/Shell/Shell.h b/Shell/Shell.h index 63be56c69a..b397757ff8 100644 --- a/Shell/Shell.h +++ b/Shell/Shell.h @@ -115,6 +115,8 @@ public: void highlight(Line::Editor&) const; Vector<Line::CompletionSuggestion> complete(const Line::Editor&); + bool is_waiting_for(pid_t pid) const { return m_waiting_for_pid == pid; } + String get_history_path(); void load_history(); void save_history(); @@ -187,6 +189,7 @@ private: StringBuilder m_complete_line_builder; bool m_should_break_current_command { false }; bool m_should_ignore_jobs_on_next_exit { false }; + pid_t m_waiting_for_pid { -1 }; }; static constexpr bool is_word_character(char c) diff --git a/Shell/main.cpp b/Shell/main.cpp index 2ec8118018..28c97cbb19 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -58,7 +58,7 @@ void FileDescriptionCollector::add(int fd) int main(int argc, char** argv) { Core::EventLoop loop; - + signal(SIGINT, [](int) { editor->interrupted(); }); @@ -74,6 +74,8 @@ int main(int argc, char** argv) signal(SIGCHLD, [](int) { auto& jobs = s_shell->jobs; for (auto& job : jobs) { + if (s_shell->is_waiting_for(job.value->pid())) + continue; int wstatus = 0; auto child_pid = waitpid(job.value->pid(), &wstatus, WNOHANG); if (child_pid == job.value->pid()) { |