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