Partial merge of MXS-70
This commit is contained in:
parent
7cfb83554f
commit
0abcf349ff
@ -2480,3 +2480,12 @@ void config_add_param(CONFIG_CONTEXT* obj, char* key,char* value)
|
||||
nptr->next = obj->parameters;
|
||||
obj->parameters = nptr;
|
||||
}
|
||||
/**
|
||||
* Return the pointer to the global options for MaxScale.
|
||||
* @return Pointer to the GATEWAY_CONF structure. This is a static structure and
|
||||
* should not be modified.
|
||||
*/
|
||||
GATEWAY_CONF* config_get_global_options()
|
||||
{
|
||||
return &gateway;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
* Put example code behind SS_DEBUG macros.
|
||||
* 05/02/14 Mark Riddoch Addition of version string
|
||||
* 29/06/14 Massimiliano Pinto Addition of pidfile
|
||||
*
|
||||
* 10/08/15 Markus Makela Added configurable directory locations
|
||||
* @endverbatim
|
||||
*/
|
||||
#define _XOPEN_SOURCE 700
|
||||
@ -178,7 +178,7 @@ static struct option long_options[] = {
|
||||
static int cnf_preparser(void* data, const char* section, const char* name, const char* value);
|
||||
static void log_flush_shutdown(void);
|
||||
static void log_flush_cb(void* arg);
|
||||
static int write_pid_file(char *); /* write MaxScale pidfile */
|
||||
static int write_pid_file(); /* write MaxScale pidfile */
|
||||
static void unlink_pidfile(void); /* remove pidfile */
|
||||
static void libmysqld_done(void);
|
||||
static bool file_write_header(FILE* outfile);
|
||||
@ -978,7 +978,7 @@ return_cnf_file_buf:
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"\nUsage : %s [OPTION]...\n\n"
|
||||
"\nUsage : %s [OPTION]...\n\n"
|
||||
" -d, --nodaemon enable running in terminal process (default:disabled)\n"
|
||||
" -f, --config=FILE relative|absolute pathname of MaxScale configuration file\n"
|
||||
" (default:/etc/maxscale.cnf)\n"
|
||||
@ -993,6 +993,8 @@ static void usage(void)
|
||||
" (default: /etc/)\n"
|
||||
" -D, --datadir=PATH path to data directory, stored embedded mysql tables\n"
|
||||
" (default: /var/cache/maxscale)\n"
|
||||
" -N, --language=PATH apth to errmsg.sys file\n"
|
||||
" (default: /var/lib/maxscale)\n"
|
||||
" -P, --piddir=PATH path to PID file directory\n"
|
||||
" (default: /var/run/maxscale)\n"
|
||||
" -U, --user=USER run MaxScale as another user.\n"
|
||||
@ -1049,7 +1051,6 @@ int main(int argc, char **argv)
|
||||
char mysql_home[PATH_MAX+1];
|
||||
char datadir_arg[10+PATH_MAX+1]; /*< '--datadir=' + PATH_MAX */
|
||||
char language_arg[11+PATH_MAX+1]; /*< '--language=' + PATH_MAX */
|
||||
char* home_dir = NULL; /*< home dir, to be freed */
|
||||
char* cnf_file_path = NULL; /*< conf file, to be freed */
|
||||
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
|
||||
void* log_flush_thr = NULL;
|
||||
@ -1057,8 +1058,8 @@ int main(int argc, char **argv)
|
||||
char* tmp_var;
|
||||
int option_index;
|
||||
int logtofile = 0; /* Use shared memory or file */
|
||||
int syslog_enabled = 0; /** Log to syslog */
|
||||
int maxscalelog_enabled = 1; /** Log with MaxScale */
|
||||
int *syslog_enabled = &config_get_global_options()->syslog; /** Log to syslog */
|
||||
int *maxscalelog_enabled = &config_get_global_options()->maxlog; /** Log with MaxScale */
|
||||
ssize_t log_flush_timeout_ms = 0;
|
||||
sigset_t sigset;
|
||||
sigset_t sigpipe_mask;
|
||||
@ -1068,7 +1069,8 @@ int main(int argc, char **argv)
|
||||
write_footer,
|
||||
NULL};
|
||||
|
||||
|
||||
*syslog_enabled = 0;
|
||||
*maxscalelog_enabled = 1;
|
||||
|
||||
sigemptyset(&sigpipe_mask);
|
||||
sigaddset(&sigpipe_mask, SIGPIPE);
|
||||
@ -1160,20 +1162,20 @@ int main(int argc, char **argv)
|
||||
|
||||
if(handle_path_arg(&tmp_path,optarg,NULL,true,false))
|
||||
{
|
||||
logdir = tmp_path;
|
||||
set_logdir(tmp_path);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'N':
|
||||
if(handle_path_arg(&tmp_path,optarg,NULL,true,false))
|
||||
{
|
||||
langdir = tmp_path;
|
||||
set_langdir(tmp_path);
|
||||
}
|
||||
break;
|
||||
case 'P':
|
||||
if(handle_path_arg(&tmp_path,optarg,NULL,true,true))
|
||||
{
|
||||
piddir = tmp_path;
|
||||
set_piddir(tmp_path);
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
@ -1184,7 +1186,7 @@ int main(int argc, char **argv)
|
||||
case 'C':
|
||||
if(handle_path_arg(&tmp_path,optarg,NULL,true,false))
|
||||
{
|
||||
configdir = tmp_path;
|
||||
set_configdir(tmp_path);
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
@ -1206,11 +1208,11 @@ int main(int argc, char **argv)
|
||||
{
|
||||
tok++;
|
||||
if(tok)
|
||||
maxscalelog_enabled = config_truth_value(tok);
|
||||
*maxscalelog_enabled = config_truth_value(tok);
|
||||
}
|
||||
else
|
||||
{
|
||||
maxscalelog_enabled = config_truth_value(optarg);
|
||||
*maxscalelog_enabled = config_truth_value(optarg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1221,11 +1223,11 @@ int main(int argc, char **argv)
|
||||
{
|
||||
tok++;
|
||||
if(tok)
|
||||
syslog_enabled = config_truth_value(tok);
|
||||
*syslog_enabled = config_truth_value(tok);
|
||||
}
|
||||
else
|
||||
{
|
||||
syslog_enabled = config_truth_value(optarg);
|
||||
*syslog_enabled = config_truth_value(optarg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1539,7 +1541,7 @@ int main(int argc, char **argv)
|
||||
* read accessibility.
|
||||
*/
|
||||
char pathbuf[PATH_MAX+1];
|
||||
snprintf(pathbuf,PATH_MAX,"%s",configdir ? configdir:default_configdir);
|
||||
snprintf(pathbuf,PATH_MAX,"%s",get_configdir());
|
||||
if(pathbuf[strlen(pathbuf)-1] != '/')
|
||||
strcat(pathbuf,"/");
|
||||
|
||||
@ -1568,35 +1570,30 @@ int main(int argc, char **argv)
|
||||
char buf[1024];
|
||||
char *argv[8];
|
||||
bool succp;
|
||||
|
||||
/** Use default log directory /var/log/maxscale/ */
|
||||
if(logdir == NULL)
|
||||
|
||||
if(mkdir(get_logdir(),0777) != 0 && errno != EEXIST)
|
||||
{
|
||||
if(mkdir(default_logdir,0777) != 0 && errno != EEXIST)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Error: Cannot create log directory: %s\n",
|
||||
default_logdir);
|
||||
goto return_main;
|
||||
}
|
||||
logdir = strdup(default_logdir);
|
||||
fprintf(stderr,
|
||||
"Error: Cannot create log directory: %s\n",
|
||||
default_logdir);
|
||||
goto return_main;
|
||||
}
|
||||
|
||||
argv[0] = "MaxScale";
|
||||
argv[1] = "-j";
|
||||
argv[2] = logdir;
|
||||
argv[2] = get_logdir();
|
||||
|
||||
if(!syslog_enabled)
|
||||
if(!(*syslog_enabled))
|
||||
{
|
||||
printf("Syslog logging is disabled.\n");
|
||||
}
|
||||
|
||||
if(!maxscalelog_enabled)
|
||||
if(!(*maxscalelog_enabled))
|
||||
{
|
||||
printf("MaxScale logging is disabled.\n");
|
||||
}
|
||||
logmanager_enable_syslog(syslog_enabled);
|
||||
logmanager_enable_maxscalelog(maxscalelog_enabled);
|
||||
logmanager_enable_syslog(*syslog_enabled);
|
||||
logmanager_enable_maxscalelog(*maxscalelog_enabled);
|
||||
|
||||
if (logtofile)
|
||||
{
|
||||
@ -1662,8 +1659,8 @@ int main(int argc, char **argv)
|
||||
"Module directory : %s\n"
|
||||
"Service cache : %s\n\n",
|
||||
cnf_file_path,
|
||||
logdir,
|
||||
datadir,
|
||||
get_logdir(),
|
||||
get_datadir(),
|
||||
get_libdir(),
|
||||
get_cachedir());
|
||||
}
|
||||
@ -1677,12 +1674,12 @@ int main(int argc, char **argv)
|
||||
(skygw_log_write_flush(
|
||||
LOGFILE_MESSAGE,
|
||||
"Log directory: %s/",
|
||||
logdir)));
|
||||
get_logdir())));
|
||||
LOGIF(LM,
|
||||
(skygw_log_write_flush(
|
||||
LOGFILE_MESSAGE,
|
||||
"Data directory: %s",
|
||||
datadir)));
|
||||
get_datadir())));
|
||||
LOGIF(LM,
|
||||
(skygw_log_write_flush(LOGFILE_MESSAGE,
|
||||
"Module directory: %s",
|
||||
@ -1705,7 +1702,7 @@ int main(int argc, char **argv)
|
||||
snprintf(language_arg,
|
||||
11+PATH_MAX+1,
|
||||
"--language=%s",
|
||||
langdir?langdir:default_langdir);
|
||||
get_langdir());
|
||||
server_options[i] = language_arg;
|
||||
}
|
||||
}
|
||||
@ -1735,7 +1732,7 @@ int main(int argc, char **argv)
|
||||
"exactly with that of the errmsg.sys "
|
||||
"file.\n*\n",
|
||||
mysql_error(NULL),
|
||||
home_dir);
|
||||
get_langdir());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1784,7 +1781,7 @@ int main(int argc, char **argv)
|
||||
getpid())));
|
||||
|
||||
/* Write process pid into MaxScale pidfile */
|
||||
write_pid_file(home_dir);
|
||||
write_pid_file();
|
||||
|
||||
/* Init MaxScale poll system */
|
||||
poll_init();
|
||||
@ -1894,8 +1891,6 @@ int main(int argc, char **argv)
|
||||
return_main:
|
||||
if (threads)
|
||||
free(threads);
|
||||
if (home_dir)
|
||||
free(home_dir);
|
||||
if (cnf_file_path)
|
||||
free(cnf_file_path);
|
||||
|
||||
@ -1977,11 +1972,11 @@ static void unlink_pidfile(void)
|
||||
*
|
||||
*/
|
||||
|
||||
static int write_pid_file(char *home_dir) {
|
||||
static int write_pid_file() {
|
||||
|
||||
int fd = -1;
|
||||
|
||||
snprintf(pidfile, PATH_MAX, "%s/maxscale.pid",piddir?piddir:default_piddir);
|
||||
snprintf(pidfile, PATH_MAX, "%s/maxscale.pid",get_piddir());
|
||||
|
||||
fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC, 0777);
|
||||
if (fd == -1) {
|
||||
@ -2043,7 +2038,7 @@ bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr)
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"%s\n",errstr);
|
||||
print_log_n_stderr(true,true,errstr,errstr,0);
|
||||
free(errstr);
|
||||
errstr = NULL;
|
||||
}
|
||||
@ -2062,9 +2057,7 @@ bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr)
|
||||
*/
|
||||
static int cnf_preparser(void* data, const char* section, const char* name, const char* value)
|
||||
{
|
||||
|
||||
char pathbuffer[PATH_MAX];
|
||||
char* errstr;
|
||||
GATEWAY_CONF* cnf = config_get_global_options();
|
||||
char *tmp;
|
||||
/** These are read from the configuration file. These will not override
|
||||
* command line parameters but will override default values. */
|
||||
@ -2072,8 +2065,13 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
|
||||
{
|
||||
if(strcmp(name, "logdir") == 0)
|
||||
{
|
||||
if(logdir == NULL)
|
||||
handle_path_arg(&logdir,(char*)value,NULL,true,true);
|
||||
if(strcmp(get_logdir(),default_logdir) == 0)
|
||||
{
|
||||
if(handle_path_arg(&tmp,(char*)value,NULL,true,true))
|
||||
{
|
||||
set_logdir(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(name, "libdir") == 0)
|
||||
{
|
||||
@ -2085,14 +2083,18 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
|
||||
}
|
||||
else if(strcmp(name, "piddir") == 0)
|
||||
{
|
||||
if(piddir == NULL)
|
||||
handle_path_arg(&piddir,(char*)value,NULL,true,true);
|
||||
if(strcmp(get_piddir(),default_piddir) == 0)
|
||||
{
|
||||
if(handle_path_arg(&tmp,(char*)value,NULL,true,true))
|
||||
{
|
||||
set_piddir(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(name, "datadir") == 0)
|
||||
{
|
||||
if(!datadir_defined)
|
||||
{
|
||||
char* tmp;
|
||||
if(handle_path_arg(&tmp,(char*)value,NULL,true,false))
|
||||
{
|
||||
sprintf(datadir,"%s",tmp);
|
||||
@ -2111,8 +2113,21 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
|
||||
}
|
||||
else if(strcmp(name, "language") == 0)
|
||||
{
|
||||
if(langdir == NULL)
|
||||
handle_path_arg((char**)&langdir,(char*)value,NULL,true,false);
|
||||
if(strcmp(get_langdir(),default_langdir) == 0)
|
||||
{
|
||||
if(handle_path_arg((char**)&tmp,(char*)value,NULL,true,false))
|
||||
{
|
||||
set_langdir(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(name, "syslog") == 0)
|
||||
{
|
||||
cnf->syslog = config_truth_value((char*)value);
|
||||
}
|
||||
else if(strcmp(name, "maxlog") == 0)
|
||||
{
|
||||
cnf->maxlog = config_truth_value((char*)value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,26 @@
|
||||
#include <gwdirs.h>
|
||||
|
||||
void set_configdir(char* str)
|
||||
{
|
||||
free(configdir);
|
||||
configdir = str;
|
||||
}
|
||||
void set_logdir(char* str)
|
||||
{
|
||||
free(logdir);
|
||||
logdir = str;
|
||||
}
|
||||
void set_langdir(char* str)
|
||||
{
|
||||
free(langdir);
|
||||
langdir = str;
|
||||
}
|
||||
void set_piddir(char* str)
|
||||
{
|
||||
free(piddir);
|
||||
piddir = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory with all the modules.
|
||||
* @return The module directory
|
||||
@ -45,4 +66,24 @@ void set_datadir(char* param)
|
||||
if(maxscaledatadir)
|
||||
free(maxscaledatadir);
|
||||
maxscaledatadir = param;
|
||||
}
|
||||
}
|
||||
|
||||
char* get_configdir()
|
||||
{
|
||||
return configdir?configdir:(char*)default_configdir;
|
||||
}
|
||||
|
||||
char* get_piddir()
|
||||
{
|
||||
return piddir?piddir:(char*)default_piddir;
|
||||
}
|
||||
|
||||
char* get_logdir()
|
||||
{
|
||||
return logdir?logdir:(char*)default_logdir;
|
||||
}
|
||||
|
||||
char* get_langdir()
|
||||
{
|
||||
return langdir?langdir:(char*)default_langdir;
|
||||
}
|
||||
|
@ -42,10 +42,19 @@ static char* cachedir = NULL;
|
||||
static char* maxscaledatadir = NULL;
|
||||
static char* langdir = NULL;
|
||||
static char* piddir = NULL;
|
||||
|
||||
void set_libdir(char* param);
|
||||
void set_datadir(char* param);
|
||||
void set_cachedir(char* param);
|
||||
void set_configdir(char* param);
|
||||
void set_logdir(char* param);
|
||||
void set_langdir(char* param);
|
||||
void set_piddir(char* param);
|
||||
char* get_libdir();
|
||||
char* get_datadir();
|
||||
char* get_cachedir();
|
||||
char* get_configdir();
|
||||
char* get_piddir();
|
||||
char* get_logdir();
|
||||
char* get_langdir();
|
||||
#endif
|
||||
|
@ -104,6 +104,8 @@ typedef struct {
|
||||
unsigned long id; /**< MaxScale ID */
|
||||
unsigned int n_nbpoll; /**< Tune number of non-blocking polls */
|
||||
unsigned int pollsleep; /**< Wait time in blocking polls */
|
||||
int syslog; /*< Log to syslog */
|
||||
int maxlog; /*< Log to MaxScale's own logs */
|
||||
} GATEWAY_CONF;
|
||||
|
||||
extern int config_load(char *);
|
||||
@ -143,4 +145,5 @@ bool config_get_valtarget(
|
||||
void config_enable_feedback_task(void);
|
||||
void config_disable_feedback_task(void);
|
||||
unsigned long config_get_gateway_id(void);
|
||||
GATEWAY_CONF* config_get_global_options();
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user