Added more error messaging when the parsing of the configuration file fails.
This commit is contained in:
Markus Makela 2015-08-31 11:39:20 +03:00
parent 9d9b7bccfc
commit 386fa78a30
2 changed files with 38 additions and 3 deletions

View File

@ -271,7 +271,7 @@ int
config_load(char *file)
{
CONFIG_CONTEXT config;
int rval;
int rval, ini_rval;
MYSQL *conn;
conn = mysql_init(NULL);
@ -314,8 +314,23 @@ int rval;
config.object = "";
config.next = NULL;
if (ini_parse(file, handler, &config) < 0)
if (( ini_rval = ini_parse(file, handler, &config)) != 0)
{
char errorbuffer[1024 + 1];
if(ini_rval > 0)
snprintf(errorbuffer, 1024,
"Error: Failed to parse configuration file. Error on line %d.", ini_rval);
else if(ini_rval == -1)
snprintf(errorbuffer, 1024,
"Error: Failed to parse configuration file. Failed to open file.");
else
snprintf(errorbuffer, 1024,
"Error: Failed to parse configuration file. Memory allocation failed.");
skygw_log_write(LE, errorbuffer);
return 0;
}
config_file = file;

View File

@ -1055,6 +1055,7 @@ int main(int argc, char **argv)
int l;
int i;
int n;
int ini_rval;
intptr_t thread_id;
int n_threads; /*< number of epoll listener threads */
int n_services;
@ -1591,8 +1592,27 @@ int main(int argc, char **argv)
goto return_main;
}
if(ini_parse(cnf_file_path,cnf_preparser,NULL) != 0)
if((ini_rval = ini_parse(cnf_file_path,cnf_preparser,NULL)) != 0)
{
char errorbuffer[STRING_BUFFER_SIZE + 1];
if(ini_rval > 0)
snprintf(errorbuffer, STRING_BUFFER_SIZE,
"Error: Failed to pre-parse configuration file. Error on line %d.", ini_rval);
else if(ini_rval == -1)
snprintf(errorbuffer, STRING_BUFFER_SIZE,
"Error: Failed to pre-parse configuration file. Failed to open file.");
else
snprintf(errorbuffer, STRING_BUFFER_SIZE,
"Error: Failed to pre-parse configuration file. Memory allocation failed.");
skygw_log_write(LE, errorbuffer);
if(!daemon_mode)
{
strncat(errorbuffer,"\n",STRING_BUFFER_SIZE);
fprintf(stderr, errorbuffer);
}
rc = MAXSCALE_BADCONFIG;
goto return_main;
}