diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-03-26 00:27:36 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-03-26 10:15:09 +0000 |
commit | 6c7c3d70cd55d5e57f966c25a347dcf0632f38a9 (patch) | |
tree | 692d44035c612576c9c446e0d1151c0b8c4bb708 /platform/x11 | |
parent | 0af0f0f0740fc4914c4c13e232f88b8304173c76 (diff) | |
download | mupdf-6c7c3d70cd55d5e57f966c25a347dcf0632f38a9.tar.xz |
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.
Diffstat (limited to 'platform/x11')
-rw-r--r-- | platform/x11/x11_main.c | 17 |
1 files 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) |