aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor E <38229097+c-edw@users.noreply.github.com>2019-02-24 04:39:08 +0000
committerDrew DeVault <sir@cmpwn.com>2019-02-25 17:10:04 -0500
commit401df9cff48351459d9f733432d0122384827e87 (patch)
tree86d5ab43f65191d2e7bb82cd6ad32ecfe91bf024
parent3924039bc09197de970a7ddb6d1ce0bc412edc84 (diff)
downloadsway-401df9cff48351459d9f733432d0122384827e87.zip
sway-401df9cff48351459d9f733432d0122384827e87.tar.gz
sway-401df9cff48351459d9f733432d0122384827e87.tar.bz2
Make load_include_configs void. Fix some cases where WD would not be restored.
-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 54cdcc9..ab494e7 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);
/**
* Loads an included config. Can only be used after load_main_config.
*/
-bool load_include_configs(const char *path, struct sway_config *config,
+void load_include_configs(const char *path, struct sway_config *config,
struct swaynag_instance *swaynag);
/**
diff --git a/sway/commands/include.c b/sway/commands/include.c
index d180985..d4c14c3 100644
--- a/sway/commands/include.c
+++ b/sway/commands/include.c
@@ -7,11 +7,8 @@ struct cmd_results *cmd_include(int argc, char **argv) {
return error;
}
- if (!load_include_configs(argv[0], config,
- &config->swaynag_config_errors)) {
- return cmd_results_new(CMD_INVALID,
- "Failed to include sub configuration file: %s", argv[0]);
- }
+ // We don't care if the included config(s) fails to load.
+ load_include_configs(argv[0], config, &config->swaynag_config_errors);
return cmd_results_new(CMD_SUCCESS, NULL);
}
diff --git a/sway/config.c b/sway/config.c
index 206ca95..4cd21bb 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,
return true;
}
-bool load_include_configs(const char *path, struct sway_config *config,
+void load_include_configs(const char *path, struct sway_config *config,
struct swaynag_instance *swaynag) {
char *wd = getcwd(NULL, 0);
char *parent_path = strdup(config->current_config_path);
const char *parent_dir = dirname(parent_path);
if (chdir(parent_dir) < 0) {
- free(parent_path);
- free(wd);
- return false;
+ sway_log(SWAY_ERROR, "failed to change working directory");
+ goto cleanup;
}
wordexp_t p;
-
- if (wordexp(path, &p, 0) != 0) {
- free(parent_path);
- free(wd);
- return false;
+ if (wordexp(path, &p, 0) == 0) {
+ char **w = p.we_wordv;
+ size_t i;
+ for (i = 0; i < p.we_wordc; ++i) {
+ load_include_config(w[i], parent_dir, config, swaynag);
+ }
+ wordfree(&p);
}
- char **w = p.we_wordv;
- size_t i;
- for (i = 0; i < p.we_wordc; ++i) {
- load_include_config(w[i], parent_dir, config, swaynag);
- }
- free(parent_path);
- wordfree(&p);
-
- // restore wd
+ // Attempt to restore working directory before returning.
if (chdir(wd) < 0) {
- free(wd);
- sway_log(SWAY_ERROR, "failed to restore working directory");
- return false;
+ sway_log(SWAY_ERROR, "failed to change working directory");
}
-
+cleanup:
+ free(parent_path);
free(wd);
- return true;
}
void run_deferred_commands(void) {