]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace isc_log_create/destroy with isc_logconfig_get()
authorOndřej Surý <ondrej@isc.org>
Tue, 13 Aug 2024 13:52:51 +0000 (15:52 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 20 Aug 2024 12:50:39 +0000 (12:50 +0000)
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().

29 files changed:
bin/check/check-tool.c
bin/check/named-checkconf.c
bin/check/named-checkzone.c
bin/delv/delv.c
bin/dig/dighost.c
bin/dnssec/dnssectool.c
bin/named/include/named/log.h
bin/named/log.c
bin/named/server.c
bin/nsupdate/nsupdate.c
bin/rndc/rndc.c
bin/tests/system/makejournal.c
bin/tests/system/pipelined/pipequeries.c
bin/tests/system/rsabigexponent/bigkey.c
bin/tools/mdig.c
bin/tools/named-journalprint.c
doc/dev/dev.md
doc/misc/cfg_test.c
lib/dns/include/dns/log.h
lib/dns/log.c
lib/isc/include/isc/log.h
lib/isc/log.c
lib/isccfg/log.c
lib/ns/include/ns/log.h
lib/ns/log.c
tests/bench/qpmulti.c
tests/dns/qpmulti_test.c
tests/isccfg/duration_test.c
tests/isccfg/parser_test.c

index 352d83acbf0697a46c80a50e040c880da94e196c..4e0b96afeac06c1335ec7f7bc8f2f785e1caa9b6 100644 (file)
@@ -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;
index 70b4b317ba1c782425e0cf2ac2da6a1ae6f08ab6..495902e648740784dd581a34a2989903ecd037a0 100644 (file)
@@ -753,10 +753,6 @@ cleanup:
                cfg_parser_destroy(&parser);
        }
 
-       if (logc != NULL) {
-               isc_log_destroy(&logc);
-       }
-
        if (mctx != NULL) {
                isc_mem_destroy(&mctx);
        }
index a0ddf8a94b7ffad7a40cc849679a7ca0a27509dd..f637b4a5cba8017ec724e8e48e4616e0cfced70c 100644 (file)
@@ -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);
index 29989929e185b16a1dce5a966df79925b6718bd7..7e3bc57917ff13be3e600a099ef846e9492fde24 100644 (file)
@@ -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);
index 6756bd990093d317403f8daa17874c6a48c08125..64c33d4906d4d43df6b549c24babf31b30d1365c 100644 (file)
@@ -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);
index b35a24058f4cd21359e30b13cbb57305bd5519d3..3c272135d010c55e1a78e0b0286e5dbf89921d80 100644 (file)
@@ -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
index f18e93a17ff167cc7002a5abd4486e7886ad62de..eebe89208137da3b8e68383d05f8e6720bb4d153 100644 (file)
@@ -81,4 +81,4 @@ named_log_setunmatchedcategory(isc_logconfig_t *lcfg);
  */
 
 void
-named_log_shutdown(void);
+named_log_shutdown(void) __attribute__((__deprecated__));
index d25382d89ac2f08c3ac2592e9ce7ab816c44506d..41102c1c9f39ee52c4c2e800c67671b23a8223b3 100644 (file)
@@ -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 */
 }
index 7a6c837c5f46aa60a87db81c28029d7c994401fd..e3528276579eb3973c9e80aad420a8c302e1f41e 100644 (file)
@@ -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,
index 5e06051cf67f0b624600bb5163d5d7e08379791b..ac2b62f7f7894f40f302a9d933561d9a52e92a6c 100644 (file)
@@ -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);
index b11fbf47d2fadaabc459c617d4f026c5986fca0b..101eccdb71399c9df6a3be50e8826d6984639e29 100644 (file)
@@ -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);
 
index 6c1ddfc85c1bb7d4636f15979dc4f4fff763b9c2..f57ba407752965fee0dfc88f51d69f836597386f 100644 (file)
 #include <dns/name.h>
 #include <dns/types.h>
 
-#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);
        }
index d636f05978c345181ea9c3486e05660251e125e7..31ce067a9123bd7432151fb629a421a87a601603 100644 (file)
@@ -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);
index ad76fd7db87cce7e329cca41d045b9ce555a0845..c3b858683fa184b85d0076af0c79f3c97d5e8437 100644 (file)
@@ -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);
 }
index b5b14936c0f7affbd27fa396172f996fea571645..15876005857b969a8841f7a3ace8579eeddbf45d 100644 (file)
@@ -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);
index ce6c3816d0befae288d02eb33dbe289f0fbc7486..c047074acfbf5282447bc9b8d8622c4253163949 100644 (file)
@@ -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);
 }
index f186a9ed2ea400b6169b92940adefba2b72108d0..437aa8803396fb576293734031d9f728d5e66b4d 100644 (file)
@@ -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
 
index e5e62c8cd5864645314f9286680d3a40bf8db590..6d53fd2442525c8a394e624f5eab0fa9bb27c5b9 100644 (file)
@@ -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);
        }
index e2cd959dc87739809bfad829383ae5594703cfcc..97e0ac00cc585cfefbbdefb7c9e2591b148dc3d2 100644 (file)
@@ -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
index 6f583d763bcfa18f56388941df982c2f2df7b0af..6eed43ec06a8d7eab7c6141473396542b3eac886 100644 (file)
@@ -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;
-}
index 119772eb11247783e7a89a6af2a7d9b43b9e750e..cc4c340517c2bd3183080d91fb53cb6c4a2cb35c 100644 (file)
@@ -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);
 /*%<
index 2e4298067aeb8ce880b6868977d9a5abadbca4e0..c03cc3e746357c3a879558ea78a16257dcf32aeb 100644 (file)
@@ -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);
-}
index 22979ef2723043309f592a592c51e26c0a5d2fa1..099331af2e13a7252c16f332232475ee1047f493 100644 (file)
@@ -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);
 }
index 3ade016a8e67e939cbb3270e5e1fe0c3f79efbb4..ba21175dfcc38650e00d4440fd64b5d8668dae57 100644 (file)
@@ -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.
- */
index 4a7ff20d0298d95f059f29a5c969deb553b20ee3..0adf034241b94c85cbe6a40d5d03919eb1727d91 100644 (file)
@@ -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;
-}
index 590b90b5a5da467ca2b72ea20fb55cc66f79df16..2a7451d90c78795f9107d1646572da9ea1bab2cd 100644 (file)
@@ -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);
index 30ec498f56f34d68222af1b6ac7f857205307595..b6603dddc08e2a41720e04084548ccd37e283d22 100644 (file)
@@ -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
index 8bc911cf23cc5a43d50fade0ee733abda6a3885b..d093e70e3c0904fe8c6dbc68ffa8445392659c62 100644 (file)
@@ -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)
index baba26dd6d4b634b7cd17daf3cc2ae29b3b4c46f..9bbd0ddd337f404c4b8334f45d99513aa9313d5a 100644 (file)
@@ -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)