diff options
Diffstat (limited to 'sway/commands/exec_always.c')
-rw-r--r-- | sway/commands/exec_always.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index ab2d8622..954950e7 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -1,9 +1,13 @@ | |||
1 | #define _XOPEN_SOURCE 500 | 1 | #define _XOPEN_SOURCE 500 |
2 | #include <stdlib.h> | ||
3 | #include <stdint.h> | ||
2 | #include <string.h> | 4 | #include <string.h> |
3 | #include <sys/wait.h> | 5 | #include <sys/wait.h> |
4 | #include <unistd.h> | 6 | #include <unistd.h> |
5 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
6 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/tree/container.h" | ||
10 | #include "sway/tree/workspace.h" | ||
7 | #include "log.h" | 11 | #include "log.h" |
8 | #include "stringop.h" | 12 | #include "stringop.h" |
9 | 13 | ||
@@ -16,7 +20,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
16 | 20 | ||
17 | char *tmp = NULL; | 21 | char *tmp = NULL; |
18 | if (strcmp((char*)*argv, "--no-startup-id") == 0) { | 22 | if (strcmp((char*)*argv, "--no-startup-id") == 0) { |
19 | sway_log(L_INFO, "exec switch '--no-startup-id' not supported, ignored."); | 23 | wlr_log(L_INFO, "exec switch '--no-startup-id' not supported, ignored."); |
20 | if ((error = checkarg(argc - 1, "exec_always", EXPECTED_MORE_THAN, 0))) { | 24 | if ((error = checkarg(argc - 1, "exec_always", EXPECTED_MORE_THAN, 0))) { |
21 | return error; | 25 | return error; |
22 | } | 26 | } |
@@ -31,11 +35,11 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
31 | strncpy(cmd, tmp, sizeof(cmd)); | 35 | strncpy(cmd, tmp, sizeof(cmd)); |
32 | cmd[sizeof(cmd) - 1] = 0; | 36 | cmd[sizeof(cmd) - 1] = 0; |
33 | free(tmp); | 37 | free(tmp); |
34 | sway_log(L_DEBUG, "Executing %s", cmd); | 38 | wlr_log(L_DEBUG, "Executing %s", cmd); |
35 | 39 | ||
36 | int fd[2]; | 40 | int fd[2]; |
37 | if (pipe(fd) != 0) { | 41 | if (pipe(fd) != 0) { |
38 | sway_log(L_ERROR, "Unable to create pipe for fork"); | 42 | wlr_log(L_ERROR, "Unable to create pipe for fork"); |
39 | } | 43 | } |
40 | 44 | ||
41 | pid_t pid; | 45 | pid_t pid; |
@@ -49,7 +53,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
49 | setsid(); | 53 | setsid(); |
50 | if ((*child = fork()) == 0) { | 54 | if ((*child = fork()) == 0) { |
51 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); | 55 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); |
52 | /* Not reached */ | 56 | // Not reached |
53 | } | 57 | } |
54 | close(fd[0]); | 58 | close(fd[0]); |
55 | ssize_t s = 0; | 59 | ssize_t s = 0; |
@@ -70,13 +74,9 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
70 | close(fd[0]); | 74 | close(fd[0]); |
71 | // cleanup child process | 75 | // cleanup child process |
72 | wait(0); | 76 | wait(0); |
73 | swayc_t *ws = swayc_active_workspace(); | 77 | if (*child > 0) { |
74 | if (*child > 0 && ws) { | 78 | wlr_log(L_DEBUG, "Child process created with pid %d", *child); |
75 | sway_log(L_DEBUG, "Child process created with pid %d for workspace %s", *child, ws->name); | 79 | // TODO: add PID to active workspace |
76 | struct pid_workspace *pw = malloc(sizeof(struct pid_workspace)); | ||
77 | pw->pid = child; | ||
78 | pw->workspace = strdup(ws->name); | ||
79 | pid_workspace_add(pw); | ||
80 | } else { | 80 | } else { |
81 | free(child); | 81 | free(child); |
82 | } | 82 | } |