2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00:00

Refactor the isc_log API so it cannot fail on memory failures

The isc_mem API now crashes on memory allocation failure, and this is
the next commit in series to cleanup the code that could fail before,
but cannot fail now, e.g. isc_result_t return type has been changed to
void for the isc_log API functions that could only return ISC_R_SUCCESS.
This commit is contained in:
Mark Andrews 2020-03-18 14:17:55 +11:00 committed by Ondřej Surý
parent e6deefd03f
commit 0b793166d0
35 changed files with 217 additions and 399 deletions

View File

@ -553,7 +553,7 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
isc_log_t *log = NULL; isc_log_t *log = NULL;
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); isc_log_create(mctx, &log, &logconfig);
isc_log_registercategories(log, categories); isc_log_registercategories(log, categories);
isc_log_setcontext(log); isc_log_setcontext(log);
dns_log_init(log); dns_log_init(log);
@ -565,9 +565,9 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination, 0);
&destination, 0) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) == RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);

View File

@ -271,11 +271,7 @@ setup_logging(FILE *errout) {
isc_logdestination_t destination; isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
result = isc_log_create(mctx, &lctx, &logconfig); isc_log_create(mctx, &lctx, &logconfig);
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up logging");
}
isc_log_registercategories(lctx, categories); isc_log_registercategories(lctx, categories);
isc_log_registermodules(lctx, modules); isc_log_registermodules(lctx, modules);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
@ -287,20 +283,12 @@ setup_logging(FILE *errout) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTPREFIX);
ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'stderr'");
}
isc_log_setdebuglevel(lctx, loglevel); isc_log_setdebuglevel(lctx, loglevel);
isc_log_settag(logconfig, ";; ");
result = isc_log_settag(logconfig, ";; ");
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set log tag");
}
result = isc_log_usechannel(logconfig, "stderr", result = isc_log_usechannel(logconfig, "stderr",
ISC_LOGCATEGORY_DEFAULT, NULL); ISC_LOGCATEGORY_DEFAULT, NULL);
@ -309,12 +297,9 @@ setup_logging(FILE *errout) {
} }
if (resolve_trace && loglevel < 1) { if (resolve_trace && loglevel < 1) {
result = isc_log_createchannel( isc_log_createchannel(logconfig, "resolver", ISC_LOG_TOFILEDESC,
logconfig, "resolver", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(1), &destination,
ISC_LOG_DEBUG(1), &destination, ISC_LOG_PRINTPREFIX); ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'resolver'");
}
result = isc_log_usechannel(logconfig, "resolver", result = isc_log_usechannel(logconfig, "resolver",
DNS_LOGCATEGORY_RESOLVER, DNS_LOGCATEGORY_RESOLVER,
@ -325,12 +310,9 @@ setup_logging(FILE *errout) {
} }
if (validator_trace && loglevel < 3) { if (validator_trace && loglevel < 3) {
result = isc_log_createchannel( isc_log_createchannel(logconfig, "validator",
logconfig, "validator", ISC_LOG_TOFILEDESC, ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(3),
ISC_LOG_DEBUG(3), &destination, ISC_LOG_PRINTPREFIX); &destination, ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'validator'");
}
result = isc_log_usechannel(logconfig, "validator", result = isc_log_usechannel(logconfig, "validator",
DNS_LOGCATEGORY_DNSSEC, DNS_LOGCATEGORY_DNSSEC,
@ -341,12 +323,9 @@ setup_logging(FILE *errout) {
} }
if (message_trace && loglevel < 10) { if (message_trace && loglevel < 10) {
result = isc_log_createchannel( isc_log_createchannel(logconfig, "messages", ISC_LOG_TOFILEDESC,
logconfig, "messages", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(10), &destination,
ISC_LOG_DEBUG(10), &destination, ISC_LOG_PRINTPREFIX); ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'messages'");
}
result = isc_log_usechannel(logconfig, "messages", result = isc_log_usechannel(logconfig, "messages",
DNS_LOGCATEGORY_RESOLVER, DNS_LOGCATEGORY_RESOLVER,

View File

@ -1394,9 +1394,7 @@ setup_libs(void) {
isc_mem_create(&mctx); isc_mem_create(&mctx);
isc_mem_setname(mctx, "dig", NULL); isc_mem_setname(mctx, "dig", NULL);
result = isc_log_create(mctx, &lctx, &logconfig); isc_log_create(mctx, &lctx, &logconfig);
check_result(result, "isc_log_create");
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
dns_log_setcontext(lctx); dns_log_setcontext(lctx);

View File

@ -128,7 +128,6 @@ sig_format(dns_rdata_rrsig_t *sig, char *cp, unsigned int size) {
void void
setup_logging(isc_mem_t *mctx, isc_log_t **logp) { setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
isc_result_t result;
isc_logdestination_t destination; isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
isc_log_t *log = NULL; isc_log_t *log = NULL;
@ -153,12 +152,11 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
break; break;
} }
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); isc_log_create(mctx, &log, &logconfig);
isc_log_setcontext(log); isc_log_setcontext(log);
dns_log_init(log); dns_log_init(log);
dns_log_setcontext(log); dns_log_setcontext(log);
isc_log_settag(logconfig, program);
RUNTIME_CHECK(isc_log_settag(logconfig, program) == ISC_R_SUCCESS);
/* /*
* Set up a channel similar to default_stderr except: * Set up a channel similar to default_stderr except:
@ -170,10 +168,9 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
level, &destination, &destination,
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL); ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
check_result(result, "isc_log_createchannel()");
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) == RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);

View File

@ -45,7 +45,7 @@ named_log_init(bool safe);
* as root. * as root.
*/ */
isc_result_t void
named_log_setdefaultchannels(isc_logconfig_t *lcfg); named_log_setdefaultchannels(isc_logconfig_t *lcfg);
/*% /*%
* Set up logging channels according to the named defaults, which * Set up logging channels according to the named defaults, which
@ -53,7 +53,7 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg);
* this just means setting up default_debug. * this just means setting up default_debug.
*/ */
isc_result_t void
named_log_setsafechannels(isc_logconfig_t *lcfg); named_log_setsafechannels(isc_logconfig_t *lcfg);
/*% /*%
* Like named_log_setdefaultchannels(), but omits any logging to files. * Like named_log_setdefaultchannels(), but omits any logging to files.

View File

@ -53,10 +53,7 @@ named_log_init(bool safe) {
/* /*
* Setup a logging context. * Setup a logging context.
*/ */
result = isc_log_create(named_g_mctx, &named_g_lctx, &lcfg); isc_log_create(named_g_mctx, &named_g_lctx, &lcfg);
if (result != ISC_R_SUCCESS) {
return (result);
}
/* /*
* named-checktool.c:setup_logging() needs to be kept in sync. * named-checktool.c:setup_logging() needs to be kept in sync.
@ -71,12 +68,9 @@ named_log_init(bool safe) {
ns_log_setcontext(named_g_lctx); ns_log_setcontext(named_g_lctx);
if (safe) { if (safe) {
result = named_log_setsafechannels(lcfg); named_log_setsafechannels(lcfg);
} else { } else {
result = named_log_setdefaultchannels(lcfg); named_log_setdefaultchannels(lcfg);
}
if (result != ISC_R_SUCCESS) {
goto cleanup;
} }
result = named_log_setdefaultcategory(lcfg); result = named_log_setdefaultcategory(lcfg);
@ -94,9 +88,8 @@ cleanup:
return (result); return (result);
} }
isc_result_t void
named_log_setdefaultchannels(isc_logconfig_t *lcfg) { named_log_setdefaultchannels(isc_logconfig_t *lcfg) {
isc_result_t result;
isc_logdestination_t destination; isc_logdestination_t destination;
/* /*
@ -109,12 +102,9 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg) {
destination.file.name = "named.run"; destination.file.name = "named.run";
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel( isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILE,
lcfg, "default_debug", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination,
&destination, ISC_LOG_PRINTTIME | ISC_LOG_DEBUGONLY); ISC_LOG_PRINTTIME | ISC_LOG_DEBUGONLY);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
} }
if (named_g_logfile != NULL) { if (named_g_logfile != NULL) {
@ -122,48 +112,32 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg) {
destination.file.name = named_g_logfile; destination.file.name = named_g_logfile;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel( isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE,
lcfg, "default_logfile", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME |
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY | ISC_LOG_PRINTCATEGORY |
ISC_LOG_PRINTLEVEL); ISC_LOG_PRINTLEVEL);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
} }
#if ISC_FACILITY != LOG_DAEMON #if ISC_FACILITY != LOG_DAEMON
destination.facility = ISC_FACILITY; destination.facility = ISC_FACILITY;
result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG,
ISC_LOG_INFO, &destination, 0); ISC_LOG_INFO, &destination, 0);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
#endif /* if ISC_FACILITY != LOG_DAEMON */ #endif /* if ISC_FACILITY != LOG_DAEMON */
/* /*
* Set the initial debug level. * Set the initial debug level.
*/ */
isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel);
result = ISC_R_SUCCESS;
cleanup:
return (result);
} }
isc_result_t void
named_log_setsafechannels(isc_logconfig_t *lcfg) { named_log_setsafechannels(isc_logconfig_t *lcfg) {
isc_result_t result;
isc_logdestination_t destination; isc_logdestination_t destination;
if (!named_g_logstderr) { if (!named_g_logstderr) {
result = isc_log_createchannel(lcfg, "default_debug", isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TONULL,
ISC_LOG_TONULL, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, NULL, 0);
NULL, 0);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
/* /*
* Setting the debug level to zero should get the output * Setting the debug level to zero should get the output
@ -179,29 +153,18 @@ named_log_setsafechannels(isc_logconfig_t *lcfg) {
destination.file.name = named_g_logfile; destination.file.name = named_g_logfile;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel( isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE,
lcfg, "default_logfile", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME |
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY | ISC_LOG_PRINTCATEGORY |
ISC_LOG_PRINTLEVEL); ISC_LOG_PRINTLEVEL);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
} }
#if ISC_FACILITY != LOG_DAEMON #if ISC_FACILITY != LOG_DAEMON
destination.facility = ISC_FACILITY; destination.facility = ISC_FACILITY;
result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG,
ISC_LOG_INFO, &destination, 0); ISC_LOG_INFO, &destination, 0);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
#endif /* if ISC_FACILITY != LOG_DAEMON */ #endif /* if ISC_FACILITY != LOG_DAEMON */
result = ISC_R_SUCCESS;
cleanup:
return (result);
} }
isc_result_t isc_result_t

View File

@ -92,7 +92,7 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
*/ */
static isc_result_t static isc_result_t
channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig) { channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig) {
isc_result_t result; isc_result_t result = ISC_R_SUCCESS;
isc_logdestination_t dest; isc_logdestination_t dest;
unsigned int type; unsigned int type;
unsigned int flags = 0; unsigned int flags = 0;
@ -271,14 +271,12 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig) {
} }
} }
if (logconfig == NULL) { if (logconfig != NULL) {
result = ISC_R_SUCCESS; isc_log_createchannel(logconfig, channelname, type, level,
} else { &dest, flags);
result = isc_log_createchannel(logconfig, channelname, type,
level, &dest, flags);
} }
if (result == ISC_R_SUCCESS && type == ISC_LOG_TOFILE) { if (type == ISC_LOG_TOFILE) {
FILE *fp; FILE *fp;
/* /*
@ -333,7 +331,7 @@ named_logconfig(isc_logconfig_t *logconfig, const cfg_obj_t *logstmt) {
const cfg_obj_t *catname; const cfg_obj_t *catname;
if (logconfig != NULL) { if (logconfig != NULL) {
CHECK(named_log_setdefaultchannels(logconfig)); named_log_setdefaultchannels(logconfig);
} }
(void)cfg_map_get(logstmt, "channel", &channels); (void)cfg_map_get(logstmt, "channel", &channels);

View File

@ -9110,8 +9110,7 @@ load_configuration(const char *filename, named_server_t *server,
} else { } else {
const cfg_obj_t *logobj = NULL; const cfg_obj_t *logobj = NULL;
CHECKM(isc_logconfig_create(named_g_lctx, &logc), isc_logconfig_create(named_g_lctx, &logc);
"creating new logging configuration");
logobj = NULL; logobj = NULL;
(void)cfg_map_get(config, "logging", &logobj); (void)cfg_map_get(config, "logging", &logobj);
@ -9119,16 +9118,14 @@ load_configuration(const char *filename, named_server_t *server,
CHECKM(named_logconfig(logc, logobj), "configuring " CHECKM(named_logconfig(logc, logobj), "configuring "
"logging"); "logging");
} else { } else {
CHECKM(named_log_setdefaultchannels(logc), named_log_setdefaultchannels(logc);
"setting up default logging channels");
CHECKM(named_log_setunmatchedcategory(logc), CHECKM(named_log_setunmatchedcategory(logc),
"setting up default 'category unmatched'"); "setting up default 'category unmatched'");
CHECKM(named_log_setdefaultcategory(logc), CHECKM(named_log_setdefaultcategory(logc),
"setting up default 'category default'"); "setting up default 'category default'");
} }
CHECKM(isc_logconfig_use(named_g_lctx, logc), isc_logconfig_use(named_g_lctx, logc);
"installing logging configuration");
logc = NULL; logc = NULL;
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,

View File

@ -812,9 +812,7 @@ setup_system(void) {
dns_result_register(); dns_result_register();
result = isc_log_create(gmctx, &glctx, &logconfig); isc_log_create(gmctx, &glctx, &logconfig);
check_result(result, "isc_log_create");
isc_log_setcontext(glctx); isc_log_setcontext(glctx);
dns_log_init(glctx); dns_log_init(glctx);
dns_log_setcontext(glctx); dns_log_setcontext(glctx);

View File

@ -985,18 +985,16 @@ main(int argc, char **argv) {
isc_taskmgr_create(rndc_mctx, 1, 0, NULL, &taskmgr)); isc_taskmgr_create(rndc_mctx, 1, 0, NULL, &taskmgr));
DO("create task", isc_task_create(taskmgr, 0, &task)); DO("create task", isc_task_create(taskmgr, 0, &task));
DO("create logging context", isc_log_create(rndc_mctx, &log, &logconfig);
isc_log_create(rndc_mctx, &log, &logconfig));
isc_log_setcontext(log); isc_log_setcontext(log);
DO("setting log tag", isc_log_settag(logconfig, progname)); isc_log_settag(logconfig, progname);
logdest.file.stream = stderr; logdest.file.stream = stderr;
logdest.file.name = NULL; logdest.file.name = NULL;
logdest.file.versions = ISC_LOG_ROLLNEVER; logdest.file.versions = ISC_LOG_ROLLNEVER;
logdest.file.maximum_size = 0; logdest.file.maximum_size = 0;
DO("creating log channel", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO, &logdest,
ISC_LOG_INFO, &logdest, ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL));
DO("enabling log channel", DO("enabling log channel",
isc_log_usechannel(logconfig, "stderr", NULL, NULL)); isc_log_usechannel(logconfig, "stderr", NULL, NULL));

View File

@ -72,8 +72,7 @@ main(int argc, char **argv) {
isc_mem_create(&mctx); isc_mem_create(&mctx);
result = isc_log_create(mctx, &lctx, &lcfg); isc_log_create(mctx, &lctx, &lcfg);
check_result(result, "isc_log_create()");
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
/* /*
@ -83,10 +82,9 @@ main(int argc, char **argv) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
ISC_LOG_PRINTTIME);
check_result(result, "isc_log_createchannel()");
result = isc_log_usechannel(lcfg, "_default", NULL, NULL); result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
check_result(result, "isc_log_usechannel()"); check_result(result, "isc_log_usechannel()");

View File

@ -100,7 +100,7 @@ main(int argc, char **argv) {
CHECK(dst_lib_init(mctx, NULL)); CHECK(dst_lib_init(mctx, NULL));
dst_active = true; dst_active = true;
CHECK(isc_log_create(mctx, &lctx, &logconfig)); isc_log_create(mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories); isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
@ -110,8 +110,9 @@ main(int argc, char **argv) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0)); ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
dns_result_register(); dns_result_register();

View File

@ -297,8 +297,7 @@ main(int argc, char **argv) {
isc_mempool_create(mctx, sizeof(client_t), &cmp); isc_mempool_create(mctx, sizeof(client_t), &cmp);
isc_mempool_setname(cmp, "adb test clients"); isc_mempool_setname(cmp, "adb test clients");
result = isc_log_create(mctx, &lctx, &lcfg); isc_log_create(mctx, &lctx, &lcfg);
check_result(result, "isc_log_create()");
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
dns_log_setcontext(lctx); dns_log_setcontext(lctx);
@ -310,10 +309,9 @@ main(int argc, char **argv) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
ISC_LOG_PRINTTIME);
check_result(result, "isc_log_createchannel()");
result = isc_log_usechannel(lcfg, "_default", NULL, NULL); result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
check_result(result, "isc_log_usechannel()"); check_result(result, "isc_log_usechannel()");

View File

@ -56,7 +56,7 @@ log_init(void) {
/* /*
* Setup a logging context. * Setup a logging context.
*/ */
RUNTIME_CHECK(isc_log_create(mctx, &lctx, &lcfg) == ISC_R_SUCCESS); isc_log_create(mctx, &lctx, &lcfg);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
dns_log_setcontext(lctx); dns_log_setcontext(lctx);
@ -69,10 +69,9 @@ log_init(void) {
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
flags = ISC_LOG_PRINTTIME; flags = ISC_LOG_PRINTTIME;
RUNTIME_CHECK(isc_log_createchannel(lcfg, "_default", isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination, flags);
&destination,
flags) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) == RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);
isc_log_setdebuglevel(lctx, level); isc_log_setdebuglevel(lctx, level);

View File

@ -402,8 +402,7 @@ main(int argc, char *argv[]) {
DNS_DBFIND_VALIDATEGLUE); DNS_DBFIND_VALIDATEGLUE);
break; break;
case 'l': case 'l':
RUNTIME_CHECK(isc_log_create(mctx, &lctx, NULL) == isc_log_create(mctx, &lctx, NULL);
ISC_R_SUCCESS);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
dns_log_setcontext(lctx); dns_log_setcontext(lctx);

View File

@ -458,7 +458,7 @@ main(int argc, char *argv[]) {
mctx = NULL; mctx = NULL;
isc_mem_create(&mctx); isc_mem_create(&mctx);
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_create(mctx, &lctx, &lcfg);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
dns_log_setcontext(lctx); dns_log_setcontext(lctx);
@ -470,9 +470,9 @@ main(int argc, char *argv[]) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
RUNCHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
ISC_LOG_PRINTTIME));
RUNCHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL)); RUNCHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL));
isc_log_setdebuglevel(lctx, 9); isc_log_setdebuglevel(lctx, 9);

View File

@ -112,9 +112,9 @@ main(int argc, char **argv) {
lcfg = NULL; lcfg = NULL;
isc_mem_create(&mctx); isc_mem_create(&mctx);
CHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_create(mctx, &lctx, &lcfg);
CHECK(isc_log_settag(lcfg, progname)); isc_log_settag(lcfg, progname);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
@ -147,20 +147,20 @@ main(int argc, char **argv) {
destination.file.maximum_size = 1; destination.file.maximum_size = 1;
destination.file.versions = file_versions; destination.file.versions = file_versions;
CHECK(isc_log_createchannel( isc_log_createchannel(
lcfg, "file_test", ISC_LOG_TOFILE, ISC_LOG_INFO, &destination, lcfg, "file_test", ISC_LOG_TOFILE, ISC_LOG_INFO, &destination,
ISC_LOG_PRINTTIME | ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL | ISC_LOG_PRINTTIME | ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL |
ISC_LOG_PRINTCATEGORY | ISC_LOG_PRINTMODULE)); ISC_LOG_PRINTCATEGORY | ISC_LOG_PRINTMODULE);
/* /*
* Create a dynamic debugging channel to a file descriptor. * Create a dynamic debugging channel to a file descriptor.
*/ */
destination.file.stream = stderr; destination.file.stream = stderr;
CHECK(isc_log_createchannel(lcfg, "debug_test", ISC_LOG_TOFILEDESC, isc_log_createchannel(lcfg, "debug_test", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, ISC_LOG_DYNAMIC, &destination,
ISC_LOG_PRINTTIME | ISC_LOG_PRINTLEVEL | ISC_LOG_PRINTTIME | ISC_LOG_PRINTLEVEL |
ISC_LOG_DEBUGONLY)); ISC_LOG_DEBUGONLY);
/* /*
* Test the usability of the four predefined logging channels. * Test the usability of the four predefined logging channels.

View File

@ -236,7 +236,7 @@ main(int argc, char *argv[]) {
socketmgr = NULL; socketmgr = NULL;
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_create(mctx, &lctx, &logconfig) == ISC_R_SUCCESS); isc_log_create(mctx, &lctx, &logconfig);
s = NULL; s = NULL;
RUNTIME_CHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp, RUNTIME_CHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp,

View File

@ -274,7 +274,7 @@ main(int argc, char *argv[]) {
lctx = NULL; lctx = NULL;
lcfg = NULL; lcfg = NULL;
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_create(mctx, &lctx, &lcfg);
RUNCHECK(dst_lib_init(mctx, NULL)); RUNCHECK(dst_lib_init(mctx, NULL));

View File

@ -107,19 +107,20 @@ main(int argc, char **argv) {
isc_mem_create(&mctx); isc_mem_create(&mctx);
CHECK(dst_lib_init(mctx, NULL), "dst_lib_init()"); CHECK(dst_lib_init(mctx, NULL), "dst_lib_init()");
CHECK(isc_log_create(mctx, &log_, &logconfig), "isc_log_create()"); isc_log_create(mctx, &log_, &logconfig);
isc_log_setcontext(log_); isc_log_setcontext(log_);
dns_log_init(log_); dns_log_init(log_);
dns_log_setcontext(log_); dns_log_setcontext(log_);
CHECK(isc_log_settag(logconfig, "bigkey"), "isc_log_settag()"); isc_log_settag(logconfig, "bigkey");
destination.file.stream = stderr; destination.file.stream = stderr;
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
level, &destination, &destination,
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL), ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
"isc_log_createchannel()");
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_" CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_"
"usechannel(" "usechannel("
")"); ")");

View File

@ -232,7 +232,7 @@ main(int argc, char *argv[]) {
log = NULL; log = NULL;
logconfig = NULL; logconfig = NULL;
RUNCHECK(isc_log_create(mctx, &log, &logconfig)); isc_log_create(mctx, &log, &logconfig);
RUNCHECK(dst_lib_init(mctx, NULL)); RUNCHECK(dst_lib_init(mctx, NULL));

View File

@ -172,7 +172,7 @@ main(int argc, char **argv) {
log = NULL; log = NULL;
logconfig = NULL; logconfig = NULL;
RUNCHECK(isc_log_create(mctx, &log, &logconfig)); isc_log_create(mctx, &log, &logconfig);
RUNCHECK(dst_lib_init(mctx, NULL)); RUNCHECK(dst_lib_init(mctx, NULL));

View File

@ -2086,7 +2086,7 @@ main(int argc, char *argv[]) {
lctx = NULL; lctx = NULL;
lcfg = NULL; lcfg = NULL;
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_create(mctx, &lctx, &lcfg);
RUNCHECK(dst_lib_init(mctx, NULL)); RUNCHECK(dst_lib_init(mctx, NULL));
isc_nonce_buf(cookie_secret, sizeof(cookie_secret)); isc_nonce_buf(cookie_secret, sizeof(cookie_secret));

View File

@ -32,7 +32,7 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
isc_log_t *log = NULL; isc_log_t *log = NULL;
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); isc_log_create(mctx, &log, &logconfig);
isc_log_setcontext(log); isc_log_setcontext(log);
dns_log_init(log); dns_log_init(log);
dns_log_setcontext(log); dns_log_setcontext(log);
@ -41,9 +41,9 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination, 0);
&destination, 0) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) == RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);

View File

@ -62,8 +62,7 @@ int ctx_init(void) {
isc_mem_create(&ctx.mem); isc_mem_create(&ctx.mem);
if (isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg) != ISC_R_SUCCESS) isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg);
goto done;
isc_log_setcontext(ctx.log); isc_log_setcontext(ctx.log);
dns_log_init(ctx.log); dns_log_init(ctx.log);

View File

@ -283,8 +283,7 @@ rudimentary initialization of both.
isc_logconfig_t *lcfg; isc_logconfig_t *lcfg;
isc_mem_create(&mctx); isc_mem_create(&mctx);
if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) isc_log_create(mctx, &lctx, &lcfg);
oops_it_didnt_work();
3) Initialize any additional libraries. The convention for the name of 3) Initialize any additional libraries. The convention for the name of
the initialization function is {library}_log_init, with just a pointer the initialization function is {library}_log_init, with just a pointer
@ -374,7 +373,7 @@ configuration, first create the new configuration with:
and then configure newlcfg with isc_log_createchannel() and and then configure newlcfg with isc_log_createchannel() and
isc_log_usechannel(). When it is all ready: isc_log_usechannel(). When it is all ready:
result = isc_logconfig_use(lctx, newlcfg); isc_logconfig_use(lctx, newlcfg);
If the new configuration is successfully installed, then the old one If the new configuration is successfully installed, then the old one
will be destroyed, freeing all memory it used. will be destroyed, freeing all memory it used.

View File

@ -1066,9 +1066,7 @@ the following steps need to be taken to initialize it.
isc_logconfig_t *lcfg; isc_logconfig_t *lcfg;
isc_mem_create(&mctx); isc_mem_create(&mctx);
if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) { isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS);
oops_it_didnt_work();
}
1. Initialize any additional libraries. The convention for the name of 1. Initialize any additional libraries. The convention for the name of
the initialization function is `{library}_log_init()`, with a pointer to the initialization function is `{library}_log_init()`, with a pointer to
@ -1091,24 +1089,16 @@ the following steps need to be taken to initialize it.
destination.file.name = "/var/log/example"; destination.file.name = "/var/log/example";
destination.file.maximum_size = 0; /* No byte limit. */ destination.file.maximum_size = 0; /* No byte limit. */
destination.file.versions = ISC_LOG_ROLLNEVER; /* External rolling. */ destination.file.versions = ISC_LOG_ROLLNEVER; /* External rolling. */
result = isc_log_createchannel(lcfg, "sample1", ISC_LOG_TOFILE, isc_log_createchannel(lcfg, "sample1", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC,
ISC_LOG_DYNAMIC, &destination, &destination, ISC_LOG_PRINTTIME);
ISC_LOG_PRINTTIME);
if (result != ISC_R_SUCCESS)
oops_it_didnt_work();
destination.file.stream = stdout; destination.file.stream = stdout;
result = isc_log_createchannel(lcfg, "sample2", ISC_LOG_TOFILEDESC, isc_log_createchannel(lcfg, "sample2", ISC_LOG_TOFILEDESC,
ISC_LOG_INFO, &destination, ISC_LOG_INFO, &destination, ISC_LOG_PRINTTIME);
ISC_LOG_PRINTTIME);
if (result != ISC_R_SUCCESS)
oops_it_didnt_work();
destination.facility = LOG_ERR; destination.facility = LOG_ERR;
result = isc_log_createchannel(lcfg, "sample3", ISC_LOG_SYSLOG, isc_log_createchannel(lcfg, "sample3", ISC_LOG_SYSLOG, ISC_LOG_ERROR,
ISC_LOG_ERROR, &destination, 0); &destination, 0);
if (result != ISC_R_SUCCESS)
oops_it_didnt_work();
`ISC_LOG_DYNAMIC` is used to define a channel that wants any of the `ISC_LOG_DYNAMIC` is used to define a channel that wants any of the
messages up to the current debugging level of the program. messages up to the current debugging level of the program.

View File

@ -445,10 +445,7 @@ dns_client_create(dns_client_t **clientp, unsigned int options) {
goto cleanup; goto cleanup;
} }
#if 0 #if 0
result = isc_log_create(mctx, &lctx, &logconfig); isc_log_create(mctx, &lctx, &logconfig);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
dns_log_setcontext(lctx); dns_log_setcontext(lctx);

View File

@ -153,8 +153,7 @@ dns_test_begin(FILE *logfile, bool start_managers) {
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
INSIST(lctx == NULL); INSIST(lctx == NULL);
CHECK(isc_log_create(dt_mctx, &lctx, &logconfig)); isc_log_create(dt_mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories); isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
dns_log_init(lctx); dns_log_init(lctx);
@ -164,9 +163,8 @@ dns_test_begin(FILE *logfile, bool start_managers) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination, 0);
&destination, 0));
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
} }

View File

@ -183,7 +183,7 @@ LIBISC_EXTERNAL_DATA extern isc_logmodule_t isc_modules[];
ISC_LANG_BEGINDECLS ISC_LANG_BEGINDECLS
isc_result_t void
isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp); isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp);
/*%< /*%<
* Establish a new logging context, with default channels. * Establish a new logging context, with default channels.
@ -203,13 +203,9 @@ isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp);
*\li *lcfgp will point to a valid logging configuration if all of the *\li *lcfgp will point to a valid logging configuration if all of the
* necessary memory was allocated, or NULL otherwise. * necessary memory was allocated, or NULL otherwise.
*\li On failure, no additional memory is allocated. *\li On failure, no additional memory is allocated.
*
* Returns:
*\li #ISC_R_SUCCESS Success
*\li #ISC_R_NOMEMORY Resource limit: Out of memory
*/ */
isc_result_t void
isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp); isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp);
/*%< /*%<
* Create the data structure that holds all of the configurable information * Create the data structure that holds all of the configurable information
@ -249,13 +245,9 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp);
*\li *lcfgp will point to a valid logging context if all of the necessary *\li *lcfgp will point to a valid logging context if all of the necessary
* memory was allocated, or NULL otherwise. * memory was allocated, or NULL otherwise.
*\li On failure, no additional memory is allocated. *\li On failure, no additional memory is allocated.
*
* Returns:
*\li #ISC_R_SUCCESS Success
*\li #ISC_R_NOMEMORY Resource limit: Out of memory
*/ */
isc_result_t void
isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg); isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg);
/*%< /*%<
* Associate a new configuration with a logging context. * Associate a new configuration with a logging context.
@ -274,10 +266,6 @@ isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg);
* *
* Ensures: * Ensures:
*\li Future calls to isc_log_write will use the new configuration. *\li Future calls to isc_log_write will use the new configuration.
*
* Returns:
*\li #ISC_R_SUCCESS Success
*\li #ISC_R_NOMEMORY Resource limit: Out of memory
*/ */
void void
@ -388,7 +376,7 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]);
* used with isc_log_usechannel() and isc_log_write(). * used with isc_log_usechannel() and isc_log_write().
*/ */
isc_result_t void
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name, isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
unsigned int type, int level, unsigned int type, int level,
const isc_logdestination_t *destination, const isc_logdestination_t *destination,
@ -449,12 +437,6 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
* No additional memory is being used by the logging context. * No additional memory is being used by the logging context.
* Any channel that previously existed with the given name * Any channel that previously existed with the given name
* is not redefined. * is not redefined.
*
* Returns:
*\li #ISC_R_SUCCESS Success
*\li #ISC_R_NOMEMORY Resource limit: Out of memory
*\li #ISC_R_UNEXPECTED type was out of range and REQUIRE()
* was disabled.
*/ */
isc_result_t isc_result_t
@ -699,7 +681,7 @@ isc_log_getduplicateinterval(isc_logconfig_t *lcfg);
*\li The current duplicate filtering interval. *\li The current duplicate filtering interval.
*/ */
isc_result_t void
isc_log_settag(isc_logconfig_t *lcfg, const char *tag); isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
/*%< /*%<
* Set the program name or other identifier for #ISC_LOG_PRINTTAG. * Set the program name or other identifier for #ISC_LOG_PRINTTAG.
@ -718,10 +700,6 @@ isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
* #ISC_LOG_PRINTTAG channel flag to not print anything. If tag equals the * #ISC_LOG_PRINTTAG channel flag to not print anything. If tag equals the
* empty string, calls to isc_log_gettag will return NULL. * empty string, calls to isc_log_gettag will return NULL.
* *
* Returns:
*\li #ISC_R_SUCCESS Success
*\li #ISC_R_NOMEMORY Resource Limit: Out of memory
*
* XXXDCL when creating a new isc_logconfig_t, it might be nice if the tag * XXXDCL when creating a new isc_logconfig_t, it might be nice if the tag
* of the currently active isc_logconfig_t was inherited. this does not * of the currently active isc_logconfig_t was inherited. this does not
* currently happen. * currently happen.

View File

@ -196,11 +196,11 @@ LIBISC_EXTERNAL_DATA isc_log_t *isc_lctx = NULL;
/*! /*!
* Forward declarations. * Forward declarations.
*/ */
static isc_result_t static void
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
const isc_logmodule_t *module, isc_logchannel_t *channel); const isc_logmodule_t *module, isc_logchannel_t *channel);
static isc_result_t static void
sync_channellist(isc_logconfig_t *lcfg); sync_channellist(isc_logconfig_t *lcfg);
static isc_result_t static isc_result_t
@ -232,74 +232,55 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
/* /*
* Establish a new logging context, with default channels. * Establish a new logging context, with default channels.
*/ */
isc_result_t void
isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp) { isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp) {
isc_log_t *lctx; isc_log_t *lctx;
isc_logconfig_t *lcfg = NULL; isc_logconfig_t *lcfg = NULL;
isc_result_t result;
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(lctxp != NULL && *lctxp == NULL); REQUIRE(lctxp != NULL && *lctxp == NULL);
REQUIRE(lcfgp == NULL || *lcfgp == NULL); REQUIRE(lcfgp == NULL || *lcfgp == NULL);
lctx = isc_mem_get(mctx, sizeof(*lctx)); lctx = isc_mem_get(mctx, sizeof(*lctx));
if (lctx != NULL) { lctx->mctx = NULL;
lctx->mctx = NULL; isc_mem_attach(mctx, &lctx->mctx);
isc_mem_attach(mctx, &lctx->mctx); lctx->categories = NULL;
lctx->categories = NULL; lctx->category_count = 0;
lctx->category_count = 0; lctx->modules = NULL;
lctx->modules = NULL; lctx->module_count = 0;
lctx->module_count = 0; lctx->debug_level = 0;
lctx->debug_level = 0;
ISC_LIST_INIT(lctx->messages); ISC_LIST_INIT(lctx->messages);
isc_mutex_init(&lctx->lock); isc_mutex_init(&lctx->lock);
/* /*
* Normally setting the magic number is the last step done * Normally setting the magic number is the last step done
* in a creation function, but a valid log context is needed * in a creation function, but a valid log context is needed
* by isc_log_registercategories and isc_logconfig_create. * by isc_log_registercategories and isc_logconfig_create.
* If either fails, the lctx is destroyed and not returned * If either fails, the lctx is destroyed and not returned
* to the caller. * to the caller.
*/ */
lctx->magic = LCTX_MAGIC; lctx->magic = LCTX_MAGIC;
isc_log_registercategories(lctx, isc_categories); isc_log_registercategories(lctx, isc_categories);
isc_log_registermodules(lctx, isc_modules); isc_log_registermodules(lctx, isc_modules);
result = isc_logconfig_create(lctx, &lcfg); isc_logconfig_create(lctx, &lcfg);
} else {
result = ISC_R_NOMEMORY; sync_channellist(lcfg);
atomic_init(&lctx->logconfig, (uintptr_t)lcfg);
*lctxp = lctx;
if (lcfgp != NULL) {
*lcfgp = lcfg;
} }
if (result == ISC_R_SUCCESS) {
result = sync_channellist(lcfg);
}
if (result == ISC_R_SUCCESS) {
atomic_init(&lctx->logconfig, (uintptr_t)lcfg);
*lctxp = lctx;
if (lcfgp != NULL) {
*lcfgp = lcfg;
}
} else {
if (lcfg != NULL) {
isc_logconfig_destroy(&lcfg);
}
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
}
return (result);
} }
isc_result_t void
isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) { isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) {
isc_logconfig_t *lcfg; isc_logconfig_t *lcfg;
isc_logdestination_t destination; isc_logdestination_t destination;
isc_result_t result = ISC_R_SUCCESS;
int level = ISC_LOG_INFO; int level = ISC_LOG_INFO;
REQUIRE(lcfgp != NULL && *lcfgp == NULL); REQUIRE(lcfgp != NULL && *lcfgp == NULL);
@ -321,60 +302,42 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) {
* Create the default channels: * Create the default channels:
* default_syslog, default_stderr, default_debug and null. * default_syslog, default_stderr, default_debug and null.
*/ */
if (result == ISC_R_SUCCESS) { destination.facility = LOG_DAEMON;
destination.facility = LOG_DAEMON; isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, level,
result = isc_log_createchannel(lcfg, "default_syslog", &destination, 0);
ISC_LOG_TOSYSLOG, level,
&destination, 0);
}
if (result == ISC_R_SUCCESS) { destination.file.stream = stderr;
destination.file.stream = stderr; destination.file.name = NULL;
destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.suffix = isc_log_rollsuffix_increment;
destination.file.suffix = isc_log_rollsuffix_increment; destination.file.maximum_size = 0;
destination.file.maximum_size = 0; isc_log_createchannel(lcfg, "default_stderr", ISC_LOG_TOFILEDESC, level,
result = isc_log_createchannel(lcfg, "default_stderr", &destination, ISC_LOG_PRINTTIME);
ISC_LOG_TOFILEDESC, level,
&destination, ISC_LOG_PRINTTIME);
}
if (result == ISC_R_SUCCESS) { /*
/* * Set the default category's channel to default_stderr,
* Set the default category's channel to default_stderr, * which is at the head of the channels list because it was
* which is at the head of the channels list because it was * just created.
* just created. */
*/ default_channel.channel = ISC_LIST_HEAD(lcfg->channels);
default_channel.channel = ISC_LIST_HEAD(lcfg->channels);
destination.file.stream = stderr; destination.file.stream = stderr;
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.suffix = isc_log_rollsuffix_increment; destination.file.suffix = isc_log_rollsuffix_increment;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
result = isc_log_createchannel( isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILEDESC,
lcfg, "default_debug", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
}
if (result == ISC_R_SUCCESS) { isc_log_createchannel(lcfg, "null", ISC_LOG_TONULL, ISC_LOG_DYNAMIC,
result = isc_log_createchannel(lcfg, "null", ISC_LOG_TONULL, NULL, 0);
ISC_LOG_DYNAMIC, NULL, 0);
}
if (result == ISC_R_SUCCESS) { *lcfgp = lcfg;
*lcfgp = lcfg;
} else {
isc_logconfig_destroy(&lcfg);
}
return (result);
} }
isc_result_t void
isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg) { isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg) {
isc_logconfig_t *old_cfg; isc_logconfig_t *old_cfg;
isc_result_t result;
REQUIRE(VALID_CONTEXT(lctx)); REQUIRE(VALID_CONTEXT(lctx));
REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(VALID_CONFIG(lcfg));
@ -385,17 +348,12 @@ isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg) {
* They won't be equal if isc_log_usechannel has not been called * They won't be equal if isc_log_usechannel has not been called
* since any call to isc_log_registercategories. * since any call to isc_log_registercategories.
*/ */
result = sync_channellist(lcfg); sync_channellist(lcfg);
if (result != ISC_R_SUCCESS) {
return (result);
}
old_cfg = (isc_logconfig_t *)atomic_exchange_acq_rel(&lctx->logconfig, old_cfg = (isc_logconfig_t *)atomic_exchange_acq_rel(&lctx->logconfig,
(uintptr_t)lcfg); (uintptr_t)lcfg);
isc_logconfig_destroy(&old_cfg); isc_logconfig_destroy(&old_cfg);
return (ISC_R_SUCCESS);
} }
void void
@ -650,7 +608,7 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name) {
return (NULL); return (NULL);
} }
isc_result_t void
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name, isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
unsigned int type, int level, unsigned int type, int level,
const isc_logdestination_t *destination, const isc_logdestination_t *destination,
@ -715,9 +673,7 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
break; break;
default: default:
isc_mem_free(mctx, channel->name); ISC_UNREACHABLE();
isc_mem_put(mctx, channel, sizeof(*channel));
return (ISC_R_UNEXPECTED);
} }
ISC_LIST_PREPEND(lcfg->channels, channel, link); ISC_LIST_PREPEND(lcfg->channels, channel, link);
@ -729,8 +685,6 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
if (strcmp(name, "default_stderr") == 0) { if (strcmp(name, "default_stderr") == 0) {
default_channel.channel = channel; default_channel.channel = channel;
} }
return (ISC_R_SUCCESS);
} }
isc_result_t isc_result_t
@ -739,7 +693,6 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
const isc_logmodule_t *module) { const isc_logmodule_t *module) {
isc_log_t *lctx; isc_log_t *lctx;
isc_logchannel_t *channel; isc_logchannel_t *channel;
isc_result_t result = ISC_R_SUCCESS;
unsigned int i; unsigned int i;
REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(VALID_CONFIG(lcfg));
@ -763,21 +716,18 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
} }
if (category != NULL) { if (category != NULL) {
result = assignchannel(lcfg, category->id, module, channel); assignchannel(lcfg, category->id, module, channel);
} else { } else {
/* /*
* Assign to all categories. Note that this includes * Assign to all categories. Note that this includes
* the default channel. * the default channel.
*/ */
for (i = 0; i < lctx->category_count; i++) { for (i = 0; i < lctx->category_count; i++) {
result = assignchannel(lcfg, i, module, channel); assignchannel(lcfg, i, module, channel);
if (result != ISC_R_SUCCESS) {
break;
}
} }
} }
return (result); return (ISC_R_SUCCESS);
} }
void void
@ -888,7 +838,7 @@ isc_log_getduplicateinterval(isc_logconfig_t *lcfg) {
return (lcfg->duplicate_interval); return (lcfg->duplicate_interval);
} }
isc_result_t void
isc_log_settag(isc_logconfig_t *lcfg, const char *tag) { isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(VALID_CONFIG(lcfg));
@ -903,8 +853,6 @@ isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
} }
lcfg->tag = NULL; lcfg->tag = NULL;
} }
return (ISC_R_SUCCESS);
} }
char * char *
@ -947,12 +895,11 @@ isc_log_closefilelogs(isc_log_t *lctx) {
**** Internal functions **** Internal functions
****/ ****/
static isc_result_t static void
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
const isc_logmodule_t *module, isc_logchannel_t *channel) { const isc_logmodule_t *module, isc_logchannel_t *channel) {
isc_logchannellist_t *new_item; isc_logchannellist_t *new_item;
isc_log_t *lctx; isc_log_t *lctx;
isc_result_t result;
REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(VALID_CONFIG(lcfg));
@ -965,10 +912,7 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
/* /*
* Ensure lcfg->channellist_count == lctx->category_count. * Ensure lcfg->channellist_count == lctx->category_count.
*/ */
result = sync_channellist(lcfg); sync_channellist(lcfg);
if (result != ISC_R_SUCCESS) {
return (result);
}
new_item = isc_mem_get(lctx->mctx, sizeof(*new_item)); new_item = isc_mem_get(lctx->mctx, sizeof(*new_item));
@ -990,15 +934,13 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
lcfg->dynamic = true; lcfg->dynamic = true;
} }
} }
return (ISC_R_SUCCESS);
} }
/* /*
* This would ideally be part of isc_log_registercategories(), except then * This would ideally be part of isc_log_registercategories(), except then
* that function would have to return isc_result_t instead of void. * that function would have to return isc_result_t instead of void.
*/ */
static isc_result_t static void
sync_channellist(isc_logconfig_t *lcfg) { sync_channellist(isc_logconfig_t *lcfg) {
unsigned int bytes; unsigned int bytes;
isc_log_t *lctx; isc_log_t *lctx;
@ -1011,7 +953,7 @@ sync_channellist(isc_logconfig_t *lcfg) {
REQUIRE(lctx->category_count != 0); REQUIRE(lctx->category_count != 0);
if (lctx->category_count == lcfg->channellist_count) { if (lctx->category_count == lcfg->channellist_count) {
return (ISC_R_SUCCESS); return;
} }
bytes = lctx->category_count * sizeof(ISC_LIST(isc_logchannellist_t)); bytes = lctx->category_count * sizeof(ISC_LIST(isc_logchannellist_t));
@ -1029,8 +971,6 @@ sync_channellist(isc_logconfig_t *lcfg) {
lcfg->channellists = lists; lcfg->channellists = lists;
lcfg->channellist_count = lctx->category_count; lcfg->channellist_count = lctx->category_count;
return (ISC_R_SUCCESS);
} }
static isc_result_t static isc_result_t
@ -1721,16 +1661,12 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
size = sizeof(isc_logmessage_t) + size = sizeof(isc_logmessage_t) +
strlen(lctx->buffer) + 1; strlen(lctx->buffer) + 1;
message = isc_mem_get(lctx->mctx, size); message = isc_mem_get(lctx->mctx, size);
{ message->text = (char *)(message + 1);
message->text = (char *)(message + 1); size -= sizeof(isc_logmessage_t);
size -= sizeof(isc_logmessage_t); strlcpy(message->text, lctx->buffer, size);
strlcpy(message->text, lctx->buffer, TIME_NOW(&message->time);
size); ISC_LINK_INIT(message, link);
TIME_NOW(&message->time); ISC_LIST_APPEND(lctx->messages, message, link);
ISC_LINK_INIT(message, link);
ISC_LIST_APPEND(lctx->messages, message,
link);
}
} }
} }

View File

@ -116,8 +116,7 @@ isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers) {
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
INSIST(test_lctx == NULL); INSIST(test_lctx == NULL);
CHECK(isc_log_create(test_mctx, &test_lctx, &logconfig)); isc_log_create(test_mctx, &test_lctx, &logconfig);
isc_log_registercategories(test_lctx, categories); isc_log_registercategories(test_lctx, categories);
isc_log_setcontext(test_lctx); isc_log_setcontext(test_lctx);
@ -125,9 +124,8 @@ isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination, 0);
&destination, 0));
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
} }

View File

@ -73,7 +73,7 @@ setup() {
isc_logdestination_t destination; isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
CHECK(isc_log_create(mctx, &lctx, &logconfig)); isc_log_create(mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories); isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
@ -81,8 +81,8 @@ setup() {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0)); ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);

View File

@ -73,7 +73,7 @@ setup() {
isc_logdestination_t destination; isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
CHECK(isc_log_create(mctx, &lctx, &logconfig)); isc_log_create(mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories); isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
@ -81,8 +81,8 @@ setup() {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0)); ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);

View File

@ -288,7 +288,7 @@ ns_test_begin(FILE *logfile, bool start_managers) {
isc_logconfig_t *logconfig = NULL; isc_logconfig_t *logconfig = NULL;
INSIST(lctx == NULL); INSIST(lctx == NULL);
CHECK(isc_log_create(mctx, &lctx, &logconfig)); isc_log_create(mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories); isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx); isc_log_setcontext(lctx);
@ -299,9 +299,8 @@ ns_test_begin(FILE *logfile, bool start_managers) {
destination.file.name = NULL; destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0; destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, ISC_LOG_DYNAMIC, &destination, 0);
&destination, 0));
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
} }