MXS-1446: Minor refactoring of gateway.cc
Cleaned up parts of the main function and moved the global configuration initialization to the very beginning of the main function.
This commit is contained in:
@ -158,7 +158,6 @@ static char *config_get_value(MXS_CONFIG_PARAMETER *, const char *);
|
|||||||
static char *config_get_password(MXS_CONFIG_PARAMETER *);
|
static char *config_get_password(MXS_CONFIG_PARAMETER *);
|
||||||
static const char* config_get_value_string(const MXS_CONFIG_PARAMETER *params, const char *name);
|
static const char* config_get_value_string(const MXS_CONFIG_PARAMETER *params, const char *name);
|
||||||
static int handle_global_item(const char *, const char *);
|
static int handle_global_item(const char *, const char *);
|
||||||
static void global_defaults();
|
|
||||||
static bool check_config_objects(CONFIG_CONTEXT *context);
|
static bool check_config_objects(CONFIG_CONTEXT *context);
|
||||||
static int maxscale_getline(char** dest, int* size, FILE* file);
|
static int maxscale_getline(char** dest, int* size, FILE* file);
|
||||||
static bool check_first_last_char(const char* string, char expected);
|
static bool check_first_last_char(const char* string, char expected);
|
||||||
@ -831,8 +830,6 @@ config_load(const char *filename)
|
|||||||
{
|
{
|
||||||
ss_dassert(!config_file);
|
ss_dassert(!config_file);
|
||||||
|
|
||||||
global_defaults();
|
|
||||||
|
|
||||||
config_file = filename;
|
config_file = filename;
|
||||||
bool rval = config_load_and_process(filename, process_config_context);
|
bool rval = config_load_and_process(filename, process_config_context);
|
||||||
|
|
||||||
@ -855,8 +852,6 @@ bool config_reload()
|
|||||||
MXS_FREE(gateway.version_string);
|
MXS_FREE(gateway.version_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
global_defaults();
|
|
||||||
|
|
||||||
rval = config_load_and_process(config_file, process_config_update);
|
rval = config_load_and_process(config_file, process_config_update);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1737,11 +1732,7 @@ SSL_LISTENER* make_ssl_structure (CONFIG_CONTEXT *obj, bool require_cert, int *e
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void config_set_global_defaults()
|
||||||
* Set the defaults for the global configuration options
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
global_defaults()
|
|
||||||
{
|
{
|
||||||
uint8_t mac_addr[6] = "";
|
uint8_t mac_addr[6] = "";
|
||||||
struct utsname uname_data;
|
struct utsname uname_data;
|
||||||
@ -1753,6 +1744,9 @@ global_defaults()
|
|||||||
gateway.auth_read_timeout = DEFAULT_AUTH_READ_TIMEOUT;
|
gateway.auth_read_timeout = DEFAULT_AUTH_READ_TIMEOUT;
|
||||||
gateway.auth_write_timeout = DEFAULT_AUTH_WRITE_TIMEOUT;
|
gateway.auth_write_timeout = DEFAULT_AUTH_WRITE_TIMEOUT;
|
||||||
gateway.skip_permission_checks = false;
|
gateway.skip_permission_checks = false;
|
||||||
|
gateway.syslog = 1;
|
||||||
|
gateway.maxlog = 1;
|
||||||
|
gateway.log_to_shm = 0;
|
||||||
gateway.admin_port = DEFAULT_ADMIN_HTTP_PORT;
|
gateway.admin_port = DEFAULT_ADMIN_HTTP_PORT;
|
||||||
gateway.admin_auth = true;
|
gateway.admin_auth = true;
|
||||||
gateway.admin_log_auth_failures = true;
|
gateway.admin_log_auth_failures = true;
|
||||||
|
@ -1248,11 +1248,6 @@ bool set_dirs(const char *basedir)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rc = MAXSCALE_SHUTDOWN;
|
int rc = MAXSCALE_SHUTDOWN;
|
||||||
int l;
|
|
||||||
int i;
|
|
||||||
int n;
|
|
||||||
int ini_rval;
|
|
||||||
intptr_t thread_id;
|
|
||||||
int n_threads; /*< number of epoll listener threads */
|
int n_threads; /*< number of epoll listener threads */
|
||||||
size_t thread_stack_size;
|
size_t thread_stack_size;
|
||||||
int n_services;
|
int n_services;
|
||||||
@ -1276,14 +1271,13 @@ int main(int argc, char **argv)
|
|||||||
bool config_check = false;
|
bool config_check = false;
|
||||||
bool to_stdout = false;
|
bool to_stdout = false;
|
||||||
void (*exitfunp[4])(void) = { mxs_log_finish, cleanup_process_datadir, write_footer, NULL };
|
void (*exitfunp[4])(void) = { mxs_log_finish, cleanup_process_datadir, write_footer, NULL };
|
||||||
MXS_CONFIG* cnf = NULL;
|
|
||||||
int numlocks = 0;
|
int numlocks = 0;
|
||||||
bool pid_file_created = false;
|
bool pid_file_created = false;
|
||||||
Worker* worker;
|
Worker* worker;
|
||||||
|
|
||||||
*syslog_enabled = 1;
|
config_set_global_defaults();
|
||||||
*maxlog_enabled = 1;
|
MXS_CONFIG* cnf = config_get_global_options();
|
||||||
*log_to_shm = 0;
|
ss_dassert(cnf);
|
||||||
|
|
||||||
maxscale_reset_starttime();
|
maxscale_reset_starttime();
|
||||||
|
|
||||||
@ -1293,12 +1287,16 @@ int main(int argc, char **argv)
|
|||||||
snprintf(datadir, PATH_MAX, "%s", default_datadir);
|
snprintf(datadir, PATH_MAX, "%s", default_datadir);
|
||||||
datadir[PATH_MAX] = '\0';
|
datadir[PATH_MAX] = '\0';
|
||||||
file_write_header(stderr);
|
file_write_header(stderr);
|
||||||
|
|
||||||
|
// Option string for getopt
|
||||||
|
const char accepted_opts[] = "dcf:g:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:H:";
|
||||||
|
|
||||||
/*<
|
/*<
|
||||||
* Register functions which are called at exit.
|
* Register functions which are called at exit.
|
||||||
*/
|
*/
|
||||||
for (i = 0; exitfunp[i] != NULL; i++)
|
for (int i = 0; exitfunp[i] != NULL; i++)
|
||||||
{
|
{
|
||||||
l = atexit(*exitfunp);
|
int l = atexit(*exitfunp);
|
||||||
|
|
||||||
if (l != 0)
|
if (l != 0)
|
||||||
{
|
{
|
||||||
@ -1310,10 +1308,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GLIBC
|
#ifdef HAVE_GLIBC
|
||||||
while ((opt = getopt_long(argc, argv, "dcf:g:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:H:",
|
while ((opt = getopt_long(argc, argv, accepted_opts,
|
||||||
long_options, &option_index)) != -1)
|
long_options, &option_index)) != -1)
|
||||||
#else
|
#else
|
||||||
while ((opt = getopt(argc, argv, "dcf:g:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:H:")) != -1)
|
while ((opt = getopt(argc, argv, accepted_opts)) != -1)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
bool succp = true;
|
bool succp = true;
|
||||||
@ -1719,7 +1717,7 @@ int main(int argc, char **argv)
|
|||||||
goto return_main;
|
goto return_main;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < numlocks + 1; i++)
|
for (int i = 0; i < numlocks + 1; i++)
|
||||||
{
|
{
|
||||||
spinlock_init(&ssl_locks[i]);
|
spinlock_init(&ssl_locks[i]);
|
||||||
}
|
}
|
||||||
@ -1865,9 +1863,6 @@ int main(int argc, char **argv)
|
|||||||
goto return_main;
|
goto return_main;
|
||||||
}
|
}
|
||||||
|
|
||||||
cnf = config_get_global_options();
|
|
||||||
ss_dassert(cnf);
|
|
||||||
|
|
||||||
if (!qc_setup(cnf->qc_name, cnf->qc_sql_mode, cnf->qc_args))
|
if (!qc_setup(cnf->qc_name, cnf->qc_sql_mode, cnf->qc_args))
|
||||||
{
|
{
|
||||||
const char* logerr = "Failed to initialise query classifier library.";
|
const char* logerr = "Failed to initialise query classifier library.";
|
||||||
@ -2020,7 +2015,7 @@ int main(int argc, char **argv)
|
|||||||
* Start workers. We start from 1, worker 0 will be running in the main thread.
|
* Start workers. We start from 1, worker 0 will be running in the main thread.
|
||||||
*/
|
*/
|
||||||
thread_stack_size = config_thread_stack_size();
|
thread_stack_size = config_thread_stack_size();
|
||||||
for (i = 1; i < n_threads; i++)
|
for (int i = 1; i < n_threads; i++)
|
||||||
{
|
{
|
||||||
worker = Worker::get(i);
|
worker = Worker::get(i);
|
||||||
ss_dassert(worker);
|
ss_dassert(worker);
|
||||||
@ -2089,7 +2084,7 @@ int main(int argc, char **argv)
|
|||||||
/*<
|
/*<
|
||||||
* Wait for worker threads to exit.
|
* Wait for worker threads to exit.
|
||||||
*/
|
*/
|
||||||
for (i = 1; i < n_threads; i++)
|
for (int i = 1; i < n_threads; i++)
|
||||||
{
|
{
|
||||||
worker = Worker::get(i);
|
worker = Worker::get(i);
|
||||||
ss_dassert(worker);
|
ss_dassert(worker);
|
||||||
|
@ -42,6 +42,11 @@ extern const char *config_monitor_params[];
|
|||||||
extern const char *config_filter_params[];
|
extern const char *config_filter_params[];
|
||||||
extern const char *config_server_params[];
|
extern const char *config_server_params[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the defaults for the global configuration options
|
||||||
|
*/
|
||||||
|
void config_set_global_defaults();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generate default module parameters
|
* @brief Generate default module parameters
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user