}
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;
cfg_parser_destroy(&parser);
}
- if (logc != NULL) {
- isc_log_destroy(&logc);
- }
-
if (mctx != NULL) {
isc_mem_destroy(&mctx);
}
fprintf(errout, "OK\n");
}
destroy();
- if (lctx != NULL) {
- isc_log_destroy(&lctx);
- }
isc_mem_destroy(&mctx);
return ((result == ISC_R_SUCCESS) ? 0 : 1);
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;
dns_master_styledestroy(&style, mctx);
}
- isc_log_destroy(&lctx);
-
isc_managers_destroy(&mctx, &loopmgr, &netmgr);
return (0);
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);
isc_buffer_free(&namebuf);
}
- debug("Removing log context");
- isc_log_destroy(&lctx);
-
debug("Destroy memory");
if (memdebugging != 0) {
isc_mem_stats(mctx, stderr);
}
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;
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);
/*
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
*/
void
-named_log_shutdown(void);
+named_log_shutdown(void) __attribute__((__deprecated__));
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;
/*
* 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 {
}
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);
}
void
named_log_shutdown(void) {
- isc_log_destroy(&named_g_lctx);
- isc_log_setcontext(NULL);
- dns_log_setcontext(NULL);
+ /* no-op */
}
}
}
- 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,
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");
}
#endif /* ifdef HAVE_GSSAPI */
- ddebug("Removing log context");
- isc_log_destroy(&glctx);
-
ddebug("Destroying memory context");
if (memdebugging) {
isc_mem_stats(gmctx, stderr);
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;
isccc_ccmsg_invalidate(&rndc_ccmsg);
- isc_log_destroy(&log);
- isc_log_setcontext(NULL);
-
cfg_obj_destroy(pctx, &config);
cfg_parser_destroy(&pctx);
#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;
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;
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) {
dns_db_detach(&olddb);
}
- if (lctx != NULL) {
- isc_log_destroy(&lctx);
- }
if (mctx != NULL) {
isc_mem_destroy(&mctx);
}
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;
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(
isc_loopmgr_run(loopmgr);
- isc_log_destroy(&lctx);
-
isc_managers_destroy(&mctx, &loopmgr, &netmgr);
return (0);
}
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;
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);
}
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;
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));
isc_loopmgr_run(loopmgr);
- isc_log_destroy(&lctx);
-
query = ISC_LIST_HEAD(queries);
while (query != NULL) {
struct query *next = ISC_LIST_NEXT(query, link);
* 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;
fprintf(stderr, "%s\n", isc_result_totext(result));
}
}
- isc_log_destroy(&lctx);
isc_mem_detach(&mctx);
return (result != ISC_R_SUCCESS ? 1 : 0);
}
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
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;
cfg_parser_destroy(&pctx);
}
- isc_log_destroy(&lctx);
if (memstats) {
isc_mem_stats(mctx, stderr);
}
* 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
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;
-}
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);
/*%<
*\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.
*
* 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
*\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);
/*%<
*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);
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));
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);
-}
void
cfg_log_init(isc_log_t *lctx) {
- REQUIRE(lctx != NULL);
-
isc_log_registercategories(lctx, cfg_categories);
isc_log_registermodules(lctx, cfg_modules);
}
*\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.
- */
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;
-}
}
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;
isc_mem_create(&mctx);
isc_mem_setdestroycheck(mctx, true);
- init_logging(mctx);
+ init_logging();
init_items(mctx);
isc_loopmgr_create(mctx, nloops, &loopmgr);
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);
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;
isc_loopmgr_run(loopmgr);
rcu_barrier();
isc_loopmgr_destroy(&loopmgr);
- isc_log_destroy(&dns_lctx);
}
ISC_TEST_LIST_START
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;
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;
ISC_TEST_LIST_END
-ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group)
+ISC_TEST_MAIN_CUSTOM(setup_test_group, NULL)
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;
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) {
ISC_TEST_LIST_END
-ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group)
+ISC_TEST_MAIN_CUSTOM(setup_test_group, NULL)