From 88c48dde5e8ecd41e9cdddfb57f9eff266465a8e Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 7 May 2024 16:48:17 +1000 Subject: [PATCH] Stop processing catalog zone changes when shutting down Abandon catz_addmodzone_cb and catz_delzone_cb processing if the loop is shutting down. --- bin/named/server.c | 21 ++++++++++++++++----- lib/isc/include/isc/loop.h | 10 ++++++++++ lib/isc/loop.c | 8 ++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index cf852657c0..908eb4de5d 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -2656,6 +2656,10 @@ catz_addmodzone_cb(void *arg) { ns_cfgctx_t *cfg = NULL; dns_zone_t *zone = NULL; + if (isc_loop_shuttingdown(isc_loop_get(named_g_loopmgr, isc_tid()))) { + goto cleanup; + } + cfg = (ns_cfgctx_t *)cz->view->new_zone_config; if (cfg == NULL) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -2865,6 +2869,10 @@ catz_delzone_cb(void *arg) { char cname[DNS_NAME_FORMATSIZE]; const char *file = NULL; + if (isc_loop_shuttingdown(isc_loop_get(named_g_loopmgr, isc_tid()))) { + goto cleanup; + } + isc_loopmgr_pause(named_g_loopmgr); dns_name_format(dns_catz_entry_getname(cz->entry), cname, @@ -2877,7 +2885,7 @@ catz_delzone_cb(void *arg) { "catz: catz_delzone_cb: " "zone '%s' not found", cname); - goto cleanup; + goto resume; } if (!dns_zone_getadded(zone)) { @@ -2886,7 +2894,7 @@ catz_delzone_cb(void *arg) { "catz: catz_delzone_cb: " "zone '%s' is not a dynamically added zone", cname); - goto cleanup; + goto resume; } if (dns_zone_get_parentcatz(zone) != cz->origin) { @@ -2895,7 +2903,7 @@ catz_delzone_cb(void *arg) { "catz: catz_delzone_cb: zone " "'%s' exists in multiple catalog zones", cname); - goto cleanup; + goto resume; } /* Stop answering for this zone */ @@ -2904,7 +2912,9 @@ catz_delzone_cb(void *arg) { dns_zone_unload(zone); } - CHECK(dns_view_delzone(cz->view, zone)); + if (dns_view_delzone(cz->view, zone) != ISC_R_SUCCESS) { + goto resume; + } file = dns_zone_getfile(zone); if (file != NULL) { isc_file_remove(file); @@ -2919,8 +2929,9 @@ catz_delzone_cb(void *arg) { "catz: catz_delzone_cb: " "zone '%s' deleted", cname); -cleanup: +resume: isc_loopmgr_resume(named_g_loopmgr); +cleanup: if (zone != NULL) { dns_zone_detach(&zone); } diff --git a/lib/isc/include/isc/loop.h b/lib/isc/include/isc/loop.h index e774532303..f02c0925d6 100644 --- a/lib/isc/include/isc/loop.h +++ b/lib/isc/include/isc/loop.h @@ -215,4 +215,14 @@ isc_loop_now(isc_loop_t *loop); * * \li 'loop' is a valid loop. */ + +bool +isc_loop_shuttingdown(isc_loop_t *loop); +/*%< + * Returns whether the loop is shutting down. + * + * Requires: + * + * \li 'loop' is a valid loop and the loop tid matches the current tid. + */ ISC_LANG_ENDDECLS diff --git a/lib/isc/loop.c b/lib/isc/loop.c index 4aef8f2aad..5cad59e2e6 100644 --- a/lib/isc/loop.c +++ b/lib/isc/loop.c @@ -616,3 +616,11 @@ isc_loop_now(isc_loop_t *loop) { return (t); } + +bool +isc_loop_shuttingdown(isc_loop_t *loop) { + REQUIRE(VALID_LOOP(loop)); + REQUIRE(loop->tid == isc_tid()); + + return (loop->shuttingdown); +}