aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2019-01-14 09:42:55 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2019-01-14 09:45:18 +0000
commit8729c6531193e08c21babdb37731059ed289ce95 (patch)
treea0bc771a9c331ca11d330bef84a781996d2fa65b /swaynag
parentMerge pull request #3417 from swaywm/remove-swaylock (diff)
downloadsway-8729c6531193e08c21babdb37731059ed289ce95.tar.gz
sway-8729c6531193e08c21babdb37731059ed289ce95.tar.zst
sway-8729c6531193e08c21babdb37731059ed289ce95.zip
swaynag: handle empty $XDG_CONFIG_HOME better
Set config path to fallback instead of setting $XDG_CONFIG_HOME
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index 85aa380a..60bda3e0 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -304,25 +304,15 @@ char *swaynag_get_config_path(void) {
304 SYSCONFDIR "/swaynag/config", 304 SYSCONFDIR "/swaynag/config",
305 }; 305 };
306 306
307 if (!getenv("XDG_CONFIG_HOME")) { 307 char *config_home = getenv("XDG_CONFIG_HOME");
308 char *home = getenv("HOME"); 308 if (!config_home || *config_home) {
309 char *config_home = malloc(strlen(home) + strlen("/.config") + 1); 309 config_paths[1] = "$HOME/.config/swaynag/config";
310 if (!config_home) {
311 wlr_log(WLR_ERROR, "Unable to allocate $HOME/.config");
312 } else {
313 strcpy(config_home, home);
314 strcat(config_home, "/.config");
315 setenv("XDG_CONFIG_HOME", config_home, 1);
316 wlr_log(WLR_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
317 free(config_home);
318 }
319 } 310 }
320 311
321 wordexp_t p; 312 wordexp_t p;
322 char *path;
323 for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) { 313 for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) {
324 if (wordexp(config_paths[i], &p, 0) == 0) { 314 if (wordexp(config_paths[i], &p, 0) == 0) {
325 path = strdup(p.we_wordv[0]); 315 char *path = strdup(p.we_wordv[0]);
326 wordfree(&p); 316 wordfree(&p);
327 if (file_exists(path)) { 317 if (file_exists(path)) {
328 return path; 318 return path;