diff options
-rw-r--r-- | sway/commands/output/background.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 4f422cec..55cbdff0 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -69,42 +69,49 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
69 | return cmd_res; | 69 | return cmd_res; |
70 | } | 70 | } |
71 | free(src); | 71 | free(src); |
72 | src = p.we_wordv[0]; | 72 | src = strdup(p.we_wordv[0]); |
73 | wordfree(&p); | ||
74 | if (!src) { | ||
75 | wlr_log(L_ERROR, "Failed to duplicate string"); | ||
76 | return cmd_results_new(CMD_FAILURE, "output", | ||
77 | "Unable to allocate resource"); | ||
78 | } | ||
79 | |||
73 | if (config->reading && *src != '/') { | 80 | if (config->reading && *src != '/') { |
81 | // src file is inside configuration dir | ||
82 | |||
74 | char *conf = strdup(config->current_config); | 83 | char *conf = strdup(config->current_config); |
75 | if (conf) { | 84 | if(!conf) { |
76 | char *conf_path = dirname(conf); | 85 | wlr_log(L_ERROR, "Failed to duplicate string"); |
77 | src = malloc(strlen(conf_path) + strlen(src) + 2); | 86 | return cmd_results_new(CMD_FAILURE, "output", |
78 | if (!src) { | ||
79 | free(conf); | ||
80 | wordfree(&p); | ||
81 | wlr_log(L_ERROR, | ||
82 | "Unable to allocate resource: Not enough memory"); | ||
83 | return cmd_results_new(CMD_FAILURE, "output", | ||
84 | "Unable to allocate resources"); | 87 | "Unable to allocate resources"); |
85 | } | 88 | } |
86 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | 89 | |
90 | char *conf_path = dirname(conf); | ||
91 | char *rel_path = src; | ||
92 | src = malloc(strlen(conf_path) + strlen(src) + 2); | ||
93 | if (!src) { | ||
94 | free(rel_path); | ||
87 | free(conf); | 95 | free(conf); |
88 | } else { | 96 | wlr_log(L_ERROR, "Unable to allocate memory"); |
89 | wlr_log(L_ERROR, "Unable to allocate background source"); | 97 | return cmd_results_new(CMD_FAILURE, "output", |
98 | "Unable to allocate resources"); | ||
90 | } | 99 | } |
100 | |||
101 | sprintf(src, "%s/%s", conf_path, rel_path); | ||
102 | free(rel_path); | ||
103 | free(conf); | ||
91 | } | 104 | } |
92 | 105 | ||
93 | if (access(src, F_OK) == -1) { | 106 | if (access(src, F_OK) == -1) { |
94 | struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output", | 107 | struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output", |
95 | "Unable to access background file '%s': %s", src, strerror(errno)); | 108 | "Unable to access background file '%s': %s", src, strerror(errno)); |
96 | free(src); | 109 | free(src); |
97 | wordfree(&p); | ||
98 | return cmd_res; | 110 | return cmd_res; |
99 | } | 111 | } |
100 | 112 | ||
101 | output->background = strdup(src); | 113 | output->background = src; |
102 | output->background_option = strdup(mode); | 114 | output->background_option = strdup(mode); |
103 | if (src != p.we_wordv[0]) { | ||
104 | free(src); | ||
105 | } | ||
106 | wordfree(&p); | ||
107 | |||
108 | argc -= j + 1; argv += j + 1; | 115 | argc -= j + 1; argv += j + 1; |
109 | } | 116 | } |
110 | 117 | ||