From 3f4c72d4f2cc6dc5ae095da1dc0e8ca6a2f9908c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 30 Jan 2019 15:26:55 +0200 Subject: [PATCH] MXS-2303: Fix missing parameter error The detection of missing parameters that define which module to load must be done before the module is loaded. --- server/core/config.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/server/core/config.cc b/server/core/config.cc index 8c3078929..d3d395a08 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -1291,6 +1291,34 @@ const MXS_MODULE* get_module(CONFIG_CONTEXT* obj, const char* param_name, const return module ? get_module(module, module_type) : NULL; } +const char* get_missing_module_parameter_name(const CONFIG_CONTEXT* obj) +{ + std::string type = config_get_string(obj->parameters, CN_TYPE); + + if (type == CN_SERVICE && !config_get_param(obj->parameters, CN_ROUTER)) + { + return CN_ROUTER; + } + else if (type == CN_LISTENER && !config_get_param(obj->parameters, CN_PROTOCOL)) + { + return CN_PROTOCOL; + } + else if (type == CN_SERVER && !config_get_param(obj->parameters, CN_PROTOCOL)) + { + return CN_PROTOCOL; + } + else if (type == CN_MONITOR && !config_get_param(obj->parameters, CN_MODULE)) + { + return CN_MODULE; + } + else if (type == CN_FILTER && !config_get_param(obj->parameters, CN_MODULE)) + { + return CN_MODULE; + } + + return nullptr; +} + std::pair get_module_details(const CONFIG_CONTEXT* obj) { std::string type = config_get_string(obj->parameters, CN_TYPE); @@ -3044,6 +3072,15 @@ static bool check_config_objects(CONFIG_CONTEXT* context) continue; } + const char* no_module_defined = get_missing_module_parameter_name(obj); + + if (no_module_defined) + { + MXS_ERROR("'%s' is missing the required parameter '%s'", obj->object, no_module_defined); + rval = false; + continue; + } + const MXS_MODULE_PARAM* param_set = nullptr; const MXS_MODULE* mod = nullptr; std::tie(param_set, mod) = get_module_details(obj);