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().
This commit is contained in:
Ondřej Surý
2024-08-13 15:52:51 +02:00
parent a8a689531f
commit b2dda86254
29 changed files with 60 additions and 234 deletions

View 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)