diff options
author | 2019-02-24 04:39:08 +0000 | |
---|---|---|
committer | 2019-02-24 00:01:35 -0500 | |
commit | d4b1e71b919a52fbad0ba8191259eb4f14dfd1ab (patch) | |
tree | 5933eaa3a951f8b9cae3b63452f9c572b37be7b8 /sway/config.c | |
parent | Fix crash exiting fullscreened floating container (diff) | |
download | sway-d4b1e71b919a52fbad0ba8191259eb4f14dfd1ab.tar.gz sway-d4b1e71b919a52fbad0ba8191259eb4f14dfd1ab.tar.zst sway-d4b1e71b919a52fbad0ba8191259eb4f14dfd1ab.zip |
Make load_include_configs void. Fix some cases where WD would not be restored.
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/sway/config.c b/sway/config.c index 206ca95c..4cd21bbc 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -549,43 +549,34 @@ static bool load_include_config(const char *path, const char *parent_dir, | |||
549 | return true; | 549 | return true; |
550 | } | 550 | } |
551 | 551 | ||
552 | bool load_include_configs(const char *path, struct sway_config *config, | 552 | void load_include_configs(const char *path, struct sway_config *config, |
553 | struct swaynag_instance *swaynag) { | 553 | struct swaynag_instance *swaynag) { |
554 | char *wd = getcwd(NULL, 0); | 554 | char *wd = getcwd(NULL, 0); |
555 | char *parent_path = strdup(config->current_config_path); | 555 | char *parent_path = strdup(config->current_config_path); |
556 | const char *parent_dir = dirname(parent_path); | 556 | const char *parent_dir = dirname(parent_path); |
557 | 557 | ||
558 | if (chdir(parent_dir) < 0) { | 558 | if (chdir(parent_dir) < 0) { |
559 | free(parent_path); | 559 | sway_log(SWAY_ERROR, "failed to change working directory"); |
560 | free(wd); | 560 | goto cleanup; |
561 | return false; | ||
562 | } | 561 | } |
563 | 562 | ||
564 | wordexp_t p; | 563 | wordexp_t p; |
565 | 564 | if (wordexp(path, &p, 0) == 0) { | |
566 | if (wordexp(path, &p, 0) != 0) { | 565 | char **w = p.we_wordv; |
567 | free(parent_path); | 566 | size_t i; |
568 | free(wd); | 567 | for (i = 0; i < p.we_wordc; ++i) { |
569 | return false; | 568 | load_include_config(w[i], parent_dir, config, swaynag); |
569 | } | ||
570 | wordfree(&p); | ||
570 | } | 571 | } |
571 | 572 | ||
572 | char **w = p.we_wordv; | 573 | // Attempt to restore working directory before returning. |
573 | size_t i; | ||
574 | for (i = 0; i < p.we_wordc; ++i) { | ||
575 | load_include_config(w[i], parent_dir, config, swaynag); | ||
576 | } | ||
577 | free(parent_path); | ||
578 | wordfree(&p); | ||
579 | |||
580 | // restore wd | ||
581 | if (chdir(wd) < 0) { | 574 | if (chdir(wd) < 0) { |
582 | free(wd); | 575 | sway_log(SWAY_ERROR, "failed to change working directory"); |
583 | sway_log(SWAY_ERROR, "failed to restore working directory"); | ||
584 | return false; | ||
585 | } | 576 | } |
586 | 577 | cleanup: | |
578 | free(parent_path); | ||
587 | free(wd); | 579 | free(wd); |
588 | return true; | ||
589 | } | 580 | } |
590 | 581 | ||
591 | void run_deferred_commands(void) { | 582 | void run_deferred_commands(void) { |