From cdf9a1fd2082c876e4b730c8bd78abe825fe4875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 1 Oct 2019 09:47:19 +0200 Subject: [PATCH] Remove support for external applications to register libisc The previous versions of BIND 9 exported its internal libraries so that they can be used by third-party applications more easily. Certain library functions were altered from specific BIND-only behavior to more generic behavior when used by other applications. This commit removes the function isc_lib_register() that was used by external applications to enable the functionality. --- bin/delv/delv.c | 2 - bin/plugins/filter-a.c | 1 - bin/plugins/filter-aaaa.c | 1 - bin/tests/system/dyndb/driver/driver.c | 2 - bin/tests/system/hooks/driver/test-async.c | 1 - bin/tests/system/resolve.c | 2 - lib/dns/include/dns/dyndb.h | 2 +- lib/isc/Makefile.am | 1 - lib/isc/app.c | 45 ++++++++-------------- lib/isc/bind9.c | 7 ---- lib/isc/include/isc/bind9.h | 11 +----- lib/isc/include/isc/lib.h | 33 ---------------- lib/isc/lib.c | 6 --- lib/isc/result.c | 1 - util/copyrights | 1 - 15 files changed, 18 insertions(+), 98 deletions(-) delete mode 100644 lib/isc/include/isc/lib.h diff --git a/bin/delv/delv.c b/bin/delv/delv.c index c3ff1860b6..aefe3b94dc 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -1737,7 +1736,6 @@ main(int argc, char *argv[]) { argc--; argv++; - isc_lib_register(); result = dns_lib_init(); if (result != ISC_R_SUCCESS) { fatal("dns_lib_init failed: %d", result); diff --git a/bin/plugins/filter-a.c b/bin/plugins/filter-a.c index 1c67a6cb66..f72d6e54ab 100644 --- a/bin/plugins/filter-a.c +++ b/bin/plugins/filter-a.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index a00946f5f8..ec741835b8 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -20,7 +20,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 1af50c6c14..82b545d29c 100644 --- a/bin/tests/system/dyndb/driver/driver.c +++ b/bin/tests/system/dyndb/driver/driver.c @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -76,7 +75,6 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters, * to initialize libisc/libdns */ if (dctx->refvar != &isc_bind9) { - isc_lib_register(); isc_log_setcontext(dctx->lctx); dns_log_setcontext(dctx->lctx); isc_hash_set_initializer(dctx->hashinit); diff --git a/bin/tests/system/hooks/driver/test-async.c b/bin/tests/system/hooks/driver/test-async.c index f3deee2b83..d52f2eb688 100644 --- a/bin/tests/system/hooks/driver/test-async.c +++ b/bin/tests/system/hooks/driver/test-async.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/bin/tests/system/resolve.c b/bin/tests/system/resolve.c index 165124a68f..cf95ffd9ce 100644 --- a/bin/tests/system/resolve.c +++ b/bin/tests/system/resolve.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -394,7 +393,6 @@ main(int argc, char *argv[]) { altserveraddr = cp + 1; } - isc_lib_register(); result = dns_lib_init(); if (result != ISC_R_SUCCESS) { fprintf(stderr, "dns_lib_init failed: %u\n", result); diff --git a/lib/dns/include/dns/dyndb.h b/lib/dns/include/dns/dyndb.h index 2b0d1edbc0..0b2625403c 100644 --- a/lib/dns/include/dns/dyndb.h +++ b/lib/dns/include/dns/dyndb.h @@ -40,7 +40,7 @@ struct dns_dyndbctx { dns_zonemgr_t * zmgr; isc_task_t * task; isc_timermgr_t *timermgr; - bool * refvar; + const bool * refvar; }; #define DNS_DYNDBCTX_MAGIC ISC_MAGIC('D', 'd', 'b', 'c') diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 5f90634b3a..b6bd2a4dfd 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -45,7 +45,6 @@ libisc_la_HEADERS = \ include/isc/iterated_hash.h \ include/isc/lang.h \ include/isc/lex.h \ - include/isc/lib.h \ include/isc/likely.h \ include/isc/list.h \ include/isc/log.h \ diff --git a/lib/isc/app.c b/lib/isc/app.c index 1efadd0241..7bbb0331fe 100644 --- a/lib/isc/app.c +++ b/lib/isc/app.c @@ -36,8 +36,8 @@ #include /*% - * For BIND9 internal applications built with threads, we use a single app - * context and let multiple worker, I/O, timer threads do actual jobs. + * For BIND9 applications built with threads, we use a single app + * context and let multiple taskmgr and netmgr threads do actual jobs. */ static isc_thread_t blockedthread; @@ -206,13 +206,6 @@ isc_app_ctxrun(isc_appctx_t *ctx) { UNLOCK(&ctx->lock); } - /* - * BIND9 internal tools using multiple contexts do not - * rely on signal. */ - if (isc_bind9 && ctx != &isc_g_appctx) { - return (ISC_R_SUCCESS); - } - /* * There is no danger if isc_app_shutdown() is called before we * wait for signals. Signals are blocked, so any such signal will @@ -220,11 +213,10 @@ isc_app_ctxrun(isc_appctx_t *ctx) { * sigwait(). */ while (!atomic_load_acquire(&ctx->want_shutdown)) { - if (isc_bind9) { + if (ctx == &isc_g_appctx) { sigset_t sset; int sig; /* - * BIND9 internal; single context: * Wait for SIGHUP, SIGINT, or SIGTERM. */ if (sigemptyset(&sset) != 0 || @@ -257,8 +249,9 @@ isc_app_ctxrun(isc_appctx_t *ctx) { } } else { /* - * External, or BIND9 using multiple contexts: - * wait until woken up. + * Tools using multiple contexts don't + * rely on a signal, just wait until woken + * up. */ if (atomic_load_acquire(&ctx->want_shutdown)) { break; @@ -314,11 +307,12 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) { if (atomic_compare_exchange_strong_acq_rel(&ctx->shutdown_requested, &(bool){ false }, true)) { - if (isc_bind9 && ctx != &isc_g_appctx) { - /* BIND9 internal, but using multiple contexts */ + if (ctx != &isc_g_appctx) { + /* Tool using multiple contexts */ atomic_store_release(&ctx->want_shutdown, true); - } else if (isc_bind9) { - /* BIND9 internal, single context */ + SIGNAL(&ctx->ready); + } else { + /* Normal single BIND9 context */ if (kill(getpid(), SIGTERM) < 0) { char strbuf[ISC_STRERRORSIZE]; strerror_r(errno, strbuf, sizeof(strbuf)); @@ -327,10 +321,6 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) { "kill: %s", strbuf); } - } else { - /* External, multiple contexts */ - atomic_store_release(&ctx->want_shutdown, true); - SIGNAL(&ctx->ready); } } } @@ -350,11 +340,12 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) { * Don't send the reload signal if we're shutting down. */ if (!atomic_load_acquire(&ctx->shutdown_requested)) { - if (isc_bind9 && ctx != &isc_g_appctx) { - /* BIND9 internal, but using multiple contexts */ + if (ctx != &isc_g_appctx) { + /* Tool using multiple contexts */ atomic_store_release(&ctx->want_reload, true); - } else if (isc_bind9) { - /* BIND9 internal, single context */ + SIGNAL(&ctx->ready); + } else { + /* Normal single BIND9 context */ if (kill(getpid(), SIGHUP) < 0) { char strbuf[ISC_STRERRORSIZE]; strerror_r(errno, strbuf, sizeof(strbuf)); @@ -363,10 +354,6 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) { "kill: %s", strbuf); } - } else { - /* External, multiple contexts */ - atomic_store_release(&ctx->want_reload, true); - SIGNAL(&ctx->ready); } } } diff --git a/lib/isc/bind9.c b/lib/isc/bind9.c index 9b7bdfacda..6bbe3f6a79 100644 --- a/lib/isc/bind9.c +++ b/lib/isc/bind9.c @@ -15,11 +15,4 @@ #include -/* - * This determines whether we are using the libisc/libdns libraries - * in BIND9 or in some other application. It is initialized to true - * and remains unchanged for BIND9 and related tools; export library - * clients will run isc_lib_register(), which sets it to false, - * overriding certain BIND9 behaviors. - */ bool isc_bind9 = true; diff --git a/lib/isc/include/isc/bind9.h b/lib/isc/include/isc/bind9.h index be5a7df3a1..edbdc946a9 100644 --- a/lib/isc/include/isc/bind9.h +++ b/lib/isc/include/isc/bind9.h @@ -9,17 +9,8 @@ * information regarding copyright ownership. */ -#ifndef ISC_BIND9_H -#define ISC_BIND9_H 1 +#pragma once #include -/* - * This determines whether we are using the libisc/libdns libraries - * in BIND9 or in some other application. For BIND9 (named and related - * tools) it must be set to true at runtime. Export library clients - * will call isc_lib_register(), which will set it to false. - */ extern bool isc_bind9; - -#endif /* ISC_BIND9_H */ diff --git a/lib/isc/include/isc/lib.h b/lib/isc/include/isc/lib.h deleted file mode 100644 index 4a77293c32..0000000000 --- a/lib/isc/include/isc/lib.h +++ /dev/null @@ -1,33 +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 ISC_LIB_H -#define ISC_LIB_H 1 - -/*! \file isc/lib.h */ - -#include -#include - -ISC_LANG_BEGINDECLS - -void -isc_lib_register(void); -/*!< - * \brief Register the ISC library implementations for some base services - * such as memory or event management and handling socket or timer events. - * An external application that wants to use the ISC library must call this - * function very early in main(). - */ - -ISC_LANG_ENDDECLS - -#endif /* ISC_LIB_H */ diff --git a/lib/isc/lib.c b/lib/isc/lib.c index 18e3284be0..5f9173ff4c 100644 --- a/lib/isc/lib.c +++ b/lib/isc/lib.c @@ -12,7 +12,6 @@ /*! \file */ #include -#include #include #include #include @@ -31,11 +30,6 @@ *** Functions ***/ -void -isc_lib_register(void) { - isc_bind9 = false; -} - void isc__initialize(void) ISC_CONSTRUCTOR; void diff --git a/lib/isc/result.c b/lib/isc/result.c index 72e7a3c28e..6a10dd1c2c 100644 --- a/lib/isc/result.c +++ b/lib/isc/result.c @@ -14,7 +14,6 @@ #include #include -#include #include #include #include diff --git a/util/copyrights b/util/copyrights index 490b788e8a..25f5077bc5 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1723,7 +1723,6 @@ ./lib/isc/include/isc/iterated_hash.h C 2008,2014,2016,2018,2019,2020,2021 ./lib/isc/include/isc/lang.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018,2019,2020,2021 ./lib/isc/include/isc/lex.h C 1998,1999,2000,2001,2002,2004,2005,2007,2008,2015,2016,2017,2018,2019,2020,2021 -./lib/isc/include/isc/lib.h C 1999,2000,2001,2004,2005,2006,2007,2009,2016,2018,2019,2020,2021 ./lib/isc/include/isc/likely.h C 2017,2018,2019,2020,2021 ./lib/isc/include/isc/list.h C 1997,1998,1999,2000,2001,2002,2004,2006,2007,2011,2012,2013,2016,2018,2019,2020,2021 ./lib/isc/include/isc/log.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020,2021