bind/bind-9.16-pthread-dlz-threaded.patch
Petr Menšík c0565f0da1 Fix ldap and sqlite3 DLZ module failure
Thread removal were incomplete, it has broken some dlz modules
compilation. Ensure threaded variant is always used, remove
remains of single-thread variant.
2022-01-21 21:56:04 +01:00

487 lines
14 KiB
Diff

From 053886b260204e399a33a6b95c6ee95f6161b451 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Fri, 21 Jan 2022 18:52:45 +0100
Subject: [PATCH] Remove remains of #if PTHREADS
Always use only threaded version. Single thread version does not exist
anymore.
---
contrib/dlz/modules/ldap/dlz_ldap_dynamic.c | 59 -------------------
contrib/dlz/modules/mysql/dlz_mysql_dynamic.c | 37 ------------
.../dlz/modules/sqlite3/dlz_sqlite3_dynamic.c | 37 ------------
3 files changed, 133 deletions(-)
diff --git a/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c b/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c
index 7f9231244a..25a7837b67 100644
--- a/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c
+++ b/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c
@@ -69,11 +69,7 @@
* many separate instances.
*/
typedef struct {
-#if PTHREADS
db_list_t *db; /*%< handle to a list of DB */
-#else /* if PTHREADS */
- dbinstance_t *db; /*%< handle to db */
-#endif /* if PTHREADS */
int method; /*%< security authentication
* method */
char *user; /*%< who is authenticating */
@@ -227,7 +223,6 @@ cleanup:
return (result);
}
-#if PTHREADS
/*%
* Properly cleans up a list of database instances.
* This function is only used when the driver is compiled for
@@ -298,7 +293,6 @@ dlz_ldap_find_avail_conn(ldap_instance_t *ldap) {
count);
return (NULL);
}
-#endif /* PTHREADS */
static isc_result_t
dlz_ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
@@ -542,16 +536,8 @@ dlz_ldap_get_results(const char *zone, const char *record, const char *client,
int entries;
/* get db instance / connection */
-#if PTHREADS
/* find an available DBI from the list */
dbi = dlz_ldap_find_avail_conn(db);
-#else /* PTHREADS */
- /*
- * only 1 DBI - no need to lock instance lock either
- * only 1 thread in the whole process, no possible contention.
- */
- dbi = (dbinstance_t *)(db->db);
-#endif /* PTHREADS */
/* if DBI is null, can't do anything else */
if (dbi == NULL) {
@@ -907,11 +893,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
const char *helper_name;
int protocol;
int method;
-#if PTHREADS
int dbcount;
char *endp;
int i;
-#endif /* PTHREADS */
va_list ap;
UNUSED(dlzname);
@@ -930,13 +914,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
}
va_end(ap);
-#if PTHREADS
/* if debugging, let user know we are multithreaded. */
ldap->log(ISC_LOG_DEBUG(1), "LDAP driver running multithreaded");
-#else /* PTHREADS */
- /* if debugging, let user know we are single threaded. */
- ldap->log(ISC_LOG_DEBUG(1), "LDAP driver running single threaded");
-#endif /* PTHREADS */
if (argc < 9) {
ldap->log(ISC_LOG_ERROR, "LDAP driver requires at least "
@@ -979,7 +958,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
}
/* multithreaded build can have multiple DB connections */
-#if PTHREADS
/* check how many db connections we should create */
dbcount = strtol(argv[1], &endp, 10);
if (*endp != '\0' || dbcount < 0) {
@@ -988,7 +966,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
"must be positive.");
goto cleanup;
}
-#endif /* if PTHREADS */
/* check that LDAP URL parameters make sense */
switch (argc) {
@@ -1045,7 +1022,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* allocate memory for database connection list */
ldap->db = calloc(1, sizeof(db_list_t));
if (ldap->db == NULL) {
@@ -1061,7 +1037,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
* append each new DBI to the end of the list
*/
for (i = 0; i < dbcount; i++) {
-#endif /* PTHREADS */
/* how many queries were passed in from config file? */
switch (argc) {
case 9:
@@ -1099,17 +1074,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* when multithreaded, build a list of DBI's */
DLZ_LINK_INIT(dbi, link);
DLZ_LIST_APPEND(*(ldap->db), dbi, link);
-#else /* if PTHREADS */
- /*
- * when single threaded, hold onto the one connection
- * instance.
- */
- ldap->db = dbi;
-#endif /* if PTHREADS */
/* attempt to connect */
result = dlz_ldap_connect(ldap, dbi);
@@ -1126,16 +1093,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
* allocate memory
*/
case ISC_R_NOMEMORY:
-#if PTHREADS
ldap->log(ISC_LOG_ERROR,
"LDAP driver could not allocate memory "
"for connection number %u",
i + 1);
-#else /* if PTHREADS */
- ldap->log(ISC_LOG_ERROR, "LDAP driver could not allocate "
- "memory "
- "for connection");
-#endif /* if PTHREADS */
goto cleanup;
/*
* no perm means ldap_set_option could not set
@@ -1148,15 +1109,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
/* failure means couldn't connect to ldap server */
case ISC_R_FAILURE:
-#if PTHREADS
ldap->log(ISC_LOG_ERROR,
"LDAP driver could not bind "
"connection number %u to server.",
i + 1);
-#else /* if PTHREADS */
- ldap->log(ISC_LOG_ERROR, "LDAP driver could not "
- "bind connection to server.");
-#endif /* if PTHREADS */
goto cleanup;
/*
* default should never happen. If it does,
@@ -1169,11 +1125,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* set DBI = null for next loop through. */
dbi = NULL;
}
-#endif /* PTHREADS */
/* set dbdata to the ldap_instance we created. */
*dbdata = ldap;
@@ -1190,19 +1144,10 @@ void
dlz_destroy(void *dbdata) {
if (dbdata != NULL) {
ldap_instance_t *db = (ldap_instance_t *)dbdata;
-#if PTHREADS
/* cleanup the list of DBI's */
if (db->db != NULL) {
dlz_ldap_destroy_dblist((db_list_t *)(db->db));
}
-#else /* PTHREADS */
- if (db->db->dbconn != NULL) {
- ldap_unbind_s((LDAP *)(db->db->dbconn));
- }
-
- /* destroy single DB instance */
- destroy_dbinstance(db->db);
-#endif /* PTHREADS */
if (db->hosts != NULL) {
free(db->hosts);
@@ -1223,11 +1168,7 @@ dlz_destroy(void *dbdata) {
int
dlz_version(unsigned int *flags) {
*flags |= DNS_SDLZFLAG_RELATIVERDATA;
-#if PTHREADS
*flags |= DNS_SDLZFLAG_THREADSAFE;
-#else /* if PTHREADS */
- *flags &= ~DNS_SDLZFLAG_THREADSAFE;
-#endif /* if PTHREADS */
return (DLZ_DLOPEN_VERSION);
}
diff --git a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
index 81b46aa79e..0b8be40112 100644
--- a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
+++ b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
@@ -64,12 +64,8 @@ typedef bool my_bool;
* many separate instances.
*/
typedef struct {
-#if PTHREADS
db_list_t *db; /*%< handle to a list of DB */
int dbcount;
-#else /* if PTHREADS */
- dbinstance_t *db; /*%< handle to DB */
-#endif /* if PTHREADS */
unsigned int flags;
char *dbname;
@@ -112,7 +108,6 @@ mysql_destroy(dbinstance_t *db) {
destroy_dbinstance(db);
}
-#if PTHREADS
/*%
* Properly cleans up a list of database instances.
* This function is only used when the module is compiled for
@@ -175,7 +170,6 @@ mysql_find_avail_conn(mysql_instance_t *mysql) {
count);
return (NULL);
}
-#endif /* PTHREADS */
/*%
* Allocates memory for a new string, and then constructs the new
@@ -224,16 +218,8 @@ mysql_get_resultset(const char *zone, const char *record, const char *client,
unsigned int j = 0;
int qres = 0;
-#if PTHREADS
/* find an available DBI from the list */
dbi = mysql_find_avail_conn(db);
-#else /* PTHREADS */
- /*
- * only 1 DBI - no need to lock instance lock either
- * only 1 thread in the whole process, no possible contention.
- */
- dbi = (dbinstance_t *)(db->db);
-#endif /* PTHREADS */
if (dbi == NULL) {
return (ISC_R_FAILURE);
@@ -801,10 +787,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
char *endp;
int j;
const char *helper_name;
-#if PTHREADS
int dbcount;
int i;
-#endif /* PTHREADS */
va_list ap;
UNUSED(dlzname);
@@ -823,13 +807,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
}
va_end(ap);
-#if PTHREADS
/* if debugging, let user know we are multithreaded. */
mysql->log(ISC_LOG_DEBUG(1), "MySQL module running multithreaded");
-#else /* PTHREADS */
- /* if debugging, let user know we are single threaded. */
- mysql->log(ISC_LOG_DEBUG(1), "MySQL module running single threaded");
-#endif /* PTHREADS */
/* verify we have at least 4 arg's passed to the module */
if (argc < 4) {
@@ -901,7 +880,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
free(tmp);
}
-#if PTHREADS
/* multithreaded build can have multiple DB connections */
tmp = get_parameter_value(argv[1], "threads=");
if (tmp == NULL) {
@@ -934,7 +912,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
* append each new DBI to the end of the list
*/
for (i = 0; i < dbcount; i++) {
-#endif /* PTHREADS */
switch (argc) {
case 4:
result = build_dbinstance(NULL, NULL, NULL, argv[2],
@@ -973,17 +950,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* when multithreaded, build a list of DBI's */
DLZ_LINK_INIT(dbi, link);
DLZ_LIST_APPEND(*(mysql->db), dbi, link);
-#else /* if PTHREADS */
- /*
- * when single threaded, hold onto the one connection
- * instance.
- */
- mysql->db = dbi;
-#endif /* if PTHREADS */
/* create and set db connection */
dbi->dbconn = mysql_init(NULL);
@@ -1029,11 +998,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* set DBI = null for next loop through. */
dbi = NULL;
}
-#endif /* PTHREADS */
*dbdata = mysql;
@@ -1051,14 +1018,10 @@ cleanup:
void
dlz_destroy(void *dbdata) {
mysql_instance_t *db = (mysql_instance_t *)dbdata;
-#if PTHREADS
/* cleanup the list of DBI's */
if (db->db != NULL) {
mysql_destroy_dblist((db_list_t *)(db->db));
}
-#else /* PTHREADS */
- mysql_destroy(db);
-#endif /* PTHREADS */
if (db->dbname != NULL) {
free(db->dbname);
diff --git a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
index c2a8958d6a..459ae7f68d 100644
--- a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
+++ b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
@@ -59,12 +59,8 @@
* many separate instances.
*/
typedef struct {
-#if PTHREADS
db_list_t *db; /*%< handle to a list of DB */
int dbcount;
-#else /* if PTHREADS */
- dbinstance_t *db; /*%< handle to DB */
-#endif /* if PTHREADS */
char *dbname;
@@ -113,7 +109,6 @@ sqlite3_destroy(dbinstance_t *db) {
destroy_dbinstance(db);
}
-#if PTHREADS
/*%
* Properly cleans up a list of database instances.
* This function is only used when the module is compiled for
@@ -176,7 +171,6 @@ sqlite3_find_avail(sqlite3_instance_t *sqlite3) {
count);
return (NULL);
}
-#endif /* PTHREADS */
/*%
* Allocates memory for a new string, and then constructs the new
@@ -252,16 +246,8 @@ sqlite3_get_resultset(const char *zone, const char *record, const char *client,
goto cleanup;
}
-#if PTHREADS
/* find an available DBI from the list */
dbi = sqlite3_find_avail(db);
-#else /* PTHREADS */
- /*
- * only 1 DBI - no need to lock instance lock either
- * only 1 thread in the whole process, no possible contention.
- */
- dbi = (dbinstance_t *)(db->db);
-#endif /* PTHREADS */
if (dbi == NULL) {
return (ISC_R_FAILURE);
@@ -872,10 +858,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
char *tmp = NULL;
char *endp;
const char *helper_name;
-#if PTHREADS
int dbcount;
int i, ret;
-#endif /* PTHREADS */
va_list ap;
UNUSED(dlzname);
@@ -894,13 +878,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
}
va_end(ap);
-#if PTHREADS
/* if debugging, let user know we are multithreaded. */
s3->log(ISC_LOG_DEBUG(1), "SQLite3 module: running multithreaded");
-#else /* PTHREADS */
- /* if debugging, let user know we are single threaded. */
- s3->log(ISC_LOG_DEBUG(1), "SQLite3 module: running single threaded");
-#endif /* PTHREADS */
/* verify we have at least 4 arg's passed to the module */
if (argc < 4) {
@@ -925,7 +904,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* multithreaded build can have multiple DB connections */
tmp = get_parameter_value(argv[1], "threads=");
if (tmp == NULL) {
@@ -958,7 +936,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
* append each new DBI to the end of the list
*/
for (i = 0; i < dbcount; i++) {
-#endif /* PTHREADS */
switch (argc) {
case 4:
result = build_dbinstance(NULL, NULL, NULL, argv[2],
@@ -1014,25 +991,15 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
goto cleanup;
}
-#if PTHREADS
/* when multithreaded, build a list of DBI's */
DLZ_LINK_INIT(dbi, link);
DLZ_LIST_APPEND(*(s3->db), dbi, link);
-#else /* if PTHREADS */
- /*
- * when single threaded, hold onto the one connection
- * instance.
- */
- s3->db = dbi;
-#endif /* if PTHREADS */
dbi->dbconn = dbc;
dbc = NULL;
-#if PTHREADS
/* set DBI = null for next loop through. */
dbi = NULL;
}
-#endif /* PTHREADS */
*dbdata = s3;
return (ISC_R_SUCCESS);
@@ -1049,14 +1016,10 @@ cleanup:
void
dlz_destroy(void *dbdata) {
sqlite3_instance_t *db = (sqlite3_instance_t *)dbdata;
-#if PTHREADS
/* cleanup the list of DBI's */
if (db->db != NULL) {
sqlite3_destroy_dblist((db_list_t *)(db->db));
}
-#else /* PTHREADS */
- sqlite3_destroy(db);
-#endif /* PTHREADS */
if (db->dbname != NULL) {
free(db->dbname);
--
2.31.1