aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
authorLibravatar Connor E <38229097+c-edw@users.noreply.github.com>2019-02-06 15:42:32 +0000
committerLibravatar emersion <contact@emersion.fr>2019-02-06 18:23:20 +0100
commit921e42c6c06212a61d899d6335d95eb4c781e2e8 (patch)
tree1799560336318601661978f99340f2c17ec03447 /sway/config.c
parentReturn false if config could not be loaded. (diff)
downloadsway-921e42c6c06212a61d899d6335d95eb4c781e2e8.tar.gz
sway-921e42c6c06212a61d899d6335d95eb4c781e2e8.tar.zst
sway-921e42c6c06212a61d899d6335d95eb4c781e2e8.zip
Restore CWD if returning early.
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/sway/config.c b/sway/config.c
index 455d20cd..9072f7d7 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -558,17 +558,13 @@ bool load_include_configs(const char *path, struct sway_config *config,
558 const char *parent_dir = dirname(parent_path); 558 const char *parent_dir = dirname(parent_path);
559 559
560 if (chdir(parent_dir) < 0) { 560 if (chdir(parent_dir) < 0) {
561 free(parent_path); 561 goto error_chdir;
562 free(wd);
563 return false;
564 } 562 }
565 563
566 wordexp_t p; 564 wordexp_t p;
567 565
568 if (wordexp(path, &p, 0) != 0) { 566 if (wordexp(path, &p, 0) != 0) {
569 free(parent_path); 567 goto error_wordexp;
570 free(wd);
571 return false;
572 } 568 }
573 569
574 char **w = p.we_wordv; 570 char **w = p.we_wordv;
@@ -576,10 +572,7 @@ bool load_include_configs(const char *path, struct sway_config *config,
576 for (i = 0; i < p.we_wordc; ++i) { 572 for (i = 0; i < p.we_wordc; ++i) {
577 bool found = load_include_config(w[i], parent_dir, config, swaynag); 573 bool found = load_include_config(w[i], parent_dir, config, swaynag);
578 if (!found) { 574 if (!found) {
579 wordfree(&p); 575 goto error_not_found;
580 free(parent_path);
581 free(wd);
582 return false;
583 } 576 }
584 } 577 }
585 free(parent_path); 578 free(parent_path);
@@ -594,6 +587,16 @@ bool load_include_configs(const char *path, struct sway_config *config,
594 587
595 free(wd); 588 free(wd);
596 return true; 589 return true;
590error_not_found:
591 wordfree(&p);
592error_wordexp:
593 if (chdir(wd) < 0) {
594 sway_log(SWAY_ERROR, "failed to restore working directory");
595 }
596error_chdir:
597 free(parent_path);
598 free(wd);
599 return false;
597} 600}
598 601
599void run_deferred_commands(void) { 602void run_deferred_commands(void) {