MXS-1464 Add config 'substitute_variables'
With this variables set to true, if $VAR is used as a value in the configuration file, then `$VAR` will be replaced with the value of the environment variable VAR.
This commit is contained in:
@ -135,6 +135,7 @@ const char CN_SSL_CERT_VERIFY_DEPTH[] = "ssl_cert_verify_depth";
|
||||
const char CN_SSL_KEY[] = "ssl_key";
|
||||
const char CN_SSL_VERSION[] = "ssl_version";
|
||||
const char CN_STRIP_DB_ESC[] = "strip_db_esc";
|
||||
const char CN_SUBSTITUTE_VARIABLES[] = "substitute_variables";
|
||||
const char CN_THREADS[] = "threads";
|
||||
const char CN_THREAD_STACK_SIZE[] = "thread_stack_size";
|
||||
const char CN_TYPE[] = "type";
|
||||
@ -457,8 +458,7 @@ void fix_section_name(char *section)
|
||||
* @param value The Parameter value
|
||||
* @return zero on error
|
||||
*/
|
||||
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 *ptr = cntxt;
|
||||
|
@ -2617,6 +2617,24 @@ void set_log_augmentation(const char* value)
|
||||
static int cnf_preparser(void* data, const char* section, const char* name, const char* value)
|
||||
{
|
||||
MXS_CONFIG* cnf = config_get_global_options();
|
||||
|
||||
if (cnf->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;
|
||||
}
|
||||
}
|
||||
|
||||
char *tmp;
|
||||
/** These are read from the configuration file. These will not override
|
||||
* command line parameters but will override default values. */
|
||||
@ -2790,6 +2808,10 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
|
||||
cnf->log_to_shm = config_truth_value((char*)value);
|
||||
}
|
||||
}
|
||||
else if (strcmp(name, CN_SUBSTITUTE_VARIABLES) == 0)
|
||||
{
|
||||
cnf->substitute_variables = config_truth_value(value);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user