Skip to content

Commit

Permalink
Fix freeze when launching web browser on Linux/macOS
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
jyrkive committed Sep 6, 2017
1 parent 3b1083f commit b95c999
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/desktop/open.cpp
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/wesnoth.cpp
Expand Up @@ -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.
Expand Down

0 comments on commit b95c999

Please sign in to comment.