aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-06-08 22:02:47 +0900
committerLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-06-08 22:28:28 +0900
commit2477930d90a75f5d94247eddf36f87b5689f3056 (patch)
tree3c8f3bbe48420582ff926e1b7052a742ff0951f7
parentMerge pull request #2118 from RedSoxFan/fix-2117 (diff)
downloadsway-2477930d90a75f5d94247eddf36f87b5689f3056.tar.gz
sway-2477930d90a75f5d94247eddf36f87b5689f3056.tar.zst
sway-2477930d90a75f5d94247eddf36f87b5689f3056.zip
swayidle: doublefork to not leave zombies around
-rw-r--r--swayidle/main.c23
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 @@
6#include <stdlib.h> 6#include <stdlib.h>
7#include <errno.h> 7#include <errno.h>
8#include <string.h> 8#include <string.h>
9#include <sys/wait.h>
9#include <unistd.h> 10#include <unistd.h>
10#include <wayland-client-protocol.h> 11#include <wayland-client-protocol.h>
11#include <wayland-client.h> 12#include <wayland-client.h>
@@ -59,13 +60,25 @@ static void cmd_exec(void *data) {
59 } 60 }
60 char *param = (char *)data; 61 char *param = (char *)data;
61 wlr_log(L_DEBUG, "Cmd exec %s", param); 62 wlr_log(L_DEBUG, "Cmd exec %s", param);
62 int pid = fork(); 63 pid_t pid = fork();
63 if (pid == 0) { 64 if (pid == 0) {
64 char *const cmd[] = { "sh", "-c", param, NULL, }; 65 pid = fork();
65 execvp(cmd[0], cmd); 66 if (pid == 0) {
66 exit(1); 67 char *const cmd[] = { "sh", "-c", param, NULL, };
68 execvp(cmd[0], cmd);
69 wlr_log_errno(L_ERROR, "execve failed!");
70 exit(1);
71 } else if (pid < 0) {
72 wlr_log_errno(L_ERROR, "fork failed");
73 exit(1);
74 }
75 exit(0);
76 } else if (pid < 0) {
77 wlr_log_errno(L_ERROR, "fork failed");
78 } else {
79 wlr_log(L_DEBUG, "Spawned process %s", param);
80 waitpid(pid, NULL, 0);
67 } 81 }
68 wlr_log(L_DEBUG, "Spawned process %d", pid);
69} 82}
70 83
71#if defined(SWAY_IDLE_HAS_SYSTEMD) || defined(SWAY_IDLE_HAS_ELOGIND) 84#if defined(SWAY_IDLE_HAS_SYSTEMD) || defined(SWAY_IDLE_HAS_ELOGIND)