From cd8a081a4f67e223e63506a474620c0e095dc5f1 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Wed, 15 Sep 2021 01:40:31 -0700 Subject: [PATCH] Remove libdns init/shutdown functions as libdns is no longer exported, it's not necessary to have init and shutdown functions. the only purpose they served was to create a private mctx and run dst_lib_init(), which can be called directly instead. --- bin/delv/delv.c | 15 ++-- bin/named/server.c | 1 - bin/tests/system/dyndb/driver/driver.c | 1 - bin/tests/system/resolve.c | 15 ++-- lib/dns/Makefile.am | 2 - lib/dns/cache.c | 1 - lib/dns/db.c | 2 + lib/dns/include/dns/db.h | 5 ++ lib/dns/include/dns/lib.h | 43 ---------- lib/dns/lib.c | 104 ------------------------- lib/dns/masterdump.c | 1 - lib/dns/rbtdb.c | 1 - lib/dns/result.c | 1 - lib/dns/tests/result_test.c | 1 - util/copyrights | 2 - 15 files changed, 22 insertions(+), 173 deletions(-) delete mode 100644 lib/dns/include/dns/lib.h delete mode 100644 lib/dns/lib.c diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 3559f1bf63..960695cb89 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -1735,13 +1734,15 @@ main(int argc, char *argv[]) { argc--; argv++; - result = dns_lib_init(); - if (result != ISC_R_SUCCESS) { - fatal("dns_lib_init failed: %d", result); - } - isc_mem_create(&mctx); + dns_result_register(); + + result = dst_lib_init(mctx, NULL); + if (result != ISC_R_SUCCESS) { + fatal("dst_lib_init failed: %d", result); + } + CHECK(isc_appctx_create(mctx, &actx)); isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, NULL); @@ -1856,7 +1857,7 @@ cleanup: } isc_mem_detach(&mctx); - dns_lib_shutdown(); + dst_lib_destroy(); return (0); } diff --git a/bin/named/server.c b/bin/named/server.c index 31c9af5572..602afc089a 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -73,7 +73,6 @@ #include #include #include -#include #include #include #include diff --git a/bin/tests/system/dyndb/driver/driver.c b/bin/tests/system/dyndb/driver/driver.c index 82b545d29c..266e71476e 100644 --- a/bin/tests/system/dyndb/driver/driver.c +++ b/bin/tests/system/dyndb/driver/driver.c @@ -22,7 +22,6 @@ #include #include -#include #include #include "db.h" diff --git a/bin/tests/system/resolve.c b/bin/tests/system/resolve.c index 6508b6e9ff..ee94fe98ad 100644 --- a/bin/tests/system/resolve.c +++ b/bin/tests/system/resolve.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -391,17 +390,17 @@ main(int argc, char *argv[]) { altserveraddr = cp + 1; } - result = dns_lib_init(); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "dns_lib_init failed: %u\n", result); - exit(1); - } - result = ctxs_init(); if (result != ISC_R_SUCCESS) { goto cleanup; } + result = dst_lib_init(ctxs_mctx, NULL); + if (result != ISC_R_SUCCESS) { + fprintf(stderr, "dst_lib_init failed: %u\n", result); + exit(1); + } + clientopt = 0; result = dns_client_create(ctxs_mctx, ctxs_actx, ctxs_taskmgr, ctxs_netmgr, ctxs_timermgr, clientopt, @@ -495,7 +494,7 @@ cleanup: } ctxs_destroy(); - dns_lib_shutdown(); + dst_lib_destroy(); return (0); } diff --git a/lib/dns/Makefile.am b/lib/dns/Makefile.am index d724dbd45b..b763756b5e 100644 --- a/lib/dns/Makefile.am +++ b/lib/dns/Makefile.am @@ -87,7 +87,6 @@ libdns_la_HEADERS = \ include/dns/keymgr.h \ include/dns/keytable.h \ include/dns/keyvalues.h \ - include/dns/lib.h \ include/dns/librpz.h \ include/dns/lookup.h \ include/dns/log.h \ @@ -190,7 +189,6 @@ libdns_la_SOURCES = \ keydata.c \ keymgr.c \ keytable.c \ - lib.c \ log.c \ lookup.c \ master.c \ diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 579d395131..60de98f2bf 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/dns/db.c b/lib/dns/db.c index c082a8d677..3a96f1d934 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -58,6 +58,8 @@ struct dns_dbimplementation { #include "rbtdb.h" +unsigned int dns_pps = 0U; + static ISC_LIST(dns_dbimplementation_t) implementations; static isc_rwlock_t implock; static isc_once_t once = ISC_ONCE_INIT; diff --git a/lib/dns/include/dns/db.h b/lib/dns/include/dns/db.h index 850746236e..29d3daebd2 100644 --- a/lib/dns/include/dns/db.h +++ b/lib/dns/include/dns/db.h @@ -64,6 +64,11 @@ ISC_LANG_BEGINDECLS +/*% + * Tuning: external query load in packets per seconds. + */ +extern unsigned int dns_pps; + /***** ***** Types *****/ diff --git a/lib/dns/include/dns/lib.h b/lib/dns/include/dns/lib.h deleted file mode 100644 index 8ee94ec04f..0000000000 --- a/lib/dns/include/dns/lib.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -#ifndef DNS_LIB_H -#define DNS_LIB_H 1 - -/*! \file dns/lib.h */ - -#include -#include - -ISC_LANG_BEGINDECLS - -/*% - * Tuning: external query load in packets per seconds. - */ -extern unsigned int dns_pps; - -isc_result_t -dns_lib_init(void); -/*%< - * A set of initialization procedures used in the DNS library. This function - * is provided for an application that is not aware of the underlying ISC or - * DNS libraries much. - */ - -void -dns_lib_shutdown(void); -/*%< - * Free temporary resources allocated in dns_lib_init(). - */ - -ISC_LANG_ENDDECLS - -#endif /* DNS_LIB_H */ diff --git a/lib/dns/lib.c b/lib/dns/lib.c deleted file mode 100644 index 36d0f5b7e6..0000000000 --- a/lib/dns/lib.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -/*! \file */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -/*** - *** Globals - ***/ - -unsigned int dns_pps = 0U; - -/*** - *** Functions - ***/ - -static isc_once_t init_once = ISC_ONCE_INIT; -static isc_mem_t *dns_g_mctx = NULL; -static bool initialize_done = false; -static isc_refcount_t references; - -static void -initialize(void) { - isc_result_t result; - - REQUIRE(!initialize_done); - - isc_refcount_init(&references, 0); - - isc_mem_create(&dns_g_mctx); - dns_result_register(); - - result = dst_lib_init(dns_g_mctx, NULL); - if (result != ISC_R_SUCCESS) { - goto cleanup_mctx; - } - - initialize_done = true; - return; - -cleanup_mctx: - if (dns_g_mctx != NULL) { - isc_mem_detach(&dns_g_mctx); - } -} - -isc_result_t -dns_lib_init(void) { - isc_result_t result; - - /* - * Since this routine is expected to be used by a normal application, - * it should be better to return an error, instead of an emergency - * abort, on any failure. - */ - result = isc_once_do(&init_once, initialize); - if (result != ISC_R_SUCCESS) { - return (result); - } - - if (!initialize_done) { - return (ISC_R_FAILURE); - } - - isc_refcount_increment0(&references); - - return (ISC_R_SUCCESS); -} - -void -dns_lib_shutdown(void) { - if (isc_refcount_decrement(&references) == 1) { - dst_lib_destroy(); - - isc_refcount_destroy(&references); - - if (dns_g_mctx != NULL) { - isc_mem_detach(&dns_g_mctx); - } - } -} diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index f3c0ebbbf5..f761376347 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index ec803925b9..97b8e6e804 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/dns/result.c b/lib/dns/result.c index 01ce2b4e85..b037e7f609 100644 --- a/lib/dns/result.c +++ b/lib/dns/result.c @@ -14,7 +14,6 @@ #include #include -#include #include static const char *text[DNS_R_NRESULTS] = { diff --git a/lib/dns/tests/result_test.c b/lib/dns/tests/result_test.c index b21828cbe5..66eeade0ec 100644 --- a/lib/dns/tests/result_test.c +++ b/lib/dns/tests/result_test.c @@ -23,7 +23,6 @@ #include #include -#include #include #include diff --git a/util/copyrights b/util/copyrights index 42ce88bb7e..13da1c2939 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1193,7 +1193,6 @@ ./lib/dns/include/dns/keymgr.h C 2019,2020,2021 ./lib/dns/include/dns/keytable.h C 2000,2001,2004,2005,2007,2009,2010,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/dns/include/dns/keyvalues.h C 1999,2000,2001,2003,2004,2005,2006,2007,2008,2009,2010,2012,2016,2017,2018,2019,2020,2021 -./lib/dns/include/dns/lib.h C 1999,2000,2001,2004,2005,2006,2007,2009,2016,2017,2018,2019,2020,2021 ./lib/dns/include/dns/librpz.h C 2017,2018,2019,2020,2021 ./lib/dns/include/dns/log.h C 1999,2000,2001,2003,2004,2005,2006,2007,2009,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/dns/include/dns/lookup.h C 2000,2001,2004,2005,2006,2007,2009,2016,2018,2019,2020,2021 @@ -1259,7 +1258,6 @@ ./lib/dns/keydata.c C 2009,2014,2016,2018,2019,2020,2021 ./lib/dns/keymgr.c C 2019,2020,2021 ./lib/dns/keytable.c C 2000,2001,2004,2005,2007,2009,2010,2013,2014,2015,2016,2017,2018,2019,2020,2021 -./lib/dns/lib.c C 1999,2000,2001,2004,2005,2007,2009,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/dns/log.c C 1999,2000,2001,2003,2004,2005,2006,2007,2009,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/dns/lookup.c C 2000,2001,2003,2004,2005,2007,2013,2016,2018,2019,2020,2021 ./lib/dns/master.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021