diff options
| author | Pavel 'LEdoian' Turinsky <ledoian@matfyz.cz> | 2024-05-03 09:09:14 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2025-05-18 23:55:44 +0200 |
| commit | caeee85d8d50d9870c2cb35ad310bbca50cf4846 (patch) | |
| tree | d82c5c0ac4c2f5611ebfe2a237a7c46178e9bd14 | |
| parent | 6894b498a889d809093c920d397a42db7f5e4970 (diff) | |
Fix includes with relative paths
The function `load_include_configs` already changes the directory to the
one containing the parent config. Therefore, `load_include_config`
trying to assemble the "full" path leads to repetition of path segments,
making the `realpath` call fail with ENOENT.
Just calling `realpath` on the path itself from the directory with the
parent configuration is sufficient, so there is no point in passing
`parent_dir` to `load_include_config`.
(cherry picked from commit 6cac61b6b96c4a48a69f8ec3c06c2df560b01827)
| -rw-r--r-- | sway/config.c | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/sway/config.c b/sway/config.c index ec705968..d579022d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -552,28 +552,12 @@ bool load_main_config(const char *file, bool is_active, bool validating) { return success; } -static bool load_include_config(const char *path, const char *parent_dir, - struct sway_config *config, struct swaynag_instance *swaynag) { +static bool load_include_config(const char *path, struct sway_config *config, + struct swaynag_instance *swaynag) { // save parent config const char *parent_config = config->current_config_path; - char *full_path; - int len = strlen(path); - if (len >= 1 && path[0] != '/') { - len = len + strlen(parent_dir) + 2; - full_path = malloc(len * sizeof(char)); - if (!full_path) { - sway_log(SWAY_ERROR, - "Unable to allocate full path to included config"); - return false; - } - snprintf(full_path, len, "%s/%s", parent_dir, path); - } else { - full_path = strdup(path); - } - - char *real_path = realpath(full_path, NULL); - free(full_path); + char *real_path = realpath(path, NULL); if (real_path == NULL) { sway_log(SWAY_DEBUG, "%s not found.", path); @@ -625,7 +609,7 @@ void load_include_configs(const char *path, struct sway_config *config, 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); + load_include_config(w[i], config, swaynag); } wordfree(&p); } |
