diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-10-08 11:24:37 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-10-08 11:24:37 -0400 |
commit | 73af58152b24e0cfe28f6c613e8e7523ffb515fc (patch) | |
tree | 08b4326d5e5b69b8b91e842ccc63a57b7f6f79fb /sway/commands.c | |
parent | d2680ac8fe43c9469b0a2cc00ca53612bcab8438 (diff) | |
parent | 18f4905e62e1fb2042abd79b2a4c756187e3d506 (diff) |
Merge pull request #190 from taiyu-len/master
#187, let init handle child processes
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index 03c682d7..2358b9e9 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -9,6 +9,7 @@ #include <unistd.h> #include <ctype.h> #include <sys/types.h> +#include <sys/wait.h> #include "stringop.h" #include "layout.h" #include "focus.h" @@ -190,18 +191,25 @@ static enum cmd_status cmd_exec_always(int argc, char **argv) { char cmd[4096]; strcpy(cmd, tmp); free(tmp); - - char *args[] = {"sh", "-c", cmd, 0 }; sway_log(L_DEBUG, "Executing %s", cmd); pid_t pid; + // Fork process if ((pid = fork()) == 0) { - execv("/bin/sh", args); - _exit(-1); + // Fork child process again + setsid(); + if (fork() == 0) { + execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); + /* Not reached */ + } + // Close child process + _exit(0); } else if (pid < 0) { sway_log(L_ERROR, "exec command failed, sway could not fork"); return CMD_FAILURE; } + // cleanup child process + wait(0); return CMD_SUCCESS; } |