X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fconfig.c;h=4d855bf8a4f8dc0dcbbf3b27ff5e9be663540b93;hb=7ab70fe08ac9308e320d58a672feab0282c11d47;hp=b8a32e6e1f803218e0ba1f0aea10668d865a7dde;hpb=b2579dc14eacae00a596d8bb885620c9fa4e263d;p=lttng-tools.git diff --git a/src/common/config/config.c b/src/common/config/config.c index b8a32e6e1..4d855bf8a 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -154,6 +154,7 @@ const char * const config_event_context_vppid = "VPPID"; const char * const config_event_context_pthread_id = "PTHREAD_ID"; const char * const config_event_context_hostname = "HOSTNAME"; const char * const config_event_context_ip = "IP"; +const char * const config_event_context_perf_thread_counter = "PERF_THREAD_COUNTER"; struct consumer_output { int enabled; @@ -191,54 +192,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; -end: +error: return ret; } @@ -2436,7 +2456,7 @@ int load_session_from_path(const char *path, const char *session_name, continue; } - if (path_len + file_name_len > PATH_MAX) { + if (path_len + file_name_len >= PATH_MAX) { continue; }