From 7d9cb86e80971c80ab90cb7ea831b6a7dd756d71 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 26 Oct 1999 02:29:49 +0000 Subject: [PATCH] Add stop on error flag to dns_zt_apply. --- lib/dns/include/dns/zt.h | 11 +++++++++-- lib/dns/zt.c | 24 +++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/dns/include/dns/zt.h b/lib/dns/include/dns/zt.h index 7ecf7fff8e..700f420c29 100644 --- a/lib/dns/include/dns/zt.h +++ b/lib/dns/include/dns/zt.h @@ -132,15 +132,22 @@ void dns_zt_print(dns_zt_t *zt); * 'zt' to be valid. */ -void -dns_zt_apply(dns_zt_t *zt, void (*action)(dns_zone_t *, void *), void *uap); +dns_result_t +dns_zt_apply(dns_zt_t *zt, isc_boolean_t stop, + dns_result_t (*action)(dns_zone_t *, void *), void *uap); /* * Apply a given 'action' to all zone zones in the table. + * If 'stop' is 'ISC_TRUE' then walking the zone tree will stop if + * 'action' does not return DNS_R_SUCCESS. * * Requires: * 'zt' to be valid. * 'action' to be non NULL. + * + * Returns: + * DNS_R_SUCCESS if action was applied to all nodes. + * any error code from 'action'. */ ISC_LANG_ENDDECLS diff --git a/lib/dns/zt.c b/lib/dns/zt.c index e96aff3e6c..e61addd345 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -41,7 +41,7 @@ struct dns_zt { #define VALID_ZT(zt) ISC_MAGIC_VALID(zt, ZTMAGIC) static void auto_detach(void *, void *); -static void load(dns_zone_t *zone, void *uap); +static dns_result_t load(dns_zone_t *zone, void *uap); isc_result_t dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **ztp) { @@ -219,17 +219,19 @@ dns_zt_print(dns_zt_t *zt) { void dns_zt_load(dns_zt_t *zt) { - dns_zt_apply(zt, load, NULL); + (void)dns_zt_apply(zt, ISC_FALSE, load, NULL); } -static void +static dns_result_t load(dns_zone_t *zone, void *uap) { uap = uap; - (void)dns_zone_load(zone); + return (dns_zone_load(zone)); } -void -dns_zt_apply(dns_zt_t *zt, void (*action)(dns_zone_t *, void *), void *uap) { +dns_result_t +dns_zt_apply(dns_zt_t *zt, isc_boolean_t stop, + dns_result_t (*action)(dns_zone_t *, void *), void *uap) +{ dns_rbtnode_t *node; dns_rbtnodechain_t chain; isc_result_t result; @@ -248,13 +250,21 @@ dns_zt_apply(dns_zt_t *zt, void (*action)(dns_zone_t *, void *), void *uap) { if (result == DNS_R_SUCCESS) { zone = node->data; if (zone != NULL) - (action)(zone, uap); + result = (action)(zone, uap); + if (result != DNS_R_SUCCESS && stop) + goto cleanup; /* don't break */ } result = dns_rbtnodechain_next(&chain, NULL, NULL); } + if (result == DNS_R_NOMORE) + result = DNS_R_SUCCESS; + + cleanup: dns_rbtnodechain_invalidate(&chain); RWUNLOCK(&zt->rwlock, isc_rwlocktype_read); + + return (result); } /***