From: David Goulet Date: Wed, 14 May 2014 15:01:43 +0000 (-0400) Subject: Fix: load all possible path for sessiond conf file X-Git-Tag: v2.5.0-rc1~43 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7ab02a271869642f4b34d4bd4dd9a68b3207271d;p=lttng-tools.git Fix: load all possible path for sessiond conf file The session daemon now tries to load the system wide conf. file, user local and finally the command line. Fixes #709 Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 3a8a1b27c..0a2f3f48f 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -4258,6 +4258,9 @@ static int set_option(int opt, const char *arg, const char *optname) ret = -ENOMEM; } break; + case 'f': + /* This is handled in set_options() thus silent break. */ + break; default: /* Unknown option or other error. * Error is printed by getopt, just return */ diff --git a/src/common/config/config.c b/src/common/config/config.c index 829a645bb..cdc044d6d 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -191,55 +191,73 @@ int config_get_section_entries(const char *override_path, const char *section, config_entry_handler_cb handler, void *user_data) { int ret = 0; + char *path; FILE *config_file = NULL; struct handler_filter_args filter = { section, handler, user_data }; - if (override_path) { - config_file = fopen(override_path, "r"); - if (config_file) { - DBG("Loaded daemon configuration file at %s", - override_path); - } else { - ERR("Failed to open daemon configuration file at %s", - override_path); - ret = -ENOENT; - goto end; - } - } else { - char *path = utils_get_home_dir(); + /* First, try system-wide conf. file. */ + path = DEFAULT_DAEMON_SYSTEM_CONFIGPATH; - /* Try to open the user's daemon configuration file */ - if (path) { - ret = asprintf(&path, DEFAULT_DAEMON_HOME_CONFIGPATH, path); - if (ret < 0) { - goto end; - } + config_file = fopen(path, "r"); + if (config_file) { + DBG("Loading daemon conf file at %s", path); + /* + * Return value is not very important here since error or not, we + * continue and try the next possible conf. file. + */ + (void) ini_parse_file(config_file, + (ini_entry_handler) config_entry_handler_filter, + (void *) &filter); + fclose(config_file); + } - ret = 0; - config_file = fopen(path, "r"); - if (config_file) { - DBG("Loaded daemon configuration file at %s", path); - } + /* Second is the user local configuration. */ + path = utils_get_home_dir(); + if (path) { + char fullpath[PATH_MAX]; - free(path); + ret = snprintf(fullpath, sizeof(fullpath), + DEFAULT_DAEMON_HOME_CONFIGPATH, path); + if (ret < 0) { + PERROR("snprintf user conf. path"); + goto error; } - /* Try to open the system daemon configuration file */ - if (!config_file) { - config_file = fopen(DEFAULT_DAEMON_HOME_CONFIGPATH, "r"); + config_file = fopen(fullpath, "r"); + if (config_file) { + DBG("Loading daemon user conf file at %s", path); + /* + * Return value is not very important here since error or not, we + * continue and try the next possible conf. file. + */ + (void) ini_parse_file(config_file, + (ini_entry_handler) config_entry_handler_filter, + (void *) &filter); + fclose(config_file); } } - if (!config_file) { - DBG("No daemon configuration file found."); - goto end; + /* Final path is the one that the user might have provided. */ + if (override_path) { + config_file = fopen(override_path, "r"); + if (config_file) { + DBG("Loading daemon command line conf file at %s", override_path); + (void) ini_parse_file(config_file, + (ini_entry_handler) config_entry_handler_filter, + (void *) &filter); + fclose(config_file); + } else { + ERR("Failed to open daemon configuration file at %s", + override_path); + ret = -ENOENT; + goto error; + } } - ret = ini_parse_file(config_file, - (ini_entry_handler) config_entry_handler_filter, (void *) &filter); + /* Everything went well. */ + ret = 0; - fclose(config_file); -end: +error: return ret; }