2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

841. [bug] When sdb modules were not declared threadsafe, their

create and destroy functions were not serialized.
This commit is contained in:
Brian Wellington 2001-05-29 18:34:24 +00:00
parent b96a1d9fa3
commit e2fd12f3a0
2 changed files with 31 additions and 22 deletions

View File

@ -1,3 +1,6 @@
841. [bug] When sdb modules were not declared threadsafe, their
create and destroy functions were not serialized.
840. [bug] The config file parser could print the wrong file
name if an error was detected after an included file
was parsed. [RT #1353]

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sdb.c,v 1.31 2001/05/02 19:25:19 bwelling Exp $ */
/* $Id: sdb.c,v 1.32 2001/05/29 18:34:24 bwelling Exp $ */
#include <config.h>
@ -52,6 +52,7 @@ struct dns_sdbimplementation {
void *driverdata;
unsigned int flags;
isc_mem_t *mctx;
isc_mutex_t driverlock;
dns_dbimplementation_t *dbimp;
};
@ -62,7 +63,6 @@ struct dns_sdb {
dns_sdbimplementation_t *implementation;
void *dbdata;
isc_mutex_t lock;
isc_mutex_t driverlock;
/* Locked */
unsigned int references;
@ -119,14 +119,14 @@ typedef struct sdb_rdatasetiter {
do { \
unsigned int flags = sdb->implementation->flags; \
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
LOCK(&sdb->driverlock); \
LOCK(&sdb->implementation->driverlock); \
} while (0)
#define MAYBE_UNLOCK(sdb) \
do { \
unsigned int flags = sdb->implementation->flags; \
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
UNLOCK(&sdb->driverlock); \
UNLOCK(&sdb->implementation->driverlock); \
} while (0)
static int dummy;
@ -220,16 +220,28 @@ dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
imp->flags = flags;
imp->mctx = NULL;
isc_mem_attach(mctx, &imp->mctx);
result = isc_mutex_init(&imp->driverlock);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed: %s",
isc_result_totext(result));
goto cleanup_mctx;
}
imp->dbimp = NULL;
result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
&imp->dbimp);
if (result != ISC_R_SUCCESS) {
dns_sdb_unregister(&imp);
return (result);
}
if (result != ISC_R_SUCCESS)
goto cleanup_mutex;
*sdbimp = imp;
return (ISC_R_SUCCESS);
cleanup_mutex:
DESTROYLOCK(&imp->driverlock);
cleanup_mctx:
isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
return (result);
}
void
@ -241,6 +253,7 @@ dns_sdb_unregister(dns_sdbimplementation_t **sdbimp) {
imp = *sdbimp;
dns_db_unregister(&imp->dbimp);
DESTROYLOCK(&imp->driverlock);
mctx = imp->mctx;
isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
@ -476,13 +489,15 @@ destroy(dns_sdb_t *sdb) {
mctx = sdb->common.mctx;
if (imp->methods->destroy != NULL)
if (imp->methods->destroy != NULL) {
MAYBE_LOCK(sdb);
imp->methods->destroy(sdb->zone, imp->driverdata,
&sdb->dbdata);
MAYBE_UNLOCK(sdb);
}
isc_mem_free(mctx, sdb->zone);
DESTROYLOCK(&sdb->lock);
DESTROYLOCK(&sdb->driverlock);
sdb->common.magic = 0;
sdb->common.impmagic = 0;
@ -1195,18 +1210,9 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
goto cleanup_mctx;
}
result = isc_mutex_init(&sdb->driverlock);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed: %s",
isc_result_totext(result));
result = ISC_R_UNEXPECTED;
goto cleanup_lock;
}
result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
if (result != ISC_R_SUCCESS)
goto cleanup_driverlock;
goto cleanup_lock;
isc_buffer_init(&b, zonestr, sizeof(zonestr));
result = dns_name_totext(origin, ISC_TRUE, &b);
@ -1222,8 +1228,10 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
sdb->dbdata = NULL;
if (imp->methods->create != NULL) {
MAYBE_LOCK(sdb);
result = imp->methods->create(sdb->zone, argc, argv,
imp->driverdata, &sdb->dbdata);
MAYBE_UNLOCK(sdb);
if (result != ISC_R_SUCCESS)
goto cleanup_zonestr;
}
@ -1241,8 +1249,6 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
isc_mem_free(mctx, sdb->zone);
cleanup_origin:
dns_name_free(&sdb->common.origin, mctx);
cleanup_driverlock:
isc_mutex_destroy(&sdb->driverlock);
cleanup_lock:
isc_mutex_destroy(&sdb->lock);
cleanup_mctx: