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"
This commit is contained in:
Jyrki Vesterinen 2017-09-06 19:50:38 +03:00
parent 3b1083f4e7
commit b95c9996bf
2 changed files with 8 additions and 3 deletions

View file

@ -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

View file

@ -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.