From 2477930d90a75f5d94247eddf36f87b5689f3056 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 8 Jun 2018 22:02:47 +0900 Subject: [PATCH 1/2] swayidle: doublefork to not leave zombies around --- swayidle/main.c | 23 ++++++++++++++++++----- 1 file 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 #include #include +#include #include #include #include @@ -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) From d26a0a1a6e88ae632c2bcc33fed589ff733c818e Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 8 Jun 2018 22:27:33 +0900 Subject: [PATCH 2/2] sway exec command: use waitpid instead of wait --- sway/commands/exec_always.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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