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.
This commit is contained in:
Johan Wikman
2017-10-09 15:11:53 +03:00
parent 1666c9f0b6
commit 22f4b02b44

View File

@ -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) static int ini_handler(void *userdata, const char *section, const char *name, const char *value)
{ {
CONFIG_CONTEXT *cntxt = (CONFIG_CONTEXT *)userdata; CONFIG_CONTEXT *cntxt = (CONFIG_CONTEXT *)userdata;
CONFIG_CONTEXT *ptr = cntxt; 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) if (strcmp(section, CN_GATEWAY) == 0 || strcasecmp(section, CN_MAXSCALE) == 0)
{ {