diff options
author | 2018-06-08 14:41:22 +0100 | |
---|---|---|
committer | 2018-06-08 14:41:22 +0100 | |
commit | 231c72a141fbf2bfd5c42413fe171f596a2ec42a (patch) | |
tree | 2035644a67f3e629565afd5026d16795d100172d /swayidle/main.c | |
parent | Merge pull request #2118 from RedSoxFan/fix-2117 (diff) | |
parent | sway exec command: use waitpid instead of wait (diff) | |
download | sway-231c72a141fbf2bfd5c42413fe171f596a2ec42a.tar.gz sway-231c72a141fbf2bfd5c42413fe171f596a2ec42a.tar.zst sway-231c72a141fbf2bfd5c42413fe171f596a2ec42a.zip |
Merge pull request #2120 from martinetd/swayidle-zombies
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 @@ | |||
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) |