From cedfc9797423f88db17c50ee38927d1901861cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 14 Oct 2022 16:10:41 +0200 Subject: [PATCH] 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). --- bin/named/statschannel.c | 4 ++-- lib/dns/acl.c | 3 +-- lib/dns/db.c | 6 +++--- lib/dns/dlz.c | 6 +++--- lib/dns/dyndb.c | 4 ++-- lib/dns/rdata/in_1/wks_11.c | 2 +- lib/isc/hash.c | 14 ++++---------- lib/isc/include/isc/once.h | 9 +++++---- lib/isc/mem.c | 4 ++-- lib/isc/mutex.c | 3 +-- lib/isc/net.c | 10 ++++------ 11 files changed, 28 insertions(+), 37 deletions(-) diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index c2ef1cff6e..801878e2bc 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -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; diff --git a/lib/dns/acl.c b/lib/dns/acl.c index c43713f10e..09f39bf28f 100644 --- a/lib/dns/acl.c +++ b/lib/dns/acl.c @@ -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, diff --git a/lib/dns/db.c b/lib/dns/db.c index 9d894ccd7a..c0b71599c2 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -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; diff --git a/lib/dns/dlz.c b/lib/dns/dlz.c index f99f6fcd6c..7515943912 100644 --- a/lib/dns/dlz.c +++ b/lib/dns/dlz.c @@ -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; diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index 72769bc7cd..63d0a4a95b 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -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); diff --git a/lib/dns/rdata/in_1/wks_11.c b/lib/dns/rdata/in_1/wks_11.c index 3c31b4a02d..88a46e2c87 100644 --- a/lib/dns/rdata/in_1/wks_11.c +++ b/lib/dns/rdata/in_1/wks_11.c @@ -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. diff --git a/lib/isc/hash.c b/lib/isc/hash.c index f2708e6bb5..1a28a216a7 100644 --- a/lib/isc/hash.c +++ b/lib/isc/hash.c @@ -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); diff --git a/lib/isc/include/isc/once.h b/lib/isc/include/isc/once.h index 7d341ca63c..4771b5cb5e 100644 --- a/lib/isc/include/isc/once.h +++ b/lib/isc/include/isc/once.h @@ -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); \ + } diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 50da4c2832..39ce4cec17 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -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 diff --git a/lib/isc/mutex.c b/lib/isc/mutex.c index 9c067cbd9e..c0bc2dc2e0 100644 --- a/lib/isc/mutex.c +++ b/lib/isc/mutex.c @@ -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 diff --git a/lib/isc/net.c b/lib/isc/net.c index efb9ff1ccf..be75fb480b 100644 --- a/lib/isc/net.c +++ b/lib/isc/net.c @@ -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