From 7069ee25497fbde1f5ac1b28607ec09f132259e1 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 12 Sep 2014 12:16:39 +0100 Subject: [PATCH 1/4] Added checks to determine if servers in the servers= lists for services and monitors exist in the configuration file. --- server/core/config.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/server/core/config.c b/server/core/config.c index ae477b07c..09ce1ee11 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -616,17 +616,29 @@ int error_count = 0; while (s) { CONFIG_CONTEXT *obj1 = context; + int found = 0; while (obj1) { if (strcmp(trim(s), obj1->object) == 0 && obj->element && obj1->element) { + found = 1; serviceAddBackend( obj->element, obj1->element); } obj1 = obj1->next; } + if (!found) + { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: Unable to find " + "server '%s' that is " + "configured as part of " + "service '%s'.", + s, obj->object))); + } s = strtok(NULL, ","); } } @@ -634,7 +646,7 @@ int error_count = 0; { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, - "Error : The service '%s' is missing a " + "Warning: The service '%s' is missing a " "definition of the servers that provide " "the service.", obj->object))); @@ -787,17 +799,29 @@ int error_count = 0; while (s) { CONFIG_CONTEXT *obj1 = context; + int found = 0; while (obj1) { if (strcmp(s, obj1->object) == 0 && obj->element && obj1->element) { + found = 1; monitorAddServer( obj->element, obj1->element); } obj1 = obj1->next; } + if (!found) + LOGIF(LE, + (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: Unable to find " + "server '%s' that is " + "configured in the " + "monitor '%s'.", + s, obj->object))); + s = strtok(NULL, ","); } } @@ -1391,11 +1415,13 @@ SERVER *server; while (s) { CONFIG_CONTEXT *obj1 = context; + int found = 0; while (obj1) { if (strcmp(s, obj1->object) == 0 && obj->element && obj1->element) { + found = 1; if (!serviceHasBackend(obj->element, obj1->element)) { serviceAddBackend( @@ -1405,6 +1431,16 @@ SERVER *server; } obj1 = obj1->next; } + if (!found) + { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: Unable to find " + "server '%s' that is " + "configured as part of " + "service '%s'.", + s, obj->object))); + } s = strtok(NULL, ","); } } From ffc7e7aa103dc598fd5e4d44800557b6e7fcd8b1 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Fri, 12 Sep 2014 15:36:22 +0200 Subject: [PATCH 2/4] Fix for server_string memory leak Fix for server_string memory leak --- server/modules/monitor/galera_mon.c | 4 +++- server/modules/monitor/mysql_mon.c | 4 +++- server/modules/monitor/ndbcluster_mon.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index de71c4dfb..211407f86 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -359,7 +359,9 @@ char *server_string; /* get server version string */ server_string = (char *)mysql_get_server_info(database->con); if (server_string) { - database->server->server_string = strdup(server_string); + database->server->server_string = realloc(database->server->server_string, strlen(server_string)+1); + if (database->server->server_string) + strcpy(database->server->server_string, server_string); } /* Check if the the Galera FSM shows this node is joined to the cluster */ diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index fb86fc0fc..976aa315d 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -439,7 +439,9 @@ char *server_string; /* get server version string */ server_string = (char *)mysql_get_server_info(database->con); if (server_string) { - database->server->server_string = strdup(server_string); + database->server->server_string = realloc(database->server->server_string, strlen(server_string)+1); + if (database->server->server_string) + strcpy(database->server->server_string, server_string); } /* get server_id form current node */ diff --git a/server/modules/monitor/ndbcluster_mon.c b/server/modules/monitor/ndbcluster_mon.c index f83ee7ae7..840e30691 100644 --- a/server/modules/monitor/ndbcluster_mon.c +++ b/server/modules/monitor/ndbcluster_mon.c @@ -353,7 +353,9 @@ char *server_string; /* get server version string */ server_string = (char *)mysql_get_server_info(database->con); if (server_string) { - database->server->server_string = strdup(server_string); + database->server->server_string = realloc(database->server->server_string, strlen(server_string)+1); + if (database->server->server_string) + strcpy(database->server->server_string, server_string); } /* Check if the the SQL node is able to contact one or more data nodes */ From 3dcecc2d772725a2af4f4e51db965cb66691b901 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 12 Sep 2014 15:29:48 +0100 Subject: [PATCH 3/4] Fix for bug 539 --- client/maxadmin.c | 23 ++++++++++++++++++++++- server/core/session.c | 13 +++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/client/maxadmin.c b/client/maxadmin.c index 5710cc35a..683916e9f 100644 --- a/client/maxadmin.c +++ b/client/maxadmin.c @@ -58,6 +58,7 @@ static int authMaxScale(int so, char *user, char *password); static int sendCommand(int so, char *cmd); static void DoSource(int so, char *cmd); static void DoUsage(); +static int isquit(char *buf); #ifdef HISTORY static char * @@ -289,7 +290,7 @@ int argno = 0; history(hist, &ev, H_ENTER, buf); #endif - if (!strcasecmp(buf, "quit")) + if (isquit(buf)) { break; } @@ -552,3 +553,23 @@ DoUsage() printf("Any remaining arguments are treated as MaxScale commands or a file\n"); printf("containing commands to execute.\n"); } + +/** + * Check command to see if it is a quit command + * + * @param buf The command buffer + * @return Non-zero if the command should cause maxadmin to quit + */ +static int +isquit(char *buf) +{ +char *ptr = buf; + + if (!buf) + return 0; + while (*ptr && isspace(*ptr)) + ptr++; + if (strncasecmp(ptr, "quit", 4) == 0 || strncasecmp(ptr, "exit", 4) == 0) + return 1; + return 0; +} diff --git a/server/core/session.c b/server/core/session.c index a67926b48..eb9d42a2b 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -693,8 +693,17 @@ int i; service->name))); return 0; } - session->tail = *tail; - free(tail); + + /* + * filterUpstream may simply return the 3 parameter if + * the filter has no upstream entry point. So no need + * to copy the contents or free tail in this case. + */ + if (tail != &session->tail) + { + session->tail = *tail; + free(tail); + } } return 1; From 46c4808c79f08aaeb4934eee0dd53141491c7aac Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 12 Sep 2014 15:45:10 +0100 Subject: [PATCH 4/4] Bug 494 - remove error log report for missing servers for debugcli and cli router --- server/core/config.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/server/core/config.c b/server/core/config.c index 09ce1ee11..b67376751 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -35,6 +35,8 @@ * 23/05/14 Massimiliano Pinto Added automatic set of maxscale-id: first listening ipv4_raw + port + pid * 28/05/14 Massimiliano Pinto Added detect_replication_lag parameter * 28/08/14 Massimiliano Pinto Added detect_stale_master parameter + * 12/09/14 Mark Riddoch Addition of checks on servers list and + * internal router suppression of messages * * @endverbatim */ @@ -62,6 +64,7 @@ static int handle_global_item(const char *, const char *); static void global_defaults(); static void check_config_objects(CONFIG_CONTEXT *context); static int config_truth_value(char *str); +static int internalService(char *router); static char *config_file = NULL; static GATEWAY_CONF gateway; @@ -605,11 +608,13 @@ int error_count = 0; { char *servers; char *roptions; + char *router; char *filters = config_get_value(obj->parameters, "filters"); servers = config_get_value(obj->parameters, "servers"); roptions = config_get_value(obj->parameters, "router_options"); + router = config_get_value(obj->parameters, "router"); if (servers && obj->element) { char *s = strtok(servers, ","); @@ -642,7 +647,7 @@ int error_count = 0; s = strtok(NULL, ","); } } - else if (servers == NULL) + else if (servers == NULL && internalService(router) == 0) { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, @@ -1703,3 +1708,29 @@ config_truth_value(char *str) return atoi(str); } +static char *InternalRouters[] = { + "debugcli", + "cli", + NULL +}; + +/** + * Determine if the router is one of the special internal services that + * MaxScale offers. + * + * @param router The router name + * @return Non-zero if the router is in the InternalRouters table + */ +static int +internalService(char *router) +{ +int i; + + if (router) + { + for (i = 0; InternalRouters[i]; i++) + if (strcmp(router, InternalRouters[i]) == 0) + return 1; + } + return 0; +}