aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/exec_always.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-05-05 20:09:34 +0100
committerLibravatar GitHub <noreply@github.com>2018-05-05 20:09:34 +0100
commitc96ac2ff2a61571dc34f3a68dbe13a9b9c5884de (patch)
tree80579da473fb095b61a4693a1ab009d2fb6ea595 /sway/commands/exec_always.c
parentMerge pull request #1924 from nbraud/spelling (diff)
parentMerge branch 'master' into usr-lib (diff)
downloadsway-c96ac2ff2a61571dc34f3a68dbe13a9b9c5884de.tar.gz
sway-c96ac2ff2a61571dc34f3a68dbe13a9b9c5884de.tar.zst
sway-c96ac2ff2a61571dc34f3a68dbe13a9b9c5884de.zip
Merge pull request #1881 from nbraud/usr-lib
Install swaybar and swaybg under /usr/lib/sway
Diffstat (limited to 'sway/commands/exec_always.c')
-rw-r--r--sway/commands/exec_always.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index af4e4965..b3078640 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -11,6 +11,7 @@
11#include "log.h" 11#include "log.h"
12#include "stringop.h" 12#include "stringop.h"
13 13
14
14struct cmd_results *cmd_exec_always(int argc, char **argv) { 15struct cmd_results *cmd_exec_always(int argc, char **argv) {
15 struct cmd_results *error = NULL; 16 struct cmd_results *error = NULL;
16 if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL); 17 if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL);
@@ -51,7 +52,44 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
51 if ((pid = fork()) == 0) { 52 if ((pid = fork()) == 0) {
52 // Fork child process again 53 // Fork child process again
53 setsid(); 54 setsid();
55
54 if ((*child = fork()) == 0) { 56 if ((*child = fork()) == 0) {
57 // Acquire the current PATH
58 char *path = getenv("PATH");
59 const char *extra_path = ":" SWAY_LIBEXECDIR;
60 const size_t extra_size = sizeof(SWAY_LIBEXECDIR) + 1;
61
62 if (!path) {
63 size_t n = confstr(_CS_PATH, NULL, 0);
64 path = malloc(n + extra_size);
65 if (!path) {
66 wlr_log(L_ERROR, "exec_always: Unable to allocate PATH");
67 exit(EXIT_FAILURE);
68 }
69 confstr(_CS_PATH, path, n);
70
71 } else {
72 size_t n = strlen(path) + 1;
73 char *tmp = malloc(n + extra_size);
74 if (!tmp) {
75 wlr_log(L_ERROR, "exec_always: Unable to allocate PATH");
76 exit(EXIT_FAILURE);
77 }
78
79 strncpy(tmp, path, n);
80 path = tmp;
81 }
82
83 // Append /usr/lib/sway to PATH
84 strcat(path, extra_path);
85 if (!setenv("PATH", path, 1)) {
86 free(path);
87 wlr_log(L_ERROR, "exec_always: Unable to set PATH");
88 exit(EXIT_FAILURE);
89 }
90 free(path);
91
92 // Execute the command
55 execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); 93 execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
56 // Not reached 94 // Not reached
57 } 95 }