summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-06-08 14:41:22 +0100
committerLibravatar GitHub <noreply@github.com>2018-06-08 14:41:22 +0100
commit231c72a141fbf2bfd5c42413fe171f596a2ec42a (patch)
tree2035644a67f3e629565afd5026d16795d100172d
parentMerge pull request #2118 from RedSoxFan/fix-2117 (diff)
parentsway exec command: use waitpid instead of wait (diff)
downloadsway-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
-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) {
73 } 73 }
74 close(fd[0]); 74 close(fd[0]);
75 // cleanup child process 75 // cleanup child process
76 wait(0); 76 waitpid(pid, NULL, 0);
77 if (*child > 0) { 77 if (*child > 0) {
78 wlr_log(L_DEBUG, "Child process created with pid %d", *child); 78 wlr_log(L_DEBUG, "Child process created with pid %d", *child);
79 // TODO: add PID to active workspace 79 // 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 @@
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)