mysql_library_end is not called if it wasn't initialized properly.

This commit is contained in:
vraatikka
2013-08-12 13:12:23 +03:00
parent 0c5125a44d
commit 64cb6eca56

View File

@ -89,9 +89,14 @@ static char datadir[1024] = "";
*/ */
static bool do_exit = FALSE; static bool do_exit = FALSE;
/**
* Flag to indicate whether libmysqld is successfully initialized.
*/
static bool libmysqld_started = FALSE;
static void log_flush_shutdown(void); static void log_flush_shutdown(void);
static void log_flush_cb(void* arg); static void log_flush_cb(void* arg);
static void libmysqld_done(void);
/** /**
* Handler for SIGHUP signal. Reload the configuration for the * Handler for SIGHUP signal. Reload the configuration for the
@ -228,6 +233,15 @@ char buf[1024];
} }
} }
static libmysqld_done(void)
{
if (libmysqld_started) {
mysql_library_end();
}
}
/** /**
* The main entry point into the gateway * The main entry point into the gateway
* *
@ -271,14 +285,14 @@ ssize_t log_flush_timeout_ms = 0;
while (argv[n][s] == 0 && s<10) s++; while (argv[n][s] == 0 && s<10) s++;
if (s==10) { if (s==10) {
skygw_log_write( skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"Fatal : missing file name. \n" "Fatal : missing file name. \n"
"Unable to find a MaxScale configuration file, " "Unable to find a MaxScale configuration file, "
"either install one in /etc/MaxScale.cnf, " "either install one in /etc/MaxScale.cnf, "
"$MAXSCALE_HOME/etc/MaxScale.cnf " "$MAXSCALE_HOME/etc/MaxScale.cnf "
"or use the -c option with configuration file name." "or use the -c option with configuration file "
" Exiting.\n"); "name. Exiting.\n");
} }
cnf_file = &argv[n][s]; cnf_file = &argv[n][s];
} }
@ -325,8 +339,8 @@ ssize_t log_flush_timeout_ms = 0;
gw_daemonize(); gw_daemonize();
} }
l = atexit(mysql_library_end); l = atexit(libmysqld_done);
if (l != 0) { if (l != 0) {
fprintf(stderr, "Couldn't register exit function.\n"); fprintf(stderr, "Couldn't register exit function.\n");
} }
@ -383,8 +397,9 @@ ssize_t log_flush_timeout_ms = 0;
if (cnf_file == NULL) { if (cnf_file == NULL) {
skygw_log_write_flush( skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Fatal : Unable to find a MaxScale configuration file, either " "Fatal : Unable to find a MaxScale configuration "
"install one in /etc/MaxScale.cnf, $MAXSCALE_HOME/etc/MaxScale.cnf " "file, either install one in /etc/MaxScale.cnf, "
"$MAXSCALE_HOME/etc/MaxScale.cnf "
"or use the -c option. Exiting.\n"); "or use the -c option. Exiting.\n");
exit(1); exit(1);
} }
@ -412,6 +427,7 @@ ssize_t log_flush_timeout_ms = 0;
__LINE__); __LINE__);
exit(1); exit(1);
} }
libmysqld_started = TRUE;
if (!config_load(cnf_file)) if (!config_load(cnf_file))
{ {
@ -455,13 +471,13 @@ ssize_t log_flush_timeout_ms = 0;
thread_wait(threads[n]); thread_wait(threads[n]);
/** /**
* Wait the timer thread. * Wait the flush thread.
*/ */
thread_wait(log_flush_thr); thread_wait(log_flush_thr);
/* Stop all the monitors */ /* Stop all the monitors */
monitorStopAll(); monitorStopAll();
skygw_log_write( skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"MaxScale shutdown, PID %i\n", "MaxScale shutdown, PID %i\n",