From 57d220a43b52103a63ea9d405d01dd9d8e2a46c4 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 23 Sep 2021 23:07:15 -0400 Subject: [PATCH] [common] open: detach xdg-open instead of waiting for it Sometimes, e.g. when xdg-open has to start the browser, the xdg-open process can stay around until the browser exits, which freezes the client. Instead, we should not wait for xdg-open to exit. However, we can't simply not call wait, as that would leave the xdg-open process around as a zombie. We could turn off the SIGCHLD handler, but that's a global solution to a local problem. Instead, we call setsid and fork again to detach the xdg-open process as if it's a daemon, and let init take care of the reaping process. Co-Authored-By: Tudor Brindus --- common/src/platform/linux/open.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/src/platform/linux/open.c b/common/src/platform/linux/open.c index f42240af..b467c63c 100644 --- a/common/src/platform/linux/open.c +++ b/common/src/platform/linux/open.c @@ -31,8 +31,15 @@ static bool xdgOpen(const char * path) pid_t pid = fork(); if (pid == 0) { - execlp("xdg-open", "xdg-open", path, NULL); - _exit(127); + // setsid and fork again to detach the xdg-open process. + setsid(); + pid_t pid = fork(); + if (pid == 0) + { + execlp("xdg-open", "xdg-open", path, NULL); + _exit(127); + } + _exit(pid < 0); } else if (pid < 0) { @@ -52,9 +59,9 @@ static bool xdgOpen(const char * path) return true; if (WIFEXITED(status)) - DEBUG_ERROR("xdg-open exited with code %d", WEXITSTATUS(status)); + DEBUG_ERROR("helper process exited with code %d", WEXITSTATUS(status)); else - DEBUG_ERROR("xdg-open exited with signal: %s", strsignal(WTERMSIG(status))); + DEBUG_ERROR("helper process exited with signal: %s", strsignal(WTERMSIG(status))); return false; } }