aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/config.h2
-rw-r--r--sway/commands/include.c7
-rw-r--r--sway/config.c37
3 files changed, 17 insertions, 29 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index 54cdcc90..ab494e78 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -513,7 +513,7 @@ bool load_main_config(const char *path, bool is_active, bool validating);
513/** 513/**
514 * Loads an included config. Can only be used after load_main_config. 514 * Loads an included config. Can only be used after load_main_config.
515 */ 515 */
516bool load_include_configs(const char *path, struct sway_config *config, 516void load_include_configs(const char *path, struct sway_config *config,
517 struct swaynag_instance *swaynag); 517 struct swaynag_instance *swaynag);
518 518
519/** 519/**
diff --git a/sway/commands/include.c b/sway/commands/include.c
index d1809856..d4c14c35 100644
--- a/sway/commands/include.c
+++ b/sway/commands/include.c
@@ -7,11 +7,8 @@ struct cmd_results *cmd_include(int argc, char **argv) {
7 return error; 7 return error;
8 } 8 }
9 9
10 if (!load_include_configs(argv[0], config, 10 // We don't care if the included config(s) fails to load.
11 &config->swaynag_config_errors)) { 11 load_include_configs(argv[0], config, &config->swaynag_config_errors);
12 return cmd_results_new(CMD_INVALID,
13 "Failed to include sub configuration file: %s", argv[0]);
14 }
15 12
16 return cmd_results_new(CMD_SUCCESS, NULL); 13 return cmd_results_new(CMD_SUCCESS, NULL);
17} 14}
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
552bool load_include_configs(const char *path, struct sway_config *config, 552void 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 577cleanup:
578 free(parent_path);
587 free(wd); 579 free(wd);
588 return true;
589} 580}
590 581
591void run_deferred_commands(void) { 582void run_deferred_commands(void) {