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

@@ -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);

View 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

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

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)