From 1ff0756044800716fa63f78b2d0670d340a73b15 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 5 Mar 2015 12:37:39 +0200 Subject: [PATCH 1/5] Added a command line option for syslog logging. --- log_manager/log_manager.cc | 28 +++++++++++++++++++++++++++- log_manager/log_manager.h | 1 + server/core/gateway.c | 20 ++++++++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 4179f5c49..6713d41d7 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -52,6 +52,8 @@ static int prevval; static simple_mutex_t msg_mutex; #endif static int highprec = 0; +static int do_syslog = 1; + /** * Variable holding the enabled logfiles information. * Used from log users to check enabled logs prior calling @@ -392,7 +394,13 @@ static bool logmanager_init_nomutex( fw = &lm->lm_filewriter; fn->fn_state = UNINIT; fw->fwr_state = UNINIT; - + + if(!do_syslog) + { + free(syslog_id_str); + syslog_id_str = NULL; + } + /** Initialize configuration including log file naming info */ if (!fnames_conf_init(fn, argc, argv)) { @@ -1703,11 +1711,14 @@ static bool fnames_conf_init( case 'l': /** record list of log file ids for syslogged */ + if(do_syslog) + { if (syslog_id_str != NULL) { free (syslog_id_str); } syslog_id_str = optarg; + } break; case 'm': @@ -1720,6 +1731,7 @@ static bool fnames_conf_init( case 's': /** record list of log file ids for later use */ + if(do_syslog) shmem_id_str = optarg; break; case 'h': @@ -3083,7 +3095,21 @@ void skygw_log_sync_all(void) skygw_message_wait(lm->lm_clientmes); } +/** + * Toggle high precision logging + * @param val 0 for disabled, 1 for enabled + */ void skygw_set_highp(int val) { highprec = val; +} + + +/** + * Toggle syslog logging + * @param val 0 for disabled, 1 for enabled + */ +void logmanager_enable_syslog(int val) +{ + do_syslog = val; } \ No newline at end of file diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index 10ccdea1c..64462a25d 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -120,6 +120,7 @@ int skygw_log_enable(logfile_id_t id); int skygw_log_disable(logfile_id_t id); void skygw_log_sync_all(void); void skygw_set_highp(int); +void logmanager_enable_syslog(int); EXTERN_C_BLOCK_END const char* get_trace_prefix_default(void); diff --git a/server/core/gateway.c b/server/core/gateway.c index 0d1c9cbf5..c5507a4bb 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -150,6 +150,7 @@ static struct option long_options[] = { {"config", required_argument, 0, 'f'}, {"nodaemon", no_argument, 0, 'd'}, {"log", required_argument, 0, 'l'}, + {"syslog", required_argument, 0, 's'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, '?'}, {0, 0, 0, 0} @@ -995,6 +996,8 @@ static void usage(void) " (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n" " -l|--log=... log to file or shared memory\n" " -lfile or -lshm - defaults to shared memory\n" + " -s|--syslog= log messages to syslog" + " true or false - defaults to true" " -v|--version print version info and exit\n" " -?|--help show this help\n" , progname); @@ -1057,6 +1060,7 @@ int main(int argc, char **argv) void* log_flush_thr = NULL; int option_index; int logtofile = 0; /* Use shared memory or file */ + int syslog_enabled = 1; /** Log to syslog */ ssize_t log_flush_timeout_ms = 0; sigset_t sigset; sigset_t sigpipe_mask; @@ -1096,7 +1100,7 @@ int main(int argc, char **argv) goto return_main; } } - while ((opt = getopt_long(argc, argv, "dc:f:l:v?", + while ((opt = getopt_long(argc, argv, "dc:f:l:vs:?", long_options, &option_index)) != -1) { bool succp = true; @@ -1201,7 +1205,17 @@ int main(int argc, char **argv) succp = false; } break; - + case 's': + if(strstr(optarg,"=")) + { + strtok(optarg,"= "); + syslog_enabled = config_truth_value(strtok(NULL,"= ")); + } + else + { + syslog_enabled = config_truth_value(optarg); + } + break; case '?': usage(); rc = EXIT_SUCCESS; @@ -1563,6 +1577,8 @@ int main(int argc, char **argv) argv[0] = "MaxScale"; argv[1] = "-j"; argv[2] = buf; + + logmanager_enable_syslog(syslog_enabled); if (logtofile) { From 1299cf6ac96114443d33da502d15e33e4fd0e196 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 5 Mar 2015 12:41:09 +0200 Subject: [PATCH 2/5] Fixed hktask_add not comparing task names if there was only a single task. --- server/core/housekeeper.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/core/housekeeper.c b/server/core/housekeeper.c index 2225e628f..584910b6d 100644 --- a/server/core/housekeeper.c +++ b/server/core/housekeeper.c @@ -116,9 +116,20 @@ HKTASK *task, *ptr; ptr = ptr->next; } if (ptr) + { + if (strcmp(ptr->name, name) == 0) + { + spinlock_release(&tasklock); + free(task->name); + free(task); + return 0; + } ptr->next = task; + } else + { tasks = task; + } spinlock_release(&tasklock); return task->nextdue; From 52fbe26e3c4addfcd626f049e5cd026919410736 Mon Sep 17 00:00:00 2001 From: Timofey Turenko Date: Thu, 5 Mar 2015 18:14:59 +0200 Subject: [PATCH 3/5] redirect all maxscale output to /dev/null/ also during start for testing --- testall.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testall.cmake b/testall.cmake index 2c6868faa..fedbdf273 100644 --- a/testall.cmake +++ b/testall.cmake @@ -1,4 +1,4 @@ -execute_process(COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null") +execute_process(COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null 2> /dev/null > /dev/null") execute_process(COMMAND make test RESULT_VARIABLE RVAL) execute_process(COMMAND killall maxscale) if(NOT RVAL EQUAL 0) From c937568624298fb31ce99f29a5d0676c612f909f Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 5 Mar 2015 20:46:55 +0200 Subject: [PATCH 4/5] Fixed a possible memory leak when session command history limits are used. --- server/modules/include/readwritesplit.h | 1 + server/modules/routing/readwritesplit/readwritesplit.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/server/modules/include/readwritesplit.h b/server/modules/include/readwritesplit.h index c79373533..7bb689bdb 100644 --- a/server/modules/include/readwritesplit.h +++ b/server/modules/include/readwritesplit.h @@ -290,6 +290,7 @@ struct router_client_session { int rses_capabilities; /*< input type, for example */ bool rses_autocommit_enabled; bool rses_transaction_active; + DCB* client_dcb; #if defined(PREP_STMT_CACHING) HASHTABLE* rses_prep_stmt[2]; #endif diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index d3c959c5b..c31b6a795 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -790,6 +790,7 @@ static void* newSession( #endif client_rses->router = router; + client_rses->client_dcb = session->client; /** * If service config has been changed, reload config from service to * router instance first. @@ -4355,8 +4356,10 @@ static bool route_session_write( LOGFILE_TRACE, "Router session exceeded session command history limit. " "Closing router session. <"))); - router_cli_ses->rses_closed = true; + gwbuf_free(querybuf); rses_end_locked_router_action(router_cli_ses); + router_cli_ses->client_dcb->func.hangup(router_cli_ses->client_dcb); + goto return_succp; } From 8c3409cf32875f34994b70287af325e00e979201 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 6 Mar 2015 12:39:42 +0200 Subject: [PATCH 5/5] Fix to MXS-3: https://mariadb.atlassian.net/browse/MXS-3 Added the GNU specific code to skygw_utils.cc. This is a temporary fix and should be revisited at some point. --- utils/skygw_utils.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index 1d38d9194..a8fa45ac5 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -145,12 +145,16 @@ int atomic_add( int *variable, int value) { +#ifdef __GNUC__ + return (int) __sync_fetch_and_add (variable, value); +#else asm volatile( "lock; xaddl %%eax, %2;" :"=a" (value) : "a" (value), "m" (*variable) : "memory" ); return value; +#endif } @@ -2143,4 +2147,4 @@ bool is_valid_posix_path(char* path) } } return true; -} \ No newline at end of file +}