From 6c7c3d70cd55d5e57f966c25a347dcf0632f38a9 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 26 Mar 2015 00:27:36 +0000 Subject: Bug 695701: Tweak forking of PDF links to avoid zombie processes. Adopt a small patch from ooesili@gmail.com to avoid zombie processes that are left around after processes opened from PDF links are terminated. --- platform/x11/x11_main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index cb067ecc..bf425c7a 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -717,6 +717,7 @@ void winreloadfile(pdfapp_t *app) void winopenuri(pdfapp_t *app, char *buf) { char *browser = getenv("BROWSER"); + pid_t pid; if (!browser) { #ifdef __APPLE__ @@ -725,12 +726,22 @@ void winopenuri(pdfapp_t *app, char *buf) browser = "xdg-open"; #endif } - if (fork() == 0) + /* Fork once to start a child process that we wait on. This + * child process forks again and immediately exits. The + * grandchild process continues in the background. The purpose + * of this strange two-step is to avoid zombie processes. See + * bug 695701 for an explanation. */ + pid = fork(); + if (pid == 0) { - execlp(browser, browser, buf, (char*)0); - fprintf(stderr, "cannot exec '%s'\n", browser); + if (fork() == 0) + { + execlp(browser, browser, buf, (char*)0); + fprintf(stderr, "cannot exec '%s'\n", browser); + } exit(0); } + waitpid(pid, NULL, 0); } static void onkey(int c) -- cgit v1.2.3