From b2dda8625444f7f409aed691574f819d0edd717d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 13 Aug 2024 15:52:51 +0200 Subject: [PATCH] Replace isc_log_create/destroy with isc_logconfig_get() Add isc_logconfig_get() function to get the current logconfig and use the getter to replace most of the little dancing around setting up logging in the tools. Thus: isc_log_create(mctx, &lctx, &logconfig); isc_log_setcontext(lctx); dns_log_setcontext(lctx); ... ...use lcfg... ... isc_log_destroy(); is now only: logconfig = isc_logconfig_get(lctx); ...use lcfg... For thread-safety, isc_logconfig_get() should be surrounded by RCU read lock, but since we never use isc_logconfig_get() in threaded context, the only place where it is actually used (but not really needed) is named_log_init(). --- bin/check/check-tool.c | 6 ++-- bin/check/named-checkconf.c | 4 --- bin/check/named-checkzone.c | 3 -- bin/delv/delv.c | 6 +--- bin/dig/dighost.c | 8 ++--- bin/dnssec/dnssectool.c | 16 ++++------ bin/named/include/named/log.h | 2 +- bin/named/log.c | 25 +++++++--------- bin/named/server.c | 2 +- bin/nsupdate/nsupdate.c | 7 +---- bin/rndc/rndc.c | 6 +--- bin/tests/system/makejournal.c | 19 ++++-------- bin/tests/system/pipelined/pipequeries.c | 6 ---- bin/tests/system/rsabigexponent/bigkey.c | 9 ++---- bin/tools/mdig.c | 5 ---- bin/tools/named-journalprint.c | 7 ++--- doc/dev/dev.md | 2 +- doc/misc/cfg_test.c | 5 +--- lib/dns/include/dns/log.h | 10 ------- lib/dns/log.c | 7 ----- lib/isc/include/isc/log.h | 37 +++++------------------- lib/isc/log.c | 37 +++++------------------- lib/isccfg/log.c | 2 -- lib/ns/include/ns/log.h | 10 ------- lib/ns/log.c | 7 ----- tests/bench/qpmulti.c | 9 ++---- tests/dns/qpmulti_test.c | 5 +--- tests/isccfg/duration_test.c | 16 ++-------- tests/isccfg/parser_test.c | 16 ++-------- 29 files changed, 60 insertions(+), 234 deletions(-) diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 352d83acbf..4e0b96afea 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -549,19 +549,17 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) { } isc_result_t -setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) { +setup_logging(isc_mem_t *mctx ISC_ATTR_UNUSED, FILE *errout, isc_log_t **logp) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *log = NULL; - isc_log_create(mctx, &log, &logconfig); isc_log_registercategories(log, categories); - isc_log_setcontext(log); dns_log_init(log); - dns_log_setcontext(log); cfg_log_init(log); ns_log_init(log); + logconfig = isc_logconfig_get(log); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 70b4b317ba..495902e648 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -753,10 +753,6 @@ cleanup: cfg_parser_destroy(&parser); } - if (logc != NULL) { - isc_log_destroy(&logc); - } - if (mctx != NULL) { isc_mem_destroy(&mctx); } diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index a0ddf8a94b..f637b4a5cb 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -566,9 +566,6 @@ main(int argc, char **argv) { fprintf(errout, "OK\n"); } destroy(); - if (lctx != NULL) { - isc_log_destroy(&lctx); - } isc_mem_destroy(&mctx); return ((result == ISC_R_SUCCESS) ? 0 : 1); diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 29989929e1..7e3bc57917 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -322,14 +322,12 @@ setup_logging(FILE *errout) { isc_logconfig_t *logconfig = NULL; int packetlevel = 10; - isc_log_create(mctx, &lctx, &logconfig); isc_log_registercategories(lctx, categories); isc_log_registermodules(lctx, modules); - isc_log_setcontext(lctx); dns_log_init(lctx); - dns_log_setcontext(lctx); cfg_log_init(lctx); + logconfig = isc_logconfig_get(lctx); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -2300,8 +2298,6 @@ cleanup: dns_master_styledestroy(&style, mctx); } - isc_log_destroy(&lctx); - isc_managers_destroy(&mctx, &loopmgr, &netmgr); return (0); diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 6756bd9900..64c33d4906 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1361,12 +1361,11 @@ setup_libs(void) { isc_managers_create(&mctx, 1, &loopmgr, &netmgr); - isc_log_create(mctx, &lctx, &logconfig); - isc_log_setcontext(lctx); dns_log_init(lctx); - dns_log_setcontext(lctx); + logconfig = isc_logconfig_get(lctx); result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL); + check_result(result, "isc_log_usechannel"); isc_log_setdebuglevel(lctx, 0); @@ -4747,9 +4746,6 @@ destroy_libs(void) { isc_buffer_free(&namebuf); } - debug("Removing log context"); - isc_log_destroy(&lctx); - debug("Destroy memory"); if (memdebugging != 0) { isc_mem_stats(mctx, stderr); diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index b35a24058f..3c272135d0 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -128,7 +128,7 @@ sig_format(dns_rdata_rrsig_t *sig, char *cp, unsigned int size) { } void -setup_logging(isc_mem_t *mctx, isc_log_t **logp) { +setup_logging(isc_mem_t *mctx ISC_ATTR_UNUSED, isc_log_t **logp) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *log = NULL; @@ -153,10 +153,10 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) { break; } - isc_log_create(mctx, &log, &logconfig); - isc_log_setcontext(log); dns_log_init(log); - dns_log_setcontext(log); + + logconfig = isc_logconfig_get(log); + isc_log_settag(logconfig, program); /* @@ -181,20 +181,14 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) { void cleanup_logging(isc_log_t **logp) { - isc_log_t *log; - REQUIRE(logp != NULL); - log = *logp; + isc_log_t *log = *logp; *logp = NULL; if (log == NULL) { return; } - - isc_log_destroy(&log); - isc_log_setcontext(NULL); - dns_log_setcontext(NULL); } static isc_stdtime_t diff --git a/bin/named/include/named/log.h b/bin/named/include/named/log.h index f18e93a17f..eebe892081 100644 --- a/bin/named/include/named/log.h +++ b/bin/named/include/named/log.h @@ -81,4 +81,4 @@ named_log_setunmatchedcategory(isc_logconfig_t *lcfg); */ void -named_log_shutdown(void); +named_log_shutdown(void) __attribute__((__deprecated__)); diff --git a/bin/named/log.c b/bin/named/log.c index d25382d89a..41102c1c9f 100644 --- a/bin/named/log.c +++ b/bin/named/log.c @@ -51,7 +51,6 @@ isc_result_t named_log_init(bool safe) { isc_result_t result; isc_logconfig_t *lcfg = NULL; - isc_mem_t *log_mctx = NULL; named_g_categories = categories; named_g_modules = modules; @@ -59,23 +58,24 @@ named_log_init(bool safe) { /* * Setup a logging context. */ - isc_mem_create(&log_mctx); - isc_mem_setname(log_mctx, "named_log"); - isc_log_create(log_mctx, &named_g_lctx, &lcfg); - isc_mem_detach(&log_mctx); /* * named-checktool.c:setup_logging() needs to be kept in sync. */ isc_log_registercategories(named_g_lctx, named_g_categories); isc_log_registermodules(named_g_lctx, named_g_modules); - isc_log_setcontext(named_g_lctx); dns_log_init(named_g_lctx); - dns_log_setcontext(named_g_lctx); cfg_log_init(named_g_lctx); ns_log_init(named_g_lctx); - ns_log_setcontext(named_g_lctx); + /* + * This is not technically needed, as we are calling named_log_init() + * only at the start of named process. But since the named binary is + * the only place that also calls isc_logconfig_set(), this is a good + * hygiene. + */ + rcu_read_lock(); + lcfg = isc_logconfig_get(named_g_lctx); if (safe) { named_log_setsafechannels(lcfg); } else { @@ -88,13 +88,12 @@ named_log_init(bool safe) { } named_log_setdefaultsslkeylogfile(lcfg); + rcu_read_unlock(); return (ISC_R_SUCCESS); cleanup: - isc_log_destroy(&named_g_lctx); - isc_log_setcontext(NULL); - dns_log_setcontext(NULL); + rcu_read_unlock(); return (result); } @@ -251,7 +250,5 @@ named_log_setunmatchedcategory(isc_logconfig_t *lcfg) { void named_log_shutdown(void) { - isc_log_destroy(&named_g_lctx); - isc_log_setcontext(NULL); - dns_log_setcontext(NULL); + /* no-op */ } diff --git a/bin/named/server.c b/bin/named/server.c index 7a6c837c5f..e352827657 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -9407,7 +9407,7 @@ load_configuration(const char *filename, named_server_t *server, } } - isc_logconfig_use(named_g_lctx, logc); + isc_logconfig_set(named_g_lctx, logc); logc = NULL; isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 5e06051cf6..ac2b62f7f7 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -812,11 +812,9 @@ setup_system(void *arg ISC_ATTR_UNUSED) { ddebug("setup_system()"); - isc_log_create(gmctx, &glctx, &logconfig); - isc_log_setcontext(glctx); dns_log_init(glctx); - dns_log_setcontext(glctx); + logconfig = isc_logconfig_get(glctx); result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL); check_result(result, "isc_log_usechannel"); @@ -3488,9 +3486,6 @@ cleanup(void) { } #endif /* ifdef HAVE_GSSAPI */ - ddebug("Removing log context"); - isc_log_destroy(&glctx); - ddebug("Destroying memory context"); if (memdebugging) { isc_mem_stats(gmctx, stderr); diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index b11fbf47d2..101eccdb71 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -954,8 +954,7 @@ main(int argc, char **argv) { isc_nm_settimeouts(netmgr, timeout, timeout, timeout, 0); - isc_log_create(rndc_mctx, &log, &logconfig); - isc_log_setcontext(log); + logconfig = isc_logconfig_get(log); isc_log_settag(logconfig, progname); logdest.file.stream = stderr; logdest.file.name = NULL; @@ -1003,9 +1002,6 @@ main(int argc, char **argv) { isccc_ccmsg_invalidate(&rndc_ccmsg); - isc_log_destroy(&log); - isc_log_setcontext(NULL); - cfg_obj_destroy(pctx, &config); cfg_parser_destroy(&pctx); diff --git a/bin/tests/system/makejournal.c b/bin/tests/system/makejournal.c index 6c1ddfc85c..f57ba40775 100644 --- a/bin/tests/system/makejournal.c +++ b/bin/tests/system/makejournal.c @@ -29,13 +29,6 @@ #include #include -#define CHECK(r) \ - do { \ - result = (r); \ - if (result != ISC_R_SUCCESS) \ - goto cleanup; \ - } while (0) - isc_mem_t *mctx = NULL; isc_log_t *lctx = NULL; @@ -99,12 +92,10 @@ main(int argc, char **argv) { isc_mem_debugging |= ISC_MEM_DEBUGRECORD; isc_mem_create(&mctx); - isc_log_create(mctx, &lctx, &logconfig); isc_log_registercategories(lctx, categories); - isc_log_setcontext(lctx); dns_log_init(lctx); - dns_log_setcontext(lctx); + logconfig = isc_logconfig_get(lctx); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -112,7 +103,10 @@ main(int argc, char **argv) { isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0); - CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); + result = isc_log_usechannel(logconfig, "stderr", NULL, NULL); + if (result != ISC_R_SUCCESS) { + goto cleanup; + } result = loadzone(&olddb, origin, file1); if (result != ISC_R_SUCCESS) { @@ -140,9 +134,6 @@ cleanup: dns_db_detach(&olddb); } - if (lctx != NULL) { - isc_log_destroy(&lctx); - } if (mctx != NULL) { isc_mem_destroy(&mctx); } diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index d636f05978..31ce067a91 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -216,8 +216,6 @@ main(int argc, char *argv[]) { isc_sockaddr_t bind_any; struct in_addr inaddr; isc_result_t result; - isc_log_t *lctx = NULL; - isc_logconfig_t *lcfg = NULL; isc_nm_t *netmgr = NULL; dns_dispatchmgr_t *dispatchmgr = NULL; dns_dispatch_t *dispatchv4 = NULL; @@ -273,8 +271,6 @@ main(int argc, char *argv[]) { isc_managers_create(&mctx, 1, &loopmgr, &netmgr); - isc_log_create(mctx, &lctx, &lcfg); - RUNCHECK(dns_dispatchmgr_create(mctx, loopmgr, netmgr, &dispatchmgr)); RUNCHECK(dns_dispatch_createudp( @@ -292,8 +288,6 @@ main(int argc, char *argv[]) { isc_loopmgr_run(loopmgr); - isc_log_destroy(&lctx); - isc_managers_destroy(&mctx, &loopmgr, &netmgr); return (0); diff --git a/bin/tests/system/rsabigexponent/bigkey.c b/bin/tests/system/rsabigexponent/bigkey.c index ad76fd7db8..c3b858683f 100644 --- a/bin/tests/system/rsabigexponent/bigkey.c +++ b/bin/tests/system/rsabigexponent/bigkey.c @@ -105,10 +105,10 @@ main(int argc, char **argv) { } isc_mem_create(&mctx); - isc_log_create(mctx, &log_, &logconfig); - isc_log_setcontext(log_); + dns_log_init(log_); - dns_log_setcontext(log_); + + logconfig = isc_logconfig_get(log_); isc_log_settag(logconfig, "bigkey"); destination.file.stream = stderr; @@ -144,9 +144,6 @@ main(int argc, char **argv) { printf("%s\n", filename); dst_key_free(&key); - isc_log_destroy(&log_); - isc_log_setcontext(NULL); - dns_log_setcontext(NULL); isc_mem_destroy(&mctx); return (0); } diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index b5b14936c0..1587600585 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -2111,8 +2111,6 @@ int main(int argc, char *argv[]) { struct query *query = NULL; isc_result_t result; - isc_log_t *lctx = NULL; - isc_logconfig_t *lcfg = NULL; unsigned int i; int ns; @@ -2129,7 +2127,6 @@ main(int argc, char *argv[]) { preparse_args(argc, argv); isc_managers_create(&mctx, 1, &loopmgr, &netmgr); - isc_log_create(mctx, &lctx, &lcfg); isc_nonce_buf(cookie_secret, sizeof(cookie_secret)); @@ -2190,8 +2187,6 @@ main(int argc, char *argv[]) { isc_loopmgr_run(loopmgr); - isc_log_destroy(&lctx); - query = ISC_LIST_HEAD(queries); while (query != NULL) { struct query *next = ISC_LIST_NEXT(query, link); diff --git a/bin/tools/named-journalprint.c b/bin/tools/named-journalprint.c index ce6c3816d0..c047074acf 100644 --- a/bin/tools/named-journalprint.c +++ b/bin/tools/named-journalprint.c @@ -37,16 +37,14 @@ usage(void) { * Setup logging to use stderr. */ static isc_result_t -setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) { +setup_logging(isc_mem_t *mctx ISC_ATTR_UNUSED, FILE *errout, isc_log_t **logp) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *log = NULL; - isc_log_create(mctx, &log, &logconfig); - isc_log_setcontext(log); dns_log_init(log); - dns_log_setcontext(log); + logconfig = isc_logconfig_get(log); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -127,7 +125,6 @@ main(int argc, char **argv) { fprintf(stderr, "%s\n", isc_result_totext(result)); } } - isc_log_destroy(&lctx); isc_mem_detach(&mctx); return (result != ISC_R_SUCCESS ? 1 : 0); } diff --git a/doc/dev/dev.md b/doc/dev/dev.md index f186a9ed2e..437aa88033 100644 --- a/doc/dev/dev.md +++ b/doc/dev/dev.md @@ -1060,7 +1060,7 @@ the context (`isc_log_t`) is created. The pointer to this configuration is returned via a parameter to `isc_log_create()` so that it can then be configured. A new log configuration can be established by creating it with `isc_logconfig_create()`, configuring it, then installing it as -the active configuration with `isc_logconfig_use()`. +the active configuration with `isc_logconfig_set()`. ##### Logging in multithreaded programs diff --git a/doc/misc/cfg_test.c b/doc/misc/cfg_test.c index e5e62c8cd5..6d53fd2442 100644 --- a/doc/misc/cfg_test.c +++ b/doc/misc/cfg_test.c @@ -73,12 +73,10 @@ main(int argc, char **argv) { isc_mem_create(&mctx); - isc_log_create(mctx, &lctx, &lcfg); - isc_log_setcontext(lctx); - /* * Create and install the default channel. */ + lcfg = isc_logconfig_get(lctx); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -176,7 +174,6 @@ main(int argc, char **argv) { cfg_parser_destroy(&pctx); } - isc_log_destroy(&lctx); if (memstats) { isc_mem_stats(mctx, stderr); } diff --git a/lib/dns/include/dns/log.h b/lib/dns/include/dns/log.h index e2cd959dc8..97e0ac00cc 100644 --- a/lib/dns/include/dns/log.h +++ b/lib/dns/include/dns/log.h @@ -100,14 +100,4 @@ dns_log_init(isc_log_t *lctx); * use by isc_log_usechannnel() and isc_log_write(). */ -void -dns_log_setcontext(isc_log_t *lctx); -/*% - * Make the libdns library use the provided context for logging internal - * messages. - * - * Requires: - *\li lctx is a valid logging context. - */ - ISC_LANG_ENDDECLS diff --git a/lib/dns/log.c b/lib/dns/log.c index 6f583d763b..6eed43ec06 100644 --- a/lib/dns/log.c +++ b/lib/dns/log.c @@ -57,13 +57,6 @@ isc_log_t *dns_lctx = NULL; void dns_log_init(isc_log_t *lctx) { - REQUIRE(lctx != NULL); - isc_log_registercategories(lctx, dns_categories); isc_log_registermodules(lctx, dns_modules); } - -void -dns_log_setcontext(isc_log_t *lctx) { - dns_lctx = lctx; -} diff --git a/lib/isc/include/isc/log.h b/lib/isc/include/isc/log.h index 119772eb11..cc4c340517 100644 --- a/lib/isc/include/isc/log.h +++ b/lib/isc/include/isc/log.h @@ -184,15 +184,6 @@ extern isc_logmodule_t isc_modules[]; ISC_LANG_BEGINDECLS -void -isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp); -/*%< - * A dummy function that mimicks: - * - * isc_logconfig_create(NULL, lcfgp); - * isc_logconfig_use(NULL, *lcfgp); - */ - void isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp); /*%< @@ -235,16 +226,16 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp); *\li On failure, no additional memory is allocated. */ +isc_logconfig_t * +isc_logconfig_get(isc_log_t *lctx); void -isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg); +isc_logconfig_set(isc_log_t *lctx, isc_logconfig_t *lcfg); /*%< - * Associate a new configuration with a logging context. + * Getter/setter for a configuration with a logging context. * * Notes: - *\li This is thread safe. The logging context will lock a mutex - * before attempting to swap in the new configuration, and isc_log_doit - * (the internal function used by all of isc_log_[v]write[1]) locks - * the same lock for the duration of its use of the configuration. + *\li The setter is thread safe. The getter is only thread-safe + * if the isc_logconfig_get() call is protected by RCU read-lock. * * Requires: *\li lctx is a valid logging context. @@ -254,12 +245,7 @@ isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg); * * Ensures: *\li Future calls to isc_log_write will use the new configuration. - */ - -void -isc_log_destroy(isc_log_t **lctxp); -/*%< - * Dummy function that does nothing. + *\li The previous configuration object will be destroyed. */ void @@ -800,15 +786,6 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name); *\li NULL if no module exists by that name. */ -void -isc_log_setcontext(isc_log_t *lctx); -/*%< - * Sets the context used by the libisc for logging. - * - * Requires: - *\li lctx be a valid context. - */ - isc_result_t isc_logfile_roll(isc_logfile_t *file); /*%< diff --git a/lib/isc/log.c b/lib/isc/log.c index 2e4298067a..c03cc3e746 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -288,8 +288,15 @@ isc_logconfig_create(isc_log_t *__lctx ISC_ATTR_UNUSED, *lcfgp = lcfg; } +isc_logconfig_t * +isc_logconfig_get(isc_log_t *__lctx ISC_ATTR_UNUSED) { + REQUIRE(VALID_CONTEXT(isc__lctx)); + + return (rcu_dereference(isc__lctx->logconfig)); +} + void -isc_logconfig_use(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logconfig_t *lcfg) { +isc_logconfig_set(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logconfig_t *lcfg) { REQUIRE(VALID_CONTEXT(isc__lctx)); REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(lcfg->lctx == isc__lctx); @@ -701,11 +708,6 @@ isc_log_vwrite1(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category, isc_log_doit(NULL, category, module, level, true, format, args); } -void -isc_log_setcontext(isc_log_t *lctx) { - isc_lctx = lctx; -} - void isc_log_setdebuglevel(isc_log_t *__lctx ISC_ATTR_UNUSED, unsigned int level) { REQUIRE(VALID_CONTEXT(isc__lctx)); @@ -1853,26 +1855,3 @@ isc__log_shutdown(void) { isc_mem_putanddetach(&mctx, isc__lctx, sizeof(*isc__lctx)); } - -void -isc_log_create(isc_mem_t *mctx ISC_ATTR_UNUSED, isc_log_t **lctxp, - isc_logconfig_t **lcfgp) { - REQUIRE(lctxp != NULL && *lctxp == NULL); - REQUIRE(lcfgp == NULL || *lcfgp == NULL); - REQUIRE(VALID_CONTEXT(isc__lctx)); - - isc_logconfig_create(isc__lctx, lcfgp); - isc_logconfig_use(isc__lctx, *lcfgp); - - *lctxp = isc__lctx; - - rcu_read_lock(); - SET_IF_NOT_NULL(lcfgp, rcu_dereference(isc__lctx->logconfig)); - rcu_read_unlock(); -} - -void -isc_log_destroy(isc_log_t **lctxp ISC_ATTR_UNUSED) { - REQUIRE(lctxp != NULL && VALID_CONTEXT(*lctxp)); - REQUIRE(*lctxp == isc__lctx); -} diff --git a/lib/isccfg/log.c b/lib/isccfg/log.c index 22979ef272..099331af2e 100644 --- a/lib/isccfg/log.c +++ b/lib/isccfg/log.c @@ -31,8 +31,6 @@ isc_logmodule_t cfg_modules[] = { { "isccfg/parser", 0 }, { NULL, 0 } }; void cfg_log_init(isc_log_t *lctx) { - REQUIRE(lctx != NULL); - isc_log_registercategories(lctx, cfg_categories); isc_log_registermodules(lctx, cfg_modules); } diff --git a/lib/ns/include/ns/log.h b/lib/ns/include/ns/log.h index 3ade016a8e..ba21175dfc 100644 --- a/lib/ns/include/ns/log.h +++ b/lib/ns/include/ns/log.h @@ -60,13 +60,3 @@ ns_log_init(isc_log_t *lctx); *\li The categories and modules defined above are available for * use by isc_log_usechannnel() and isc_log_write(). */ - -void -ns_log_setcontext(isc_log_t *lctx); -/*%< - * Make the libns library use the provided context for logging internal - * messages. - * - * Requires: - *\li lctx is a valid logging context. - */ diff --git a/lib/ns/log.c b/lib/ns/log.c index 4a7ff20d02..0adf034241 100644 --- a/lib/ns/log.c +++ b/lib/ns/log.c @@ -50,13 +50,6 @@ isc_log_t *ns_lctx = NULL; void ns_log_init(isc_log_t *lctx) { - REQUIRE(lctx != NULL); - isc_log_registercategories(lctx, ns_categories); isc_log_registermodules(lctx, ns_modules); } - -void -ns_log_setcontext(isc_log_t *lctx) { - ns_lctx = lctx; -} diff --git a/tests/bench/qpmulti.c b/tests/bench/qpmulti.c index 590b90b5a5..2a7451d90c 100644 --- a/tests/bench/qpmulti.c +++ b/tests/bench/qpmulti.c @@ -153,17 +153,15 @@ init_items(isc_mem_t *mctx) { } static void -init_logging(isc_mem_t *mctx) { +init_logging(void) { isc_result_t result; isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *lctx = NULL; - isc_log_create(mctx, &lctx, &logconfig); - isc_log_setcontext(lctx); dns_log_init(lctx); - dns_log_setcontext(lctx); + logconfig = isc_logconfig_get(lctx); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -893,7 +891,7 @@ main(void) { isc_mem_create(&mctx); isc_mem_setdestroycheck(mctx, true); - init_logging(mctx); + init_logging(); init_items(mctx); isc_loopmgr_create(mctx, nloops, &loopmgr); @@ -902,7 +900,6 @@ main(void) { isc_loopmgr_run(loopmgr); isc_loopmgr_destroy(&loopmgr); - isc_log_destroy(&dns_lctx); isc_mem_free(mctx, item); isc_mem_checkdestroyed(stdout); isc_mem_destroy(&mctx); diff --git a/tests/dns/qpmulti_test.c b/tests/dns/qpmulti_test.c index 30ec498f56..b6603dddc0 100644 --- a/tests/dns/qpmulti_test.c +++ b/tests/dns/qpmulti_test.c @@ -72,11 +72,9 @@ setup_logging(void) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; - isc_log_create(mctx, &lctx, &logconfig); - isc_log_setcontext(lctx); dns_log_init(lctx); - dns_log_setcontext(lctx); + logconfig = isc_logconfig_get(lctx); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -391,7 +389,6 @@ ISC_RUN_TEST_IMPL(qpmulti) { isc_loopmgr_run(loopmgr); rcu_barrier(); isc_loopmgr_destroy(&loopmgr); - isc_log_destroy(&dns_lctx); } ISC_TEST_LIST_START diff --git a/tests/isccfg/duration_test.c b/tests/isccfg/duration_test.c index 8bc911cf23..d093e70e3c 100644 --- a/tests/isccfg/duration_test.c +++ b/tests/isccfg/duration_test.c @@ -52,10 +52,9 @@ ISC_SETUP_TEST_IMPL(group) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; - isc_log_create(mctx, &lctx, &logconfig); isc_log_registercategories(lctx, categories); - isc_log_setcontext(lctx); + logconfig = isc_logconfig_get(lctx); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -71,17 +70,6 @@ ISC_SETUP_TEST_IMPL(group) { return (0); } -ISC_TEARDOWN_TEST_IMPL(group) { - if (lctx == NULL) { - return (-1); - } - - isc_log_setcontext(NULL); - isc_log_destroy(&lctx); - - return (0); -} - struct duration_conf { const char *string; uint32_t time; @@ -240,4 +228,4 @@ ISC_TEST_ENTRY(duration) ISC_TEST_LIST_END -ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group) +ISC_TEST_MAIN_CUSTOM(setup_test_group, NULL) diff --git a/tests/isccfg/parser_test.c b/tests/isccfg/parser_test.c index baba26dd6d..9bbd0ddd33 100644 --- a/tests/isccfg/parser_test.c +++ b/tests/isccfg/parser_test.c @@ -53,10 +53,9 @@ ISC_SETUP_TEST_IMPL(group) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; - isc_log_create(mctx, &lctx, &logconfig); isc_log_registercategories(lctx, categories); - isc_log_setcontext(lctx); + logconfig = isc_logconfig_get(lctx); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; @@ -72,17 +71,6 @@ ISC_SETUP_TEST_IMPL(group) { return (0); } -ISC_TEARDOWN_TEST_IMPL(group) { - if (lctx == NULL) { - return (-1); - } - - isc_log_setcontext(NULL); - isc_log_destroy(&lctx); - - return (0); -} - /* mimic calling nzf_append() */ static void append(void *arg, const char *str, int len) { @@ -225,4 +213,4 @@ ISC_TEST_ENTRY(cfg_map_nextclause) ISC_TEST_LIST_END -ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group) +ISC_TEST_MAIN_CUSTOM(setup_test_group, NULL)