From b95c9996bf435daa4d7e64fd1ef41425ac182b95 Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Wed, 6 Sep 2017 19:50:38 +0300 Subject: [PATCH] Fix freeze when launching web browser on Linux/macOS POSIX has a feature to automatically reap zombie processes, which makes it unnecessary to wait for the child process to exit. Activate the feature and stop waiting for exit. "POSIX.1-2001 specifies that if the disposition of SIGCHLD is set to SIG_IGN or the SA_NOCLDWAIT flag is set for SIGCHLD (see sigaction(2)), then children that terminate do not become zombies" --- src/desktop/open.cpp | 6 +++--- src/wesnoth.cpp | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/desktop/open.cpp b/src/desktop/open.cpp index 949b9c6e1eb7..4dcd4907ed5d 100644 --- a/src/desktop/open.cpp +++ b/src/desktop/open.cpp @@ -73,11 +73,11 @@ bool open_object(const std::string& path_or_url) } else if(child == 0) { execlp(launcher, launcher, path_or_url.c_str(), nullptr); _exit(1); // This shouldn't happen. - } else if(waitpid(child, &child_status, 0) == -1) { - ERR_DU << "open_object(): waitpid() failed" << std::endl; - return false; } + // Waiting for the child process to exit is unnecessary because we ignore SIGCHLD. + // See the manpage for wait(2). + if(child_status) { //Those status check macros seem to trigger old style casts on some compiler versions #pragma GCC diagnostic push diff --git a/src/wesnoth.cpp b/src/wesnoth.cpp index fa92fa5d7256..74f6021e3737 100644 --- a/src/wesnoth.cpp +++ b/src/wesnoth.cpp @@ -1015,6 +1015,11 @@ int main(int argc, char** argv) sigemptyset(&terminate_handler.sa_mask); sigaction(SIGTERM, &terminate_handler, nullptr); sigaction(SIGINT, &terminate_handler, nullptr); + + // Explicitly ignore SIGCHLD. This allows us to launch child processes without waiting + // for them to exit. See the manpage for wait(2). + terminate_handler.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &terminate_handler, nullptr); #endif //declare this here so that it will always be at the front of the event queue.