From e02c696ea586f8dcc7c6145cc0f143f887960cd4 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Wed, 1 Mar 2000 00:40:54 +0000 Subject: [PATCH] checkpoint: restructured logging configuration code to enable the default logging configuration to be defined in one place --- bin/named/include/named/log.h | 3 +++ bin/named/include/named/logconf.h | 2 +- bin/named/log.c | 22 ++++++++++++++++++---- bin/named/logconf.c | 7 +------ bin/named/server.c | 22 ++++++++++------------ 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/bin/named/include/named/log.h b/bin/named/include/named/log.h index c9a7bb72e5..dc0d5c02b6 100644 --- a/bin/named/include/named/log.h +++ b/bin/named/include/named/log.h @@ -47,6 +47,9 @@ isc_result_t ns_log_init(void); +isc_result_t +ns_log_setdefaults(isc_logconfig_t *lcfg); + void ns_log_shutdown(void); diff --git a/bin/named/include/named/logconf.h b/bin/named/include/named/logconf.h index f0977291f6..7721991f09 100644 --- a/bin/named/include/named/logconf.h +++ b/bin/named/include/named/logconf.h @@ -23,7 +23,7 @@ #include isc_result_t -ns_logconfig_fromconf(isc_log_t *lctx, dns_c_logginglist_t *clog, isc_logconfig_t **lctxp); +ns_log_configure(isc_logconfig_t *lctx, dns_c_logginglist_t *clog); /* * Construct a new isc_logconfig_t object for use with the logging context 'lctx', * configuring it according to the named.conf configuration data in 'clog'. diff --git a/bin/named/log.c b/bin/named/log.c index ca45131a87..38a02c2d7b 100644 --- a/bin/named/log.c +++ b/bin/named/log.c @@ -61,8 +61,6 @@ static isc_logmodule_t modules[] = { isc_result_t ns_log_init(void) { isc_result_t result; - isc_logdestination_t destination; - unsigned int flags; isc_logconfig_t *lcfg; ns_g_categories = categories; @@ -84,6 +82,24 @@ ns_log_init(void) { isc_log_registermodules(ns_g_lctx, ns_g_modules); dns_log_init(ns_g_lctx); + result = ns_log_setdefaults(lcfg); + if (result != ISC_R_SUCCESS) + goto cleanup; + + return (ISC_R_SUCCESS); + + cleanup: + isc_log_destroy(&ns_g_lctx); + + return (result); +} + +isc_result_t +ns_log_setdefaults(isc_logconfig_t *lcfg) { + isc_result_t result; + isc_logdestination_t destination; + unsigned int flags; + /* * Create and install the default channel. */ @@ -120,8 +136,6 @@ ns_log_init(void) { return (ISC_R_SUCCESS); cleanup: - isc_log_destroy(&ns_g_lctx); - return (result); } diff --git a/bin/named/logconf.c b/bin/named/logconf.c index b29f8166e5..f7db629d91 100644 --- a/bin/named/logconf.c +++ b/bin/named/logconf.c @@ -163,16 +163,12 @@ channel_fromconf(dns_c_logchan_t *cchan, isc_logconfig_t *lctx) } isc_result_t -ns_logconfig_fromconf(isc_log_t *lctx, dns_c_logginglist_t *clog, - isc_logconfig_t **lcctxp) +ns_log_configure(isc_logconfig_t *lcctx, dns_c_logginglist_t *clog) { isc_result_t result; dns_c_logchan_t *cchan; dns_c_logcat_t *ccat; - isc_logconfig_t *lcctx = NULL; - CHECK(isc_logconfig_create(lctx, &lcctx)); - for (cchan = ISC_LIST_HEAD(clog->channels); cchan != NULL; cchan = ISC_LIST_NEXT(cchan, next)) @@ -187,7 +183,6 @@ ns_logconfig_fromconf(isc_log_t *lctx, dns_c_logginglist_t *clog, CHECK(category_fromconf(ccat, lcctx)); } - *lcctxp = lcctx; return (ISC_R_SUCCESS); cleanup: diff --git a/bin/named/server.c b/bin/named/server.c index eb5b5e70e6..bd9205f0db 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -938,18 +938,16 @@ load_configuration(const char *filename, ns_server_t *server, dns_c_logginglist_t *clog = NULL; isc_logconfig_t *logc = NULL; - /* - * dns_c_ctx_getlogging() succeeds even if there - * is no logging statement in named.conf; - * in that case it returns the default configuration - * that was set up in logging_init(). Therefore, we - * do not need to provide any defaults of our own here. - */ - CHECKM(dns_c_ctx_getlogging(configctx, &clog), - "getting logging configuration"); - - CHECKM(ns_logconfig_fromconf(ns_g_lctx, clog, &logc), - "setting up logging configuration"); + CHECKM(isc_logconfig_create(ns_g_lctx, &logc), + "creating new logging configuration"); + CHECKM(ns_log_setdefaults(logc), + "setting up default logging defaults"); + + (void) dns_c_ctx_getlogging(configctx, &clog); + if (clog != NULL) { + CHECKM(ns_log_configure(logc, clog), + "configuring logging"); + } result = isc_logconfig_use(ns_g_lctx, logc); if (result != ISC_R_SUCCESS) {