X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fini-config%2Fini-config.cpp;h=ebfe153c276c593870df422ea5ea0c9ed6cad81a;hb=5c7248cd5bce45bf64d563fb4e130a63bf345f11;hp=797de0164d35303716c880a4d306cee10a5b5b8b;hpb=3299fd310c0fab63e912004cdd404d586f936f9e;p=lttng-tools.git diff --git a/src/common/ini-config/ini-config.cpp b/src/common/ini-config/ini-config.cpp index 797de0164..ebfe153c2 100644 --- a/src/common/ini-config/ini-config.cpp +++ b/src/common/ini-config/ini-config.cpp @@ -5,13 +5,14 @@ * */ -#include "ini-config.h" +#include "ini-config.hpp" + +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include #include LTTNG_EXPORT const char *config_str_yes = "yes"; @@ -21,14 +22,18 @@ LTTNG_EXPORT const char *config_str_no = "no"; LTTNG_EXPORT const char *config_str_false = "false"; LTTNG_EXPORT const char *config_str_off = "off"; +namespace { struct handler_filter_args { - const char* section; + const char *section; config_entry_handler_cb handler; void *user_data; }; +} /* namespace */ static int config_entry_handler_filter(struct handler_filter_args *args, - const char *section, const char *name, const char *value) + const char *section, + const char *name, + const char *value) { int ret = 0; struct config_entry entry = { section, name, value }; @@ -41,7 +46,7 @@ static int config_entry_handler_filter(struct handler_filter_args *args, } if (args->section) { - if (strcmp(args->section, section)) { + if (strcmp(args->section, section) != 0) { goto end; } } @@ -51,12 +56,14 @@ end: return ret; } -int config_get_section_entries(const char *override_path, const char *section, - config_entry_handler_cb handler, void *user_data) +int config_get_section_entries(const char *override_path, + const char *section, + config_entry_handler_cb handler, + void *user_data) { int ret = 0; const char *path; - FILE *config_file = NULL; + FILE *config_file = nullptr; struct handler_filter_args filter = { section, handler, user_data }; /* First, try system-wide conf. file. */ @@ -70,8 +77,8 @@ int config_get_section_entries(const char *override_path, const char *section, * continue and try the next possible conf. file. */ (void) ini_parse_file(config_file, - (ini_entry_handler) config_entry_handler_filter, - (void *) &filter); + (ini_entry_handler) config_entry_handler_filter, + (void *) &filter); fclose(config_file); } @@ -80,8 +87,7 @@ int config_get_section_entries(const char *override_path, const char *section, if (path) { char fullpath[PATH_MAX]; - ret = snprintf(fullpath, sizeof(fullpath), - DEFAULT_DAEMON_HOME_CONFIGPATH, path); + ret = snprintf(fullpath, sizeof(fullpath), DEFAULT_DAEMON_HOME_CONFIGPATH, path); if (ret < 0) { PERROR("snprintf user conf. path"); goto error; @@ -95,8 +101,8 @@ int config_get_section_entries(const char *override_path, const char *section, * continue and try the next possible conf. file. */ (void) ini_parse_file(config_file, - (ini_entry_handler) config_entry_handler_filter, - (void *) &filter); + (ini_entry_handler) config_entry_handler_filter, + (void *) &filter); fclose(config_file); } } @@ -107,12 +113,11 @@ int config_get_section_entries(const char *override_path, const char *section, 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); + (ini_entry_handler) config_entry_handler_filter, + (void *) &filter); fclose(config_file); } else { - ERR("Failed to open daemon configuration file at %s", - override_path); + ERR("Failed to open daemon configuration file at %s", override_path); ret = -ENOENT; goto error; } @@ -144,7 +149,7 @@ int config_parse_value(const char *value) goto end; } - lower_str = (char *) zmalloc(len + 1); + lower_str = zmalloc(len + 1); if (!lower_str) { PERROR("zmalloc"); ret = -errno; @@ -155,13 +160,11 @@ int config_parse_value(const char *value) lower_str[i] = tolower(value[i]); } - if (!strcmp(lower_str, config_str_yes) || - !strcmp(lower_str, config_str_true) || - !strcmp(lower_str, config_str_on)) { + if (!strcmp(lower_str, config_str_yes) || !strcmp(lower_str, config_str_true) || + !strcmp(lower_str, config_str_on)) { ret = 1; - } else if (!strcmp(lower_str, config_str_no) || - !strcmp(lower_str, config_str_false) || - !strcmp(lower_str, config_str_off)) { + } else if (!strcmp(lower_str, config_str_no) || !strcmp(lower_str, config_str_false) || + !strcmp(lower_str, config_str_off)) { ret = 0; } else { ret = -1;