diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/sway/commands.c b/sway/commands.c index dfb3c12d..3181b434 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -214,22 +214,37 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
214 | free(tmp); | 214 | free(tmp); |
215 | sway_log(L_DEBUG, "Executing %s", cmd); | 215 | sway_log(L_DEBUG, "Executing %s", cmd); |
216 | 216 | ||
217 | int fd[2]; | ||
218 | pipe(fd); | ||
219 | |||
217 | pid_t pid; | 220 | pid_t pid; |
221 | pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space | ||
218 | // Fork process | 222 | // Fork process |
219 | if ((pid = fork()) == 0) { | 223 | if ((pid = fork()) == 0) { |
220 | // Fork child process again | 224 | // Fork child process again |
221 | setsid(); | 225 | setsid(); |
222 | if (fork() == 0) { | 226 | if ((*child = fork()) == 0) { |
223 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); | 227 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); |
224 | /* Not reached */ | 228 | /* Not reached */ |
225 | } | 229 | } |
226 | // Close child process | 230 | close(fd[0]); |
227 | _exit(0); | 231 | write(fd[1], child, sizeof(pid_t)); |
232 | close(fd[1]); | ||
233 | _exit(0); // Close child process | ||
228 | } else if (pid < 0) { | 234 | } else if (pid < 0) { |
229 | return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork)."); | 235 | return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork)."); |
230 | } | 236 | } |
237 | close(fd[1]); // close write | ||
238 | read(fd[0], child, sizeof(pid_t)); | ||
239 | close(fd[0]); | ||
231 | // cleanup child process | 240 | // cleanup child process |
232 | wait(0); | 241 | wait(0); |
242 | if (*child > 0) { | ||
243 | sway_log(L_DEBUG, "Child process created with pid %d", *child); | ||
244 | // TODO: keep track of this pid and open the corresponding view on the current workspace | ||
245 | // blocked pending feature in wlc | ||
246 | } | ||
247 | free(child); | ||
233 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 248 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
234 | } | 249 | } |
235 | 250 | ||