diff options
-rw-r--r-- | sway/commands/exec_always.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index af4e4965..af4bd739 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -51,7 +51,41 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
51 | if ((pid = fork()) == 0) { | 51 | if ((pid = fork()) == 0) { |
52 | // Fork child process again | 52 | // Fork child process again |
53 | setsid(); | 53 | setsid(); |
54 | |||
54 | if ((*child = fork()) == 0) { | 55 | if ((*child = fork()) == 0) { |
56 | // Acquire the current PATH | ||
57 | char *path = getenv("PATH"); | ||
58 | const char *extra_path = ":/usr/lib/sway"; | ||
59 | const size_t extra_size = sizeof("/usr/lib/sway") + 1; | ||
60 | |||
61 | if (!path) { | ||
62 | size_t n = confstr(_CS_PATH, NULL, 0); | ||
63 | path = malloc(n + extra_size); | ||
64 | if (!path) { | ||
65 | return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH"); | ||
66 | } | ||
67 | confstr(_CS_PATH, path, n); | ||
68 | |||
69 | } else { | ||
70 | size_t n = strlen(path) + 1; | ||
71 | char *tmp = malloc(n + extra_size); | ||
72 | if (!tmp) { | ||
73 | return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH"); | ||
74 | } | ||
75 | |||
76 | strncpy(tmp, path, n); | ||
77 | path = tmp; | ||
78 | } | ||
79 | |||
80 | // Append /usr/lib/sway to PATH | ||
81 | strcat(path, extra_path); | ||
82 | if (!setenv("PATH", path, 1)) { | ||
83 | free(path); | ||
84 | return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to set PATH"); | ||
85 | } | ||
86 | free(path); | ||
87 | |||
88 | // Execute the command | ||
55 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); | 89 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); |
56 | // Not reached | 90 | // Not reached |
57 | } | 91 | } |