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

Improve reporting for pthread_once errors

Replace all uses of RUNTIME_CHECK() in lib/isc/include/isc/once.h with
PTHEADS_RUNTIME_CHECK(), in order to improve error reporting for any
once-related run-time failures (by augmenting error messages with
file/line/caller information and the error string corresponding to
errno).
This commit is contained in:
Ondřej Surý 2022-10-14 16:10:41 +02:00 committed by Ondřej Surý
parent 2ac48846f4
commit cedfc97974
11 changed files with 28 additions and 37 deletions

View File

@ -3726,7 +3726,7 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config,
const cfg_listelt_t *element, *element2;
char socktext[ISC_SOCKADDR_FORMATSIZE];
RUNTIME_CHECK(isc_once_do(&once, init_desc) == ISC_R_SUCCESS);
isc_once_do(&once, init_desc);
ISC_LIST_INIT(new_listeners);
@ -3883,7 +3883,7 @@ named_stats_dump(named_server_t *server, FILE *fp) {
uint64_t sockstat_values[isc_sockstatscounter_max];
uint64_t gluecachestats_values[dns_gluecachestatscounter_max];
RUNTIME_CHECK(isc_once_do(&once, init_desc) == ISC_R_SUCCESS);
isc_once_do(&once, init_desc);
/* Set common fields */
dumparg.type = isc_statsformat_file;

View File

@ -616,8 +616,7 @@ dns_acl_isinsecure(const dns_acl_t *a) {
unsigned int i;
bool insecure;
RUNTIME_CHECK(isc_once_do(&insecure_prefix_once, initialize_action) ==
ISC_R_SUCCESS);
isc_once_do(&insecure_prefix_once, initialize_action);
/*
* Walk radix tree to find out if there are any non-negated,

View File

@ -106,7 +106,7 @@ dns_db_create(isc_mem_t *mctx, const char *db_type, const dns_name_t *origin,
char *argv[], dns_db_t **dbp) {
dns_dbimplementation_t *impinfo;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
isc_once_do(&once, initialize);
/*
* Create a new database using implementation 'db_type'.
@ -841,7 +841,7 @@ dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
REQUIRE(name != NULL);
REQUIRE(dbimp != NULL && *dbimp == NULL);
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
isc_once_do(&once, initialize);
RWLOCK(&implock, isc_rwlocktype_write);
imp = impfind(name);
@ -871,7 +871,7 @@ dns_db_unregister(dns_dbimplementation_t **dbimp) {
REQUIRE(dbimp != NULL && *dbimp != NULL);
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
isc_once_do(&once, initialize);
imp = *dbimp;
*dbimp = NULL;

View File

@ -166,7 +166,7 @@ dns_dlzcreate(isc_mem_t *mctx, const char *dlzname, const char *drivername,
* initialize the dlz_implementations list, this is guaranteed
* to only really happen once.
*/
RUNTIME_CHECK(isc_once_do(&once, dlz_initialize) == ISC_R_SUCCESS);
isc_once_do(&once, dlz_initialize);
/*
* Performs checks to make sure data is as we expect it to be.
@ -296,7 +296,7 @@ dns_dlzregister(const char *drivername, const dns_dlzmethods_t *methods,
* initialize the dlz_implementations list, this is guaranteed
* to only really happen once.
*/
RUNTIME_CHECK(isc_once_do(&once, dlz_initialize) == ISC_R_SUCCESS);
isc_once_do(&once, dlz_initialize);
/* lock the dlz_implementations list so we can modify it. */
RWLOCK(&dlz_implock, isc_rwlocktype_write);
@ -377,7 +377,7 @@ dns_dlzunregister(dns_dlzimplementation_t **dlzimp) {
* initialize the dlz_implementations list, this is guaranteed
* to only really happen once.
*/
RUNTIME_CHECK(isc_once_do(&once, dlz_initialize) == ISC_R_SUCCESS);
isc_once_do(&once, dlz_initialize);
dlz_imp = *dlzimp;

View File

@ -212,7 +212,7 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters,
REQUIRE(DNS_DYNDBCTX_VALID(dctx));
REQUIRE(name != NULL);
RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
isc_once_do(&once, dyndb_initialize);
LOCK(&dyndb_lock);
@ -244,7 +244,7 @@ dns_dyndb_cleanup(bool exiting) {
dyndb_implementation_t *elem;
dyndb_implementation_t *prev;
RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
isc_once_do(&once, dyndb_initialize);
LOCK(&dyndb_lock);
elem = TAIL(dyndb_implementations);

View File

@ -82,7 +82,7 @@ fromtext_in_wks(ARGS_FROMTEXT) {
UNUSED(rdclass);
UNUSED(callbacks);
RUNTIME_CHECK(isc_once_do(&once, init_lock) == ISC_R_SUCCESS);
isc_once_do(&once, init_lock);
/*
* IPv4 dotted quad.

View File

@ -52,9 +52,7 @@ isc_hash_initialize(void) {
const void *
isc_hash_get_initializer(void) {
if (!hash_initialized) {
RUNTIME_CHECK(
isc_once_do(&isc_hash_once, isc_hash_initialize) ==
ISC_R_SUCCESS);
isc_once_do(&isc_hash_once, isc_hash_initialize);
}
return (isc_hash_key);
@ -69,9 +67,7 @@ isc_hash_set_initializer(const void *initializer) {
* isc_hash_set_initializer() is called.
*/
if (!hash_initialized) {
RUNTIME_CHECK(
isc_once_do(&isc_hash_once, isc_hash_initialize) ==
ISC_R_SUCCESS);
isc_once_do(&isc_hash_once, isc_hash_initialize);
}
memmove(isc_hash_key, initializer, sizeof(isc_hash_key));
@ -83,8 +79,7 @@ isc_hash64(const void *data, const size_t length, const bool case_sensitive) {
REQUIRE(length == 0 || data != NULL);
RUNTIME_CHECK(isc_once_do(&isc_hash_once, isc_hash_initialize) ==
ISC_R_SUCCESS);
isc_once_do(&isc_hash_once, isc_hash_initialize);
isc_siphash24(isc_hash_key, data, length, case_sensitive,
(uint8_t *)&hval);
@ -98,8 +93,7 @@ isc_hash32(const void *data, const size_t length, const bool case_sensitive) {
REQUIRE(length == 0 || data != NULL);
RUNTIME_CHECK(isc_once_do(&isc_hash_once, isc_hash_initialize) ==
ISC_R_SUCCESS);
isc_once_do(&isc_hash_once, isc_hash_initialize);
isc_halfsiphash24(isc_hash_key, data, length, case_sensitive,
(uint8_t *)&hval);

View File

@ -23,7 +23,8 @@ typedef pthread_once_t isc_once_t;
#define ISC_ONCE_INIT PTHREAD_ONCE_INIT
/* XXX We could do fancier error handling... */
#define isc_once_do(op, f) \
((pthread_once((op), (f)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_once_do(op, f) \
{ \
int _ret = pthread_once((op), (f)); \
PTHREADS_RUNTIME_CHECK(pthread_once, _ret); \
}

View File

@ -451,7 +451,7 @@ mem_initialize(void) {
void
isc__mem_initialize(void) {
RUNTIME_CHECK(isc_once_do(&init_once, mem_initialize) == ISC_R_SUCCESS);
isc_once_do(&init_once, mem_initialize);
}
static void
@ -463,7 +463,7 @@ mem_shutdown(void) {
void
isc__mem_shutdown(void) {
RUNTIME_CHECK(isc_once_do(&shut_once, mem_shutdown) == ISC_R_SUCCESS);
isc_once_do(&shut_once, mem_shutdown);
}
static void

View File

@ -43,8 +43,7 @@ mutex_initialize(void) {
void
isc__mutex_initialize(void) {
RUNTIME_CHECK(isc_once_do(&init_once, mutex_initialize) ==
ISC_R_SUCCESS);
isc_once_do(&init_once, mutex_initialize);
}
void

View File

@ -198,7 +198,7 @@ initialize_action(void) {
static void
initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
isc_once_do(&once, initialize_action);
}
isc_result_t
@ -281,8 +281,7 @@ close:
static void
initialize_ipv6only(void) {
RUNTIME_CHECK(isc_once_do(&once_ipv6only, try_ipv6only) ==
ISC_R_SUCCESS);
isc_once_do(&once_ipv6only, try_ipv6only);
}
#ifdef __notyet__
@ -329,8 +328,7 @@ close:
static void
initialize_ipv6pktinfo(void) {
RUNTIME_CHECK(isc_once_do(&once_ipv6pktinfo, try_ipv6pktinfo) ==
ISC_R_SUCCESS);
isc_once_do(&once_ipv6pktinfo, try_ipv6pktinfo);
}
#endif /* ifdef __notyet__ */
@ -696,7 +694,7 @@ try_dscp(void) {
static void
initialize_dscp(void) {
RUNTIME_CHECK(isc_once_do(&once_dscp, try_dscp) == ISC_R_SUCCESS);
isc_once_do(&once_dscp, try_dscp);
}
unsigned int