aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/exec_always.c
diff options
context:
space:
mode:
authorNicolas Braud-Santoni <nicolas@braud-santoni.eu>2018-05-01 16:17:10 +0200
committerNicolas Braud-Santoni <nicolas@braud-santoni.eu>2018-05-05 17:22:46 +0200
commit7709340727fe2834f87b43aeeaef878694d5acd6 (patch)
tree076a39b610d18b107f13a23e4d541ec795b22a67 /sway/commands/exec_always.c
parentf2c209c299889ad965ac995049704b1c46176c6d (diff)
exec_always: Search for executables in /usr/lib/sway
Diffstat (limited to 'sway/commands/exec_always.c')
-rw-r--r--sway/commands/exec_always.c34
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) {
if ((pid = fork()) == 0) {
// Fork child process again
setsid();
+
if ((*child = fork()) == 0) {
+ // Acquire the current PATH
+ char *path = getenv("PATH");
+ const char *extra_path = ":/usr/lib/sway";
+ const size_t extra_size = sizeof("/usr/lib/sway") + 1;
+
+ if (!path) {
+ size_t n = confstr(_CS_PATH, NULL, 0);
+ path = malloc(n + extra_size);
+ if (!path) {
+ return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH");
+ }
+ confstr(_CS_PATH, path, n);
+
+ } else {
+ size_t n = strlen(path) + 1;
+ char *tmp = malloc(n + extra_size);
+ if (!tmp) {
+ return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH");
+ }
+
+ strncpy(tmp, path, n);
+ path = tmp;
+ }
+
+ // Append /usr/lib/sway to PATH
+ strcat(path, extra_path);
+ if (!setenv("PATH", path, 1)) {
+ free(path);
+ return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to set PATH");
+ }
+ free(path);
+
+ // Execute the command
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
// Not reached
}