From a8b15f3a1b9111d0e0facd0ea413e8566a9d0a58 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 14 Jul 2022 18:28:56 +0100 Subject: [PATCH] config_libconfig: resolve symlinks when setting include dir If the config file is loaded from a symlink'd locaiton, it could be confusing that include dir is set based on the location of the symlink instead of the real file. Signed-off-by: Yuxuan Shui --- src/config_libconfig.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/config_libconfig.c b/src/config_libconfig.c index 03fb4b51..0e64869c 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -334,15 +334,14 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad config_set_options(&cfg, CONFIG_OPTION_ALLOW_OVERRIDES); #endif { - // dirname() could modify the original string, thus we must pass a - // copy - char *path2 = strdup(path); - char *parent = dirname(path2); + char *abspath = realpath(path, NULL); + char *parent = dirname(abspath); // path2 may be modified - if (parent) + if (parent) { config_set_include_dir(&cfg, parent); + } - free(path2); + free(abspath); } {