diff options
author | Dominique Martinet <asmadeus@codewreck.org> | 2018-06-08 22:02:47 +0900 |
---|---|---|
committer | Dominique Martinet <asmadeus@codewreck.org> | 2018-06-08 22:28:28 +0900 |
commit | 2477930d90a75f5d94247eddf36f87b5689f3056 (patch) | |
tree | 3c8f3bbe48420582ff926e1b7052a742ff0951f7 /swayidle/main.c | |
parent | bf6ca69ae8c1149e6b6ae84f5ddc40639d1ff5a1 (diff) |
swayidle: doublefork to not leave zombies around
Diffstat (limited to 'swayidle/main.c')
-rw-r--r-- | swayidle/main.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/swayidle/main.c b/swayidle/main.c index ad9c84c9..d83ab98d 100644 --- a/swayidle/main.c +++ b/swayidle/main.c @@ -6,6 +6,7 @@ #include <stdlib.h> #include <errno.h> #include <string.h> +#include <sys/wait.h> #include <unistd.h> #include <wayland-client-protocol.h> #include <wayland-client.h> @@ -59,13 +60,25 @@ static void cmd_exec(void *data) { } char *param = (char *)data; wlr_log(L_DEBUG, "Cmd exec %s", param); - int pid = fork(); + pid_t pid = fork(); if (pid == 0) { - char *const cmd[] = { "sh", "-c", param, NULL, }; - execvp(cmd[0], cmd); - exit(1); + pid = fork(); + if (pid == 0) { + char *const cmd[] = { "sh", "-c", param, NULL, }; + execvp(cmd[0], cmd); + wlr_log_errno(L_ERROR, "execve failed!"); + exit(1); + } else if (pid < 0) { + wlr_log_errno(L_ERROR, "fork failed"); + exit(1); + } + exit(0); + } else if (pid < 0) { + wlr_log_errno(L_ERROR, "fork failed"); + } else { + wlr_log(L_DEBUG, "Spawned process %s", param); + waitpid(pid, NULL, 0); } - wlr_log(L_DEBUG, "Spawned process %d", pid); } #if defined(SWAY_IDLE_HAS_SYSTEMD) || defined(SWAY_IDLE_HAS_ELOGIND) |