From 23b2a95d5a189a9ce61d142a42bded3f88c5b913 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 8 Jul 2013 19:20:50 +0200 Subject: [PATCH] Update to the user loading to skip servers that can not be connected to --- core/dbusers.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/dbusers.c b/core/dbusers.c index f13f7fc10..0d75662ae 100644 --- a/core/dbusers.c +++ b/core/dbusers.c @@ -52,6 +52,7 @@ load_mysql_users(SERVICE *service) char *service_user = NULL; char *service_passwd = NULL; int total_users = 0; + SERVER *server; serviceGetUser(service, &service_user, &service_passwd); @@ -62,11 +63,23 @@ load_mysql_users(SERVICE *service) return -1; } - if (mysql_real_connect(con, service->databases->name, service_user, service_passwd, NULL, service->databases->port, NULL, 0) == NULL) { + /* + * Attempt to connect to each database in the service in turn until + * we find one that we can connect to or until we run out of databases + * to try + */ + server = service->databases; + while (server && mysql_real_connect(con, server->name, service_user, service_passwd, NULL, + server->port, NULL, 0) == NULL) + { + server = server->nextdb; + } + if (server == NULL) + { fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); return -1; - } + } if (mysql_query(con, "SELECT user, password FROM mysql.user")) { fprintf(stderr, ">>>>> %s\n", mysql_error(con));