diff --git a/CMakeLists.txt b/CMakeLists.txt index 89066dcf6..a038f49c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,16 +160,16 @@ execute_process(COMMAND perl ${CMAKE_SOURCE_DIR}/Documentation/format.pl ${CMAKE_SOURCE_DIR}/Documentation/Changelog.md ${CMAKE_BINARY_DIR}/Changelog.txt) execute_process(COMMAND perl ${CMAKE_SOURCE_DIR}/Documentation/format.pl -${CMAKE_SOURCE_DIR}/Documentation/Release-Notes/MaxScale-1.1-Release-Notes.md +${CMAKE_SOURCE_DIR}/Documentation/Release-Notes/MaxScale-1.2.0-Release-Notes.md ${CMAKE_BINARY_DIR}/ReleaseNotes.txt) execute_process(COMMAND perl ${CMAKE_SOURCE_DIR}/Documentation/format.pl -${CMAKE_SOURCE_DIR}/Documentation/Upgrading-To-MaxScale-1.1.0.md - ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt) +${CMAKE_SOURCE_DIR}/Documentation/Upgrading/Upgrading-To-MaxScale-1.2.0.md + ${CMAKE_BINARY_DIR}/UpgradingToMaxScale120.txt) install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHAREDIR}) -install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale120.txt DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES server/maxscale_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) if(WITH_MAXSCALE_CNF) install(FILES server/maxscale_template.cnf DESTINATION ${MAXSCALE_CONFDIR} RENAME maxscale.cnf) diff --git a/server/core/config.c b/server/core/config.c index b41309943..dee089a49 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -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; +} diff --git a/server/core/gateway.c b/server/core/gateway.c index 4d6c30c62..b9c85434d 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -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,31 @@ int main(int argc, char **argv) if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) { - logdir = tmp_path; + set_logdir(tmp_path); + } + else + { + succp = false; } - break; case 'N': if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) { - langdir = tmp_path; + set_langdir(tmp_path); + } + else + { + succp = false; } break; case 'P': if(handle_path_arg(&tmp_path,optarg,NULL,true,true)) { - piddir = tmp_path; + set_piddir(tmp_path); + } + else + { + succp = false; } break; case 'D': @@ -1184,7 +1197,11 @@ 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); + } + else + { + succp = false; } break; case 'B': @@ -1192,12 +1209,20 @@ int main(int argc, char **argv) { set_libdir(tmp_path); } + else + { + succp = false; + } break; case 'A': if(handle_path_arg(&tmp_path,optarg,NULL,true,true)) { set_cachedir(tmp_path); } + else + { + succp = false; + } break; case 'S': { @@ -1206,11 +1231,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 +1246,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 +1564,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 +1593,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 +1682,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 +1697,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 +1725,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 +1755,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 +1804,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 +1914,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 +1995,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 +2061,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 +2080,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 +2088,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 +2106,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 +2136,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); } } diff --git a/server/core/gwdirs.c b/server/core/gwdirs.c index 95d3d6faf..1b8108b28 100644 --- a/server/core/gwdirs.c +++ b/server/core/gwdirs.c @@ -1,5 +1,26 @@ #include +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; -} \ No newline at end of file +} + +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; +} diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index 0ce6e080a..cc46b12fd 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -27,7 +27,7 @@ static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_configdir = "/etc"; static const char* default_piddir = "@MAXSCALE_VARDIR@/run/maxscale"; /*< This should be changed to just /run eventually, - * the /var/run folder is an old standard and the newe FSH 3.0 + * the /var/run folder is an old standard and the newer FSH 3.0 * uses /run for PID files.*/ static const char* default_logdir = "@MAXSCALE_VARDIR@/log/maxscale"; static const char* default_datadir = "@MAXSCALE_VARDIR@/lib/maxscale"; @@ -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 diff --git a/server/include/maxconfig.h b/server/include/maxconfig.h index 9912182c0..a3c93f2f1 100644 --- a/server/include/maxconfig.h +++ b/server/include/maxconfig.h @@ -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