aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-06-08 14:41:22 +0100
committerGitHub <noreply@github.com>2018-06-08 14:41:22 +0100
commit231c72a141fbf2bfd5c42413fe171f596a2ec42a (patch)
tree2035644a67f3e629565afd5026d16795d100172d
parentbf6ca69ae8c1149e6b6ae84f5ddc40639d1ff5a1 (diff)
parentd26a0a1a6e88ae632c2bcc33fed589ff733c818e (diff)
Merge pull request #2120 from martinetd/swayidle-zombies
Swayidle: doublefork to not leave zombies around
-rw-r--r--sway/commands/exec_always.c2
-rw-r--r--swayidle/main.c23
2 files changed, 19 insertions, 6 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index af4e4965..682d195e 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -73,7 +73,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
}
close(fd[0]);
// cleanup child process
- wait(0);
+ waitpid(pid, NULL, 0);
if (*child > 0) {
wlr_log(L_DEBUG, "Child process created with pid %d", *child);
// TODO: add PID to active workspace
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)