diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-11-20 22:10:03 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-11-21 10:36:15 -0500 |
commit | 2f858a1adaef17241ca6fda973f2b867b25e1971 (patch) | |
tree | 4942dfcbd3eeea04092ff1b40791b8c25e1f4403 /sway | |
parent | input/keyboard: cleanup xkb_file error handing (diff) | |
download | sway-2f858a1adaef17241ca6fda973f2b867b25e1971.tar.gz sway-2f858a1adaef17241ca6fda973f2b867b25e1971.tar.zst sway-2f858a1adaef17241ca6fda973f2b867b25e1971.zip |
input_cmd_xkb_file: allow shell path expansion
This allows for shell path expansion for input_cmd_xkb_file. The logic
has been extracted from output_cmd_background
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/input/xkb_file.c | 22 | ||||
-rw-r--r-- | sway/commands/output/background.c | 16 |
2 files changed, 24 insertions, 14 deletions
diff --git a/sway/commands/input/xkb_file.c b/sway/commands/input/xkb_file.c index ef59bffc..493f94fb 100644 --- a/sway/commands/input/xkb_file.c +++ b/sway/commands/input/xkb_file.c | |||
@@ -1,7 +1,10 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <unistd.h> | ||
3 | #include <errno.h> | ||
2 | #include "sway/config.h" | 4 | #include "sway/config.h" |
3 | #include "sway/commands.h" | 5 | #include "sway/commands.h" |
4 | #include "log.h" | 6 | #include "log.h" |
7 | #include "stringop.h" | ||
5 | 8 | ||
6 | struct cmd_results *input_cmd_xkb_file(int argc, char **argv) { | 9 | struct cmd_results *input_cmd_xkb_file(int argc, char **argv) { |
7 | struct cmd_results *error = NULL; | 10 | struct cmd_results *error = NULL; |
@@ -18,6 +21,25 @@ struct cmd_results *input_cmd_xkb_file(int argc, char **argv) { | |||
18 | ic->xkb_file = NULL; | 21 | ic->xkb_file = NULL; |
19 | } else { | 22 | } else { |
20 | ic->xkb_file = strdup(argv[0]); | 23 | ic->xkb_file = strdup(argv[0]); |
24 | if (!expand_path(&ic->xkb_file)) { | ||
25 | error = cmd_results_new(CMD_INVALID, "Invalid syntax (%s)", | ||
26 | ic->xkb_file); | ||
27 | free(ic->xkb_file); | ||
28 | ic->xkb_file = NULL; | ||
29 | return error; | ||
30 | } | ||
31 | if (!ic->xkb_file) { | ||
32 | sway_log(SWAY_ERROR, "Failed to allocate expanded path"); | ||
33 | return cmd_results_new(CMD_FAILURE, "Unable to allocate resource"); | ||
34 | } | ||
35 | |||
36 | bool can_access = access(ic->xkb_file, F_OK) != -1; | ||
37 | if (!can_access) { | ||
38 | sway_log_errno(SWAY_ERROR, "Unable to access xkb file '%s'", | ||
39 | ic->xkb_file); | ||
40 | config_add_swaynag_warning("Unable to access xkb file '%s'", | ||
41 | ic->xkb_file); | ||
42 | } | ||
21 | } | 43 | } |
22 | ic->xkb_file_is_set = true; | 44 | ic->xkb_file_is_set = true; |
23 | 45 | ||
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 054fb707..68ee9fe1 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -4,7 +4,6 @@ | |||
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <strings.h> | 5 | #include <strings.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <wordexp.h> | ||
8 | #include <errno.h> | 7 | #include <errno.h> |
9 | #include "sway/commands.h" | 8 | #include "sway/commands.h" |
10 | #include "sway/config.h" | 9 | #include "sway/config.h" |
@@ -79,26 +78,15 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
79 | return cmd_results_new(CMD_INVALID, "Missing background file"); | 78 | return cmd_results_new(CMD_INVALID, "Missing background file"); |
80 | } | 79 | } |
81 | 80 | ||
82 | wordexp_t p = {0}; | ||
83 | char *src = join_args(argv, j); | 81 | char *src = join_args(argv, j); |
84 | while (strstr(src, " ")) { | 82 | if (!expand_path(&src)) { |
85 | src = realloc(src, strlen(src) + 2); | ||
86 | char *ptr = strstr(src, " ") + 1; | ||
87 | memmove(ptr + 1, ptr, strlen(ptr) + 1); | ||
88 | *ptr = '\\'; | ||
89 | } | ||
90 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { | ||
91 | struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, | 83 | struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, |
92 | "Invalid syntax (%s)", src); | 84 | "Invalid syntax (%s)", src); |
93 | free(src); | 85 | free(src); |
94 | wordfree(&p); | ||
95 | return cmd_res; | 86 | return cmd_res; |
96 | } | 87 | } |
97 | free(src); | ||
98 | src = join_args(p.we_wordv, p.we_wordc); | ||
99 | wordfree(&p); | ||
100 | if (!src) { | 88 | if (!src) { |
101 | sway_log(SWAY_ERROR, "Failed to duplicate string"); | 89 | sway_log(SWAY_ERROR, "Failed to allocate expanded path"); |
102 | return cmd_results_new(CMD_FAILURE, "Unable to allocate resource"); | 90 | return cmd_results_new(CMD_FAILURE, "Unable to allocate resource"); |
103 | } | 91 | } |
104 | 92 | ||