diff --git a/server/core/config.cc b/server/core/config.cc index 4ab3ccf01..f3f42037d 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -570,6 +570,11 @@ static bool is_maxscale_section(const char* section) static bool is_root_config_file = true; +static int ini_global_handler(void *userdata, const char *section, const char *name, const char *value) +{ + return is_maxscale_section(section) ? handle_global_item(name, value) : 1; +} + /** * Config item handler for the ini file reader * @@ -673,11 +678,7 @@ static int ini_handler(void *userdata, const char *section, const char *name, co if (is_maxscale_section(section)) { - if (is_root_config_file || is_persisted_config) - { - return handle_global_item(name, value); - } - else + if (!is_root_config_file && !is_persisted_config) { MXS_ERROR("The [maxscale] section must only be defined in the root configuration file."); return 0; @@ -687,6 +688,29 @@ static int ini_handler(void *userdata, const char *section, const char *name, co return 1; } +static void log_config_error(const char* file, int rval) +{ + char errorbuffer[1024 + 1]; + + if (rval > 0) + { + snprintf(errorbuffer, sizeof(errorbuffer), + "Failed to parse configuration file %s. Error on line %d.", file, rval); + } + else if (rval == -1) + { + snprintf(errorbuffer, sizeof(errorbuffer), + "Failed to parse configuration file %s. Could not open file.", file); + } + else + { + snprintf(errorbuffer, sizeof(errorbuffer), + "Failed to parse configuration file %s. Memory allocation failed.", file); + } + + MXS_ERROR("%s", errorbuffer); +} + /** * Load single configuration file. * @@ -710,25 +734,7 @@ static bool config_load_single_file(const char* file, { if ((rval = ini_parse(file, ini_handler, ccontext)) != 0) { - char errorbuffer[1024 + 1]; - - if (rval > 0) - { - snprintf(errorbuffer, sizeof(errorbuffer), - "Failed to parse configuration file %s. Error on line %d.", file, rval); - } - else if (rval == -1) - { - snprintf(errorbuffer, sizeof(errorbuffer), - "Failed to parse configuration file %s. Could not open file.", file); - } - else - { - snprintf(errorbuffer, sizeof(errorbuffer), - "Failed to parse configuration file %s. Memory allocation failed.", file); - } - - MXS_ERROR("%s", errorbuffer); + log_config_error(file, rval); } } @@ -1075,6 +1081,18 @@ config_load_and_process(const char* filename, bool (*process_config)(CONFIG_CONT return rval; } +bool config_load_global(const char *filename) +{ + int rval; + + if ((rval = ini_parse(filename, ini_global_handler, NULL)) != 0) + { + log_config_error(filename, rval); + } + + return rval == 0; +} + /** * @brief Load the configuration file for the MaxScale * diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 001472282..fe488fae4 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -1890,6 +1890,12 @@ int main(int argc, char **argv) } } + if (!config_load_global(cnf_file_path)) + { + rc = MAXSCALE_BADCONFIG; + goto return_main; + } + if (daemon_mode) { if (!change_cwd()) diff --git a/server/core/internal/config.h b/server/core/internal/config.h index 9fed61ade..1d312d661 100644 --- a/server/core/internal/config.h +++ b/server/core/internal/config.h @@ -75,6 +75,7 @@ void config_add_defaults(CONFIG_CONTEXT *ctx, const MXS_MODULE_PARAM *params); char* config_clean_string_list(const char* str); MXS_CONFIG_PARAMETER* config_clone_param(const MXS_CONFIG_PARAMETER* param); bool config_load(const char *); +bool config_load_global(const char *filename); void config_parameter_free(MXS_CONFIG_PARAMETER* p1); /**