From f68115aba31b0702ac3e36cdf096704747e0c320 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 1 Dec 2020 20:20:30 -0700 Subject: [PATCH] Taskbar: Wait on all waitable children in SIGCHLD handler We need to call waitpid until no more waitable children are available. This is necessary because SIGCHLD signals may coalesce into one when multiple children terminate almost simultaneously. Also, switch to EventLoop's asynchronous signal handling mechanism, which allows more complex operations in the signal handler. --- Libraries/LibGUI/Application.h | 2 ++ Services/Taskbar/main.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Libraries/LibGUI/Application.h b/Libraries/LibGUI/Application.h index bc6c3e2ba2d..d28b9da7ce2 100644 --- a/Libraries/LibGUI/Application.h +++ b/Libraries/LibGUI/Application.h @@ -74,6 +74,8 @@ public: bool focus_debugging_enabled() const { return m_focus_debugging_enabled; } + Core::EventLoop& event_loop() { return *m_event_loop; } + private: Application(int argc, char** argv); diff --git a/Services/Taskbar/main.cpp b/Services/Taskbar/main.cpp index 3e4f639e054..39172854979 100644 --- a/Services/Taskbar/main.cpp +++ b/Services/Taskbar/main.cpp @@ -25,6 +25,7 @@ */ #include "TaskbarWindow.h" +#include #include #include #include @@ -38,10 +39,10 @@ int main(int argc, char** argv) } auto app = GUI::Application::construct(argc, argv); - - signal(SIGCHLD, [](int signo) { - (void)signo; - wait(nullptr); + app->event_loop().register_signal(SIGCHLD, [](int) { + // Wait all available children + while (waitpid(-1, nullptr, WNOHANG) > 0) + ; }); if (pledge("stdio shared_buffer accept proc exec rpath", nullptr) < 0) {