From fb6b3e67022a6d06aa067a1e236fd205d202b172 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 4 Apr 2016 10:48:44 +0300 Subject: [PATCH] MXS-656: Galera nodes with index 0 can be master again The index calculation falsely ignored nodes with node index 0 when errno was non-zero. --- server/modules/monitor/galeramon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/modules/monitor/galeramon.c b/server/modules/monitor/galeramon.c index 6bbf5bab7..70ef5369b 100644 --- a/server/modules/monitor/galeramon.c +++ b/server/modules/monitor/galeramon.c @@ -397,10 +397,12 @@ monitorDatabase(MONITOR *mon, MONITOR_SERVERS *database) while ((row = mysql_fetch_row(result))) { - local_index = strtol(row[1], NULL, 10); - if ((errno == ERANGE && (local_index == LONG_MAX - || local_index == LONG_MIN)) || (errno != 0 && local_index == 0)) + char* endchar; + local_index = strtol(row[1], &endchar, 10); + if (*endchar != '\0' || + (errno == ERANGE && (local_index == LONG_MAX || local_index == LONG_MIN))) { + ss_dassert(false); local_index = -1; } database->server->node_id = local_index;