From 7af9883b48a5cd7f25894f6facd7ff5c422e30c0 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 16 Mar 2020 16:36:27 +1100 Subject: [PATCH 1/3] remove unused variable --- contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c index a60cc3071f..f13cae29f5 100644 --- a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c +++ b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c @@ -887,9 +887,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, char *tmp = NULL; char *endp; const char *helper_name; -#if SQLITE3_VERSION_ID >= 50000 - my_bool auto_reconnect = 1; -#endif /* if SQLITE3_VERSION_ID >= 50000 */ #if PTHREADS int dbcount; int i, ret; From c6d5d5c88f8fe61d21d9f2911e9649f89772527d Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 16 Mar 2020 16:44:51 +1100 Subject: [PATCH 2/3] Typedef my_bool if missing. ORACLE MySQL 8.0 has dropped the my_bool type, so we need to reinstate it back when compiling with that version or higher. MariaDB is still keeping the my_bool type. The numbering between the two (MariaDB 5.x jumped to MariaDB 10.x) doesn't make the life of the developer easy. --- contrib/dlz/drivers/dlz_mysql_driver.c | 4 ++++ contrib/dlz/modules/mysql/dlz_mysql_dynamic.c | 4 ++++ contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/contrib/dlz/drivers/dlz_mysql_driver.c b/contrib/dlz/drivers/dlz_mysql_driver.c index f000aab8bd..afe906a7fb 100644 --- a/contrib/dlz/drivers/dlz_mysql_driver.c +++ b/contrib/dlz/drivers/dlz_mysql_driver.c @@ -62,6 +62,10 @@ #include #include +#if !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 +typedef bool my_bool; +#endif /* !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 */ + static dns_sdlzimplementation_t *dlz_mysql = NULL; #define dbc_search_limit 30 diff --git a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c index 1a40112b79..de6beac736 100644 --- a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c +++ b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c @@ -59,6 +59,10 @@ #include #include +#if !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 +typedef bool my_bool; +#endif /* !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 */ + #define dbc_search_limit 30 #define ALLNODES 1 #define ALLOWXFR 2 diff --git a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c index 9a2ca2370f..d6f759d414 100644 --- a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c +++ b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c @@ -61,6 +61,10 @@ #include #include +#if !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 +typedef bool my_bool; +#endif /* !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 */ + /* * The SQL queries that will be used for lookups and updates are defined * here. They will be processed into queries by the build_query() @@ -1020,7 +1024,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, */ if (mysql_thread_safe()) { for (n = 0; n < MAX_DBI; n++) { +#if MYSQL_VERSION_ID >= 50000 my_bool opt = 1; +#endif + dlz_mutex_init(&state->db[n].mutex, NULL); dlz_mutex_lock(&state->db[n].mutex); state->db[n].id = n; @@ -1028,8 +1035,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, state->db[n].sock = mysql_init(NULL); mysql_options(state->db[n].sock, MYSQL_READ_DEFAULT_GROUP, modname); +#if MYSQL_VERSION_ID >= 50000 mysql_options(state->db[n].sock, MYSQL_OPT_RECONNECT, &opt); +#endif dlz_mutex_unlock(&state->db[n].mutex); } From 715b7a7cec14e8ee18aef0d0362ae551476fbb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 18 Mar 2020 16:15:43 +0100 Subject: [PATCH 3/3] Use compound literals in mysql_options() call Makes use of compound literals instead of using extra my_bool variable just to hold "true/1" value. --- contrib/dlz/drivers/dlz_mysql_driver.c | 13 +++++-------- contrib/dlz/modules/mysql/dlz_mysql_dynamic.c | 7 +------ contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c | 8 +------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/contrib/dlz/drivers/dlz_mysql_driver.c b/contrib/dlz/drivers/dlz_mysql_driver.c index afe906a7fb..86a7f59e01 100644 --- a/contrib/dlz/drivers/dlz_mysql_driver.c +++ b/contrib/dlz/drivers/dlz_mysql_driver.c @@ -763,9 +763,6 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[], char *endp; int j; unsigned int flags = 0; -#if MYSQL_VERSION_ID >= 50000 - my_bool auto_reconnect = 1; -#endif /* if MYSQL_VERSION_ID >= 50000 */ UNUSED(driverarg); UNUSED(dlzname); @@ -901,21 +898,21 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[], pass = getParameterValue(argv[1], "pass="); socket = getParameterValue(argv[1], "socket="); -#if MYSQL_VERSION_ID >= 50000 /* enable automatic reconnection. */ if (mysql_options((MYSQL *)dbi->dbconn, MYSQL_OPT_RECONNECT, - &auto_reconnect) != 0) + &(my_bool){ 1 }) != 0) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_WARNING, "mysql driver failed to set " - "MYSQL_OPT_RECONNECT option, continuing"); + "MYSQL_OPT_RECONNECT option, " + "continuing"); } -#endif /* if MYSQL_VERSION_ID >= 50000 */ - for (j = 0; dbc == NULL && j < 4; j++) + for (j = 0; dbc == NULL && j < 4; j++) { dbc = mysql_real_connect((MYSQL *)dbi->dbconn, host, user, pass, dbname, port, socket, flags); + } /* let user know if we couldn't connect. */ if (dbc == NULL) { diff --git a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c index de6beac736..33d307975d 100644 --- a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c +++ b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c @@ -816,9 +816,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, char *endp; int j; const char *helper_name; -#if MYSQL_VERSION_ID >= 50000 - my_bool auto_reconnect = 1; -#endif /* if MYSQL_VERSION_ID >= 50000 */ #if PTHREADS int dbcount; int i; @@ -1016,17 +1013,15 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, dbc = NULL; -#if MYSQL_VERSION_ID >= 50000 /* enable automatic reconnection. */ if (mysql_options((MYSQL *)dbi->dbconn, MYSQL_OPT_RECONNECT, - &auto_reconnect) != 0) + &(my_bool){ 1 }) != 0) { mysql->log(ISC_LOG_WARNING, "MySQL module failed to " "set " "MYSQL_OPT_RECONNECT " "option, continuing"); } -#endif /* if MYSQL_VERSION_ID >= 50000 */ for (j = 0; dbc == NULL && j < 4; j++) { dbc = mysql_real_connect( diff --git a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c index d6f759d414..cb0620fde8 100644 --- a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c +++ b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c @@ -1024,10 +1024,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, */ if (mysql_thread_safe()) { for (n = 0; n < MAX_DBI; n++) { -#if MYSQL_VERSION_ID >= 50000 - my_bool opt = 1; -#endif - dlz_mutex_init(&state->db[n].mutex, NULL); dlz_mutex_lock(&state->db[n].mutex); state->db[n].id = n; @@ -1035,10 +1031,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, state->db[n].sock = mysql_init(NULL); mysql_options(state->db[n].sock, MYSQL_READ_DEFAULT_GROUP, modname); -#if MYSQL_VERSION_ID >= 50000 mysql_options(state->db[n].sock, MYSQL_OPT_RECONNECT, - &opt); -#endif + &(my_bool){ 1 }); dlz_mutex_unlock(&state->db[n].mutex); }