diff --git a/src/base/config.c b/src/base/config.c index eaa1159c2c04c9b7f5c7fdda83e5e33260435444..897cfccecbf60acc1617365b5d058b5156cf947a 100644 --- a/src/base/config.c +++ b/src/base/config.c @@ -26,24 +26,17 @@ skip(char *s) return s; } -static int +PRIVATE_FUNCTION int handler(lkt_db *user, const char *section, const char *name, const char *value) { - RETURN_UNLESS(section && name && value, "I can't complete the database with incomplete lines", - 1); - RETURN_UNLESS(database_config_set(user, section, name, value), "Failed to update the database", - 1); + RETURN_UNLESS(section && name && value, "Skip incomplete line", 1); + RETURN_UNLESS(database_config_set(user, section, name, value), "Failed to update config", 1); return 0; } -static inline void -__set_log_level(const char *name, const char *level) +PRIVATE_FUNCTION void +___set_log_level_internal(const char *level) { - if (!STR_MATCH(name, "log")) { - LOG_WARN("CONFIG", "Invalid option '%s[:=]%s' with no section", name, level); - return; - } - if (!level[0]) { LOG_WARN("CONFIG", "Invalid empty 'log' option"); return; @@ -63,7 +56,33 @@ __set_log_level(const char *name, const char *level) LOG_INFO("CONFIG", "Log level set to %d", lkt_get_log_level()); } -static inline int +PRIVATE_FUNCTION void +___set_log_level(const char *name, const char *level) +{ + /* Just check the key name here */ + if (!STR_MATCH(name, "log")) { + LOG_WARN("CONFIG", "Invalid option '%s[:=]%s' with no section", name, level); + return; + } + ___set_log_level_internal(level); +} + +PRIVATE_FUNCTION void +___apply_log_level(lkt_db *db) +{ + char loglevel[LKT_LINE_MAX]; + if (!database_config_get_text_nospace(db, "log", "level", loglevel, LKT_LINE_MAX)) { + /* 'log/level' is not present, use the '/log' */ + LOG_DEBUG("CONFIG", "No entry in config for 'log/level', set it to the '/log' entry"); + safe_snprintf(loglevel, LKT_LINE_MAX, "%d", lkt_get_log_level()); + database_config_set(db, "log", "level", loglevel); + } else { + /* 'log/level' is present, use that one */ + ___set_log_level_internal(loglevel); + } +} + +PRIVATE_FUNCTION int ini_parse(const char *path, lkt_db *db) { char *start, *end, *name, *value; @@ -132,8 +151,10 @@ ini_parse(const char *path, lkt_db *db) LOG_ERROR("PARSER", "Failed to '[handle] %s, %s{:,=}%s' at line '%d'", section, name, value, linenum); } - } else - __set_log_level(name, value); + } else { + /* Keep for legacy reasons */ + ___set_log_level(name, value); + } } else { @@ -143,6 +164,8 @@ ini_parse(const char *path, lkt_db *db) } } + ___apply_log_level(db); + /* End of the function */ fclose(file); if (error)