From 22f4b02b445d5f18155c0640e68cd37e36b4677c Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 9 Oct 2017 15:11:53 +0300 Subject: [PATCH] MXS-1464 Substitute environment variables If 'substitute_variables' has been set to true, then the value of a parameter like `some_param=$SOME_VAR' is replaced with the value of the environment variable 'SOME_VAR'. It is a fatal error to refer to a variable that does not exist. --- server/core/config.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/core/config.cc b/server/core/config.cc index a72fd824e..a10ab4161 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -460,8 +460,25 @@ void fix_section_name(char *section) */ static int ini_handler(void *userdata, const char *section, const char *name, const char *value) { - CONFIG_CONTEXT *cntxt = (CONFIG_CONTEXT *)userdata; - CONFIG_CONTEXT *ptr = cntxt; + CONFIG_CONTEXT *cntxt = (CONFIG_CONTEXT *)userdata; + CONFIG_CONTEXT *ptr = cntxt; + + if (config_get_global_options()->substitute_variables) + { + if (*value == '$') + { + char* env_value = getenv(value + 1); + + if (!env_value) + { + MXS_ERROR("The environment variable %s, used as value for parameter %s " + "in section %s, does not exist.", value, name, section); + return 0; + } + + value = env_value; + } + } if (strcmp(section, CN_GATEWAY) == 0 || strcasecmp(section, CN_MAXSCALE) == 0) {