aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/exec_always.c
diff options
context:
space:
mode:
authorLibravatar Nicolas Braud-Santoni <nicolas@braud-santoni.eu>2018-05-01 16:17:10 +0200
committerLibravatar Nicolas Braud-Santoni <nicolas@braud-santoni.eu>2018-05-05 17:22:46 +0200
commit7709340727fe2834f87b43aeeaef878694d5acd6 (patch)
tree076a39b610d18b107f13a23e4d541ec795b22a67 /sway/commands/exec_always.c
parentInstall swaybar and swaybg under /usr/lib/sway (diff)
downloadsway-7709340727fe2834f87b43aeeaef878694d5acd6.tar.gz
sway-7709340727fe2834f87b43aeeaef878694d5acd6.tar.zst
sway-7709340727fe2834f87b43aeeaef878694d5acd6.zip
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) {
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 }