From e2124ec01fdcd08b39f54ab050a24d4413f95a9f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 20 Aug 2019 15:25:10 +0300 Subject: [PATCH] MXS-2644 Log reason if mysql_real_connect fails If mysql_real_connect fails inside any of the open_conn_db... utility functions that will now be logged. --- maxscale-system-test/mariadb_func.cpp | 44 ++++++++++++++++---------- maxscale-system-test/mariadb_nodes.cpp | 5 ++- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/maxscale-system-test/mariadb_func.cpp b/maxscale-system-test/mariadb_func.cpp index b814347d2..8eb7c303a 100644 --- a/maxscale-system-test/mariadb_func.cpp +++ b/maxscale-system-test/mariadb_func.cpp @@ -53,14 +53,20 @@ MYSQL* open_conn_db_flags(int port, // MXS-2568: This fixes mxs1828_double_local_infile mysql_optionsv(conn, MYSQL_OPT_LOCAL_INFILE, (void*)"1"); - mysql_real_connect(conn, - ip.c_str(), - user.c_str(), - password.c_str(), - db.c_str(), - port, - NULL, - flag); + if (!mysql_real_connect(conn, + ip.c_str(), + user.c_str(), + password.c_str(), + db.c_str(), + port, + NULL, + flag)) + { + fprintf(stdout, + "Could not connect to %s:%d with user '%s' and password '%s', " + "and default database '%s': %s\n", + ip.c_str(), port, user.c_str(), password.c_str(), db.c_str(), mysql_error(conn)); + } return conn; } @@ -92,14 +98,20 @@ MYSQL* open_conn_db_timeout(int port, set_ssl(conn); } - mysql_real_connect(conn, - ip.c_str(), - user.c_str(), - password.c_str(), - db.c_str(), - port, - NULL, - CLIENT_MULTI_STATEMENTS); + if (!mysql_real_connect(conn, + ip.c_str(), + user.c_str(), + password.c_str(), + db.c_str(), + port, + NULL, + CLIENT_MULTI_STATEMENTS)) + { + fprintf(stdout, + "Could not connect to %s:%d with user '%s' and password '%s', " + "and default database '%s': %s\n", + ip.c_str(), port, user.c_str(), password.c_str(), db.c_str(), mysql_error(conn)); + } return conn; } diff --git a/maxscale-system-test/mariadb_nodes.cpp b/maxscale-system-test/mariadb_nodes.cpp index 50dcaa997..55d4d7f01 100644 --- a/maxscale-system-test/mariadb_nodes.cpp +++ b/maxscale-system-test/mariadb_nodes.cpp @@ -84,7 +84,7 @@ int Mariadb_nodes::connect(int i, const std::string& db) nodes[i] = open_conn_db_timeout(port[i], IP[i], db.c_str(), user_name, password, 50, ssl); } - if ((nodes[i] != NULL) && (mysql_errno(nodes[i]) != 0)) + if ((nodes[i] == NULL) || (mysql_errno(nodes[i]) != 0)) { return 1; } @@ -1015,8 +1015,7 @@ bool do_flush_hosts(MYSQL* conn) int Mariadb_nodes::flush_hosts() { - - if (this->nodes[0] == NULL && this->connect()) + if (this->nodes[0] == NULL && (this->connect() != 0)) { return 1; }