aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output/background.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/output/background.c')
-rw-r--r--sway/commands/output/background.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c
index 82bccf68..55cbdff0 100644
--- a/sway/commands/output/background.c
+++ b/sway/commands/output/background.c
@@ -62,46 +62,56 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
62 wordexp_t p; 62 wordexp_t p;
63 char *src = join_args(argv, j); 63 char *src = join_args(argv, j);
64 if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { 64 if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
65 return cmd_results_new(CMD_INVALID, "output", 65 struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, "output",
66 "Invalid syntax (%s).", src); 66 "Invalid syntax (%s)", src);
67 free(src);
68 wordfree(&p);
69 return cmd_res;
67 } 70 }
68 free(src); 71 free(src);
69 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
70 if (config->reading && *src != '/') { 80 if (config->reading && *src != '/') {
81 // src file is inside configuration dir
82
71 char *conf = strdup(config->current_config); 83 char *conf = strdup(config->current_config);
72 if (conf) { 84 if(!conf) {
73 char *conf_path = dirname(conf); 85 wlr_log(L_ERROR, "Failed to duplicate string");
74 src = malloc(strlen(conf_path) + strlen(src) + 2); 86 return cmd_results_new(CMD_FAILURE, "output",
75 if (!src) {
76 free(conf);
77 wordfree(&p);
78 wlr_log(L_ERROR,
79 "Unable to allocate resource: Not enough memory");
80 return cmd_results_new(CMD_FAILURE, "output",
81 "Unable to allocate resources"); 87 "Unable to allocate resources");
82 } 88 }
83 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);
84 free(conf); 95 free(conf);
85 } else { 96 wlr_log(L_ERROR, "Unable to allocate memory");
86 wlr_log(L_ERROR, "Unable to allocate background source"); 97 return cmd_results_new(CMD_FAILURE, "output",
98 "Unable to allocate resources");
87 } 99 }
100
101 sprintf(src, "%s/%s", conf_path, rel_path);
102 free(rel_path);
103 free(conf);
88 } 104 }
89 105
90 if (access(src, F_OK) == -1) { 106 if (access(src, F_OK) == -1) {
91 struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output", 107 struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output",
92 "Unable to access background file '%s': %s", src, strerror(errno)); 108 "Unable to access background file '%s': %s", src, strerror(errno));
93 free(src); 109 free(src);
94 wordfree(&p);
95 return cmd_res; 110 return cmd_res;
96 } 111 }
97 112
98 output->background = strdup(src); 113 output->background = src;
99 output->background_option = strdup(mode); 114 output->background_option = strdup(mode);
100 if (src != p.we_wordv[0]) {
101 free(src);
102 }
103 wordfree(&p);
104
105 argc -= j + 1; argv += j + 1; 115 argc -= j + 1; argv += j + 1;
106 } 116 }
107 117