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:
parent
e6deefd03f
commit
0b793166d0
@ -553,7 +553,7 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
|
||||
isc_logconfig_t *logconfig = 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_setcontext(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.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
|
||||
&destination, 0) == ISC_R_SUCCESS);
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
|
||||
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
|
@ -271,11 +271,7 @@ setup_logging(FILE *errout) {
|
||||
isc_logdestination_t destination;
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
|
||||
result = isc_log_create(mctx, &lctx, &logconfig);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("Couldn't set up logging");
|
||||
}
|
||||
|
||||
isc_log_create(mctx, &lctx, &logconfig);
|
||||
isc_log_registercategories(lctx, categories);
|
||||
isc_log_registermodules(lctx, modules);
|
||||
isc_log_setcontext(lctx);
|
||||
@ -287,20 +283,12 @@ setup_logging(FILE *errout) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
|
||||
result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTPREFIX);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("Couldn't set up log channel 'stderr'");
|
||||
}
|
||||
|
||||
isc_log_setdebuglevel(lctx, loglevel);
|
||||
|
||||
result = isc_log_settag(logconfig, ";; ");
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("Couldn't set log tag");
|
||||
}
|
||||
isc_log_settag(logconfig, ";; ");
|
||||
|
||||
result = isc_log_usechannel(logconfig, "stderr",
|
||||
ISC_LOGCATEGORY_DEFAULT, NULL);
|
||||
@ -309,12 +297,9 @@ setup_logging(FILE *errout) {
|
||||
}
|
||||
|
||||
if (resolve_trace && loglevel < 1) {
|
||||
result = isc_log_createchannel(
|
||||
logconfig, "resolver", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DEBUG(1), &destination, ISC_LOG_PRINTPREFIX);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("Couldn't set up log channel 'resolver'");
|
||||
}
|
||||
isc_log_createchannel(logconfig, "resolver", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DEBUG(1), &destination,
|
||||
ISC_LOG_PRINTPREFIX);
|
||||
|
||||
result = isc_log_usechannel(logconfig, "resolver",
|
||||
DNS_LOGCATEGORY_RESOLVER,
|
||||
@ -325,12 +310,9 @@ setup_logging(FILE *errout) {
|
||||
}
|
||||
|
||||
if (validator_trace && loglevel < 3) {
|
||||
result = isc_log_createchannel(
|
||||
logconfig, "validator", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DEBUG(3), &destination, ISC_LOG_PRINTPREFIX);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("Couldn't set up log channel 'validator'");
|
||||
}
|
||||
isc_log_createchannel(logconfig, "validator",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(3),
|
||||
&destination, ISC_LOG_PRINTPREFIX);
|
||||
|
||||
result = isc_log_usechannel(logconfig, "validator",
|
||||
DNS_LOGCATEGORY_DNSSEC,
|
||||
@ -341,12 +323,9 @@ setup_logging(FILE *errout) {
|
||||
}
|
||||
|
||||
if (message_trace && loglevel < 10) {
|
||||
result = isc_log_createchannel(
|
||||
logconfig, "messages", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DEBUG(10), &destination, ISC_LOG_PRINTPREFIX);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("Couldn't set up log channel 'messages'");
|
||||
}
|
||||
isc_log_createchannel(logconfig, "messages", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DEBUG(10), &destination,
|
||||
ISC_LOG_PRINTPREFIX);
|
||||
|
||||
result = isc_log_usechannel(logconfig, "messages",
|
||||
DNS_LOGCATEGORY_RESOLVER,
|
||||
|
@ -1394,9 +1394,7 @@ setup_libs(void) {
|
||||
isc_mem_create(&mctx);
|
||||
isc_mem_setname(mctx, "dig", NULL);
|
||||
|
||||
result = isc_log_create(mctx, &lctx, &logconfig);
|
||||
check_result(result, "isc_log_create");
|
||||
|
||||
isc_log_create(mctx, &lctx, &logconfig);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
dns_log_setcontext(lctx);
|
||||
|
@ -128,7 +128,6 @@ sig_format(dns_rdata_rrsig_t *sig, char *cp, unsigned int size) {
|
||||
|
||||
void
|
||||
setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
|
||||
isc_result_t result;
|
||||
isc_logdestination_t destination;
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
isc_log_t *log = NULL;
|
||||
@ -153,12 +152,11 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
|
||||
break;
|
||||
}
|
||||
|
||||
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
|
||||
isc_log_create(mctx, &log, &logconfig);
|
||||
isc_log_setcontext(log);
|
||||
dns_log_init(log);
|
||||
dns_log_setcontext(log);
|
||||
|
||||
RUNTIME_CHECK(isc_log_settag(logconfig, program) == ISC_R_SUCCESS);
|
||||
isc_log_settag(logconfig, program);
|
||||
|
||||
/*
|
||||
* 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.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
level, &destination,
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
|
||||
&destination,
|
||||
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
|
||||
check_result(result, "isc_log_createchannel()");
|
||||
|
||||
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
|
||||
ISC_R_SUCCESS);
|
||||
|
@ -45,7 +45,7 @@ named_log_init(bool safe);
|
||||
* as root.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
named_log_setdefaultchannels(isc_logconfig_t *lcfg);
|
||||
/*%
|
||||
* 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.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
named_log_setsafechannels(isc_logconfig_t *lcfg);
|
||||
/*%
|
||||
* Like named_log_setdefaultchannels(), but omits any logging to files.
|
||||
|
@ -53,10 +53,7 @@ named_log_init(bool safe) {
|
||||
/*
|
||||
* Setup a logging context.
|
||||
*/
|
||||
result = isc_log_create(named_g_mctx, &named_g_lctx, &lcfg);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
isc_log_create(named_g_mctx, &named_g_lctx, &lcfg);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
if (safe) {
|
||||
result = named_log_setsafechannels(lcfg);
|
||||
named_log_setsafechannels(lcfg);
|
||||
} else {
|
||||
result = named_log_setdefaultchannels(lcfg);
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
named_log_setdefaultchannels(lcfg);
|
||||
}
|
||||
|
||||
result = named_log_setdefaultcategory(lcfg);
|
||||
@ -94,9 +88,8 @@ cleanup:
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
named_log_setdefaultchannels(isc_logconfig_t *lcfg) {
|
||||
isc_result_t result;
|
||||
isc_logdestination_t destination;
|
||||
|
||||
/*
|
||||
@ -109,12 +102,9 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg) {
|
||||
destination.file.name = "named.run";
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(
|
||||
lcfg, "default_debug", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC,
|
||||
&destination, ISC_LOG_PRINTTIME | ISC_LOG_DEBUGONLY);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILE,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME | ISC_LOG_DEBUGONLY);
|
||||
}
|
||||
|
||||
if (named_g_logfile != NULL) {
|
||||
@ -122,48 +112,32 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg) {
|
||||
destination.file.name = named_g_logfile;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(
|
||||
lcfg, "default_logfile", ISC_LOG_TOFILE,
|
||||
isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY |
|
||||
ISC_LOG_PRINTTIME |
|
||||
ISC_LOG_PRINTCATEGORY |
|
||||
ISC_LOG_PRINTLEVEL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
#if ISC_FACILITY != LOG_DAEMON
|
||||
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);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
#endif /* if ISC_FACILITY != LOG_DAEMON */
|
||||
|
||||
/*
|
||||
* Set the initial debug level.
|
||||
*/
|
||||
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) {
|
||||
isc_result_t result;
|
||||
isc_logdestination_t destination;
|
||||
|
||||
if (!named_g_logstderr) {
|
||||
result = isc_log_createchannel(lcfg, "default_debug",
|
||||
ISC_LOG_TONULL, ISC_LOG_DYNAMIC,
|
||||
NULL, 0);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TONULL,
|
||||
ISC_LOG_DYNAMIC, NULL, 0);
|
||||
|
||||
/*
|
||||
* 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.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(
|
||||
lcfg, "default_logfile", ISC_LOG_TOFILE,
|
||||
isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY |
|
||||
ISC_LOG_PRINTTIME |
|
||||
ISC_LOG_PRINTCATEGORY |
|
||||
ISC_LOG_PRINTLEVEL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
#if ISC_FACILITY != LOG_DAEMON
|
||||
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);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
#endif /* if ISC_FACILITY != LOG_DAEMON */
|
||||
|
||||
result = ISC_R_SUCCESS;
|
||||
|
||||
cleanup:
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
|
@ -92,7 +92,7 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
|
||||
*/
|
||||
static isc_result_t
|
||||
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;
|
||||
unsigned int type;
|
||||
unsigned int flags = 0;
|
||||
@ -271,14 +271,12 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig) {
|
||||
}
|
||||
}
|
||||
|
||||
if (logconfig == NULL) {
|
||||
result = ISC_R_SUCCESS;
|
||||
} else {
|
||||
result = isc_log_createchannel(logconfig, channelname, type,
|
||||
level, &dest, flags);
|
||||
if (logconfig != NULL) {
|
||||
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;
|
||||
|
||||
/*
|
||||
@ -333,7 +331,7 @@ named_logconfig(isc_logconfig_t *logconfig, const cfg_obj_t *logstmt) {
|
||||
const cfg_obj_t *catname;
|
||||
|
||||
if (logconfig != NULL) {
|
||||
CHECK(named_log_setdefaultchannels(logconfig));
|
||||
named_log_setdefaultchannels(logconfig);
|
||||
}
|
||||
|
||||
(void)cfg_map_get(logstmt, "channel", &channels);
|
||||
|
@ -9110,8 +9110,7 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
} else {
|
||||
const cfg_obj_t *logobj = NULL;
|
||||
|
||||
CHECKM(isc_logconfig_create(named_g_lctx, &logc),
|
||||
"creating new logging configuration");
|
||||
isc_logconfig_create(named_g_lctx, &logc);
|
||||
|
||||
logobj = NULL;
|
||||
(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 "
|
||||
"logging");
|
||||
} else {
|
||||
CHECKM(named_log_setdefaultchannels(logc),
|
||||
"setting up default logging channels");
|
||||
named_log_setdefaultchannels(logc);
|
||||
CHECKM(named_log_setunmatchedcategory(logc),
|
||||
"setting up default 'category unmatched'");
|
||||
CHECKM(named_log_setdefaultcategory(logc),
|
||||
"setting up default 'category default'");
|
||||
}
|
||||
|
||||
CHECKM(isc_logconfig_use(named_g_lctx, logc),
|
||||
"installing logging configuration");
|
||||
isc_logconfig_use(named_g_lctx, logc);
|
||||
logc = NULL;
|
||||
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
|
@ -812,9 +812,7 @@ setup_system(void) {
|
||||
|
||||
dns_result_register();
|
||||
|
||||
result = isc_log_create(gmctx, &glctx, &logconfig);
|
||||
check_result(result, "isc_log_create");
|
||||
|
||||
isc_log_create(gmctx, &glctx, &logconfig);
|
||||
isc_log_setcontext(glctx);
|
||||
dns_log_init(glctx);
|
||||
dns_log_setcontext(glctx);
|
||||
|
@ -985,18 +985,16 @@ main(int argc, char **argv) {
|
||||
isc_taskmgr_create(rndc_mctx, 1, 0, NULL, &taskmgr));
|
||||
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);
|
||||
DO("setting log tag", isc_log_settag(logconfig, progname));
|
||||
isc_log_settag(logconfig, progname);
|
||||
logdest.file.stream = stderr;
|
||||
logdest.file.name = NULL;
|
||||
logdest.file.versions = ISC_LOG_ROLLNEVER;
|
||||
logdest.file.maximum_size = 0;
|
||||
DO("creating log channel",
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_INFO, &logdest,
|
||||
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL));
|
||||
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
|
||||
DO("enabling log channel",
|
||||
isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
|
||||
|
@ -72,8 +72,7 @@ main(int argc, char **argv) {
|
||||
|
||||
isc_mem_create(&mctx);
|
||||
|
||||
result = isc_log_create(mctx, &lctx, &lcfg);
|
||||
check_result(result, "isc_log_create()");
|
||||
isc_log_create(mctx, &lctx, &lcfg);
|
||||
isc_log_setcontext(lctx);
|
||||
|
||||
/*
|
||||
@ -83,10 +82,9 @@ main(int argc, char **argv) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME);
|
||||
check_result(result, "isc_log_createchannel()");
|
||||
isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
|
||||
|
||||
result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
|
||||
check_result(result, "isc_log_usechannel()");
|
||||
|
||||
|
@ -100,7 +100,7 @@ main(int argc, char **argv) {
|
||||
CHECK(dst_lib_init(mctx, NULL));
|
||||
dst_active = true;
|
||||
|
||||
CHECK(isc_log_create(mctx, &lctx, &logconfig));
|
||||
isc_log_create(mctx, &lctx, &logconfig);
|
||||
isc_log_registercategories(lctx, categories);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
@ -110,8 +110,9 @@ main(int argc, char **argv) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0));
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
|
||||
dns_result_register();
|
||||
|
@ -297,8 +297,7 @@ main(int argc, char **argv) {
|
||||
isc_mempool_create(mctx, sizeof(client_t), &cmp);
|
||||
isc_mempool_setname(cmp, "adb test clients");
|
||||
|
||||
result = isc_log_create(mctx, &lctx, &lcfg);
|
||||
check_result(result, "isc_log_create()");
|
||||
isc_log_create(mctx, &lctx, &lcfg);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
dns_log_setcontext(lctx);
|
||||
@ -310,10 +309,9 @@ main(int argc, char **argv) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME);
|
||||
check_result(result, "isc_log_createchannel()");
|
||||
isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
|
||||
|
||||
result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
|
||||
check_result(result, "isc_log_usechannel()");
|
||||
|
||||
|
@ -56,7 +56,7 @@ log_init(void) {
|
||||
/*
|
||||
* 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);
|
||||
dns_log_init(lctx);
|
||||
dns_log_setcontext(lctx);
|
||||
@ -69,10 +69,9 @@ log_init(void) {
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
flags = ISC_LOG_PRINTTIME;
|
||||
RUNTIME_CHECK(isc_log_createchannel(lcfg, "_default",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
|
||||
&destination,
|
||||
flags) == ISC_R_SUCCESS);
|
||||
isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, flags);
|
||||
|
||||
RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) ==
|
||||
ISC_R_SUCCESS);
|
||||
isc_log_setdebuglevel(lctx, level);
|
||||
|
@ -402,8 +402,7 @@ main(int argc, char *argv[]) {
|
||||
DNS_DBFIND_VALIDATEGLUE);
|
||||
break;
|
||||
case 'l':
|
||||
RUNTIME_CHECK(isc_log_create(mctx, &lctx, NULL) ==
|
||||
ISC_R_SUCCESS);
|
||||
isc_log_create(mctx, &lctx, NULL);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
dns_log_setcontext(lctx);
|
||||
|
@ -458,7 +458,7 @@ main(int argc, char *argv[]) {
|
||||
mctx = NULL;
|
||||
isc_mem_create(&mctx);
|
||||
|
||||
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg));
|
||||
isc_log_create(mctx, &lctx, &lcfg);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
dns_log_setcontext(lctx);
|
||||
@ -470,9 +470,9 @@ main(int argc, char *argv[]) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
RUNCHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME));
|
||||
isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
|
||||
|
||||
RUNCHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL));
|
||||
|
||||
isc_log_setdebuglevel(lctx, 9);
|
||||
|
@ -112,9 +112,9 @@ main(int argc, char **argv) {
|
||||
lcfg = NULL;
|
||||
|
||||
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);
|
||||
dns_log_init(lctx);
|
||||
@ -147,20 +147,20 @@ main(int argc, char **argv) {
|
||||
destination.file.maximum_size = 1;
|
||||
destination.file.versions = file_versions;
|
||||
|
||||
CHECK(isc_log_createchannel(
|
||||
isc_log_createchannel(
|
||||
lcfg, "file_test", ISC_LOG_TOFILE, ISC_LOG_INFO, &destination,
|
||||
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.
|
||||
*/
|
||||
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_PRINTTIME | ISC_LOG_PRINTLEVEL |
|
||||
ISC_LOG_DEBUGONLY));
|
||||
ISC_LOG_DEBUGONLY);
|
||||
|
||||
/*
|
||||
* Test the usability of the four predefined logging channels.
|
||||
|
@ -236,7 +236,7 @@ main(int argc, char *argv[]) {
|
||||
socketmgr = NULL;
|
||||
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;
|
||||
RUNTIME_CHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp,
|
||||
|
@ -274,7 +274,7 @@ main(int argc, char *argv[]) {
|
||||
|
||||
lctx = NULL;
|
||||
lcfg = NULL;
|
||||
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg));
|
||||
isc_log_create(mctx, &lctx, &lcfg);
|
||||
|
||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||
|
||||
|
@ -107,19 +107,20 @@ main(int argc, char **argv) {
|
||||
|
||||
isc_mem_create(&mctx);
|
||||
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_);
|
||||
dns_log_init(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.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
level, &destination,
|
||||
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL),
|
||||
"isc_log_createchannel()");
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
|
||||
&destination,
|
||||
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
|
||||
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_"
|
||||
"usechannel("
|
||||
")");
|
||||
|
@ -232,7 +232,7 @@ main(int argc, char *argv[]) {
|
||||
|
||||
log = NULL;
|
||||
logconfig = NULL;
|
||||
RUNCHECK(isc_log_create(mctx, &log, &logconfig));
|
||||
isc_log_create(mctx, &log, &logconfig);
|
||||
|
||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||
|
||||
|
@ -172,7 +172,7 @@ main(int argc, char **argv) {
|
||||
|
||||
log = NULL;
|
||||
logconfig = NULL;
|
||||
RUNCHECK(isc_log_create(mctx, &log, &logconfig));
|
||||
isc_log_create(mctx, &log, &logconfig);
|
||||
|
||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||
|
||||
|
@ -2086,7 +2086,7 @@ main(int argc, char *argv[]) {
|
||||
|
||||
lctx = NULL;
|
||||
lcfg = NULL;
|
||||
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg));
|
||||
isc_log_create(mctx, &lctx, &lcfg);
|
||||
|
||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||
isc_nonce_buf(cookie_secret, sizeof(cookie_secret));
|
||||
|
@ -32,7 +32,7 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
|
||||
isc_logconfig_t *logconfig = 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);
|
||||
dns_log_init(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.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
|
||||
&destination, 0) == ISC_R_SUCCESS);
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
|
||||
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
|
@ -62,8 +62,7 @@ int ctx_init(void) {
|
||||
|
||||
isc_mem_create(&ctx.mem);
|
||||
|
||||
if (isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg) != ISC_R_SUCCESS)
|
||||
goto done;
|
||||
isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg);
|
||||
|
||||
isc_log_setcontext(ctx.log);
|
||||
dns_log_init(ctx.log);
|
||||
|
@ -283,8 +283,7 @@ rudimentary initialization of both.
|
||||
isc_logconfig_t *lcfg;
|
||||
|
||||
isc_mem_create(&mctx);
|
||||
if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
|
||||
oops_it_didnt_work();
|
||||
isc_log_create(mctx, &lctx, &lcfg);
|
||||
|
||||
3) Initialize any additional libraries. The convention for the name of
|
||||
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
|
||||
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
|
||||
will be destroyed, freeing all memory it used.
|
||||
|
@ -1066,9 +1066,7 @@ the following steps need to be taken to initialize it.
|
||||
isc_logconfig_t *lcfg;
|
||||
|
||||
isc_mem_create(&mctx);
|
||||
if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) {
|
||||
oops_it_didnt_work();
|
||||
}
|
||||
isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS);
|
||||
|
||||
1. Initialize any additional libraries. The convention for the name of
|
||||
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.maximum_size = 0; /* No byte limit. */
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER; /* External rolling. */
|
||||
result = isc_log_createchannel(lcfg, "sample1", ISC_LOG_TOFILE,
|
||||
ISC_LOG_DYNAMIC, &destination,
|
||||
ISC_LOG_PRINTTIME);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
oops_it_didnt_work();
|
||||
isc_log_createchannel(lcfg, "sample1", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC,
|
||||
&destination, ISC_LOG_PRINTTIME);
|
||||
|
||||
destination.file.stream = stdout;
|
||||
result = isc_log_createchannel(lcfg, "sample2", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_INFO, &destination,
|
||||
ISC_LOG_PRINTTIME);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
oops_it_didnt_work();
|
||||
isc_log_createchannel(lcfg, "sample2", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_INFO, &destination, ISC_LOG_PRINTTIME);
|
||||
|
||||
destination.facility = LOG_ERR;
|
||||
result = isc_log_createchannel(lcfg, "sample3", ISC_LOG_SYSLOG,
|
||||
ISC_LOG_ERROR, &destination, 0);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
oops_it_didnt_work();
|
||||
isc_log_createchannel(lcfg, "sample3", ISC_LOG_SYSLOG, ISC_LOG_ERROR,
|
||||
&destination, 0);
|
||||
|
||||
`ISC_LOG_DYNAMIC` is used to define a channel that wants any of the
|
||||
messages up to the current debugging level of the program.
|
||||
|
@ -445,10 +445,7 @@ dns_client_create(dns_client_t **clientp, unsigned int options) {
|
||||
goto cleanup;
|
||||
}
|
||||
#if 0
|
||||
result = isc_log_create(mctx, &lctx, &logconfig);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
isc_log_create(mctx, &lctx, &logconfig);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
dns_log_setcontext(lctx);
|
||||
|
@ -153,8 +153,7 @@ dns_test_begin(FILE *logfile, bool start_managers) {
|
||||
isc_logconfig_t *logconfig = 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_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
@ -164,9 +163,8 @@ dns_test_begin(FILE *logfile, bool start_managers) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
|
||||
&destination, 0));
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ LIBISC_EXTERNAL_DATA extern isc_logmodule_t isc_modules[];
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp);
|
||||
/*%<
|
||||
* 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
|
||||
* necessary memory was allocated, or NULL otherwise.
|
||||
*\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);
|
||||
/*%<
|
||||
* 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
|
||||
* memory was allocated, or NULL otherwise.
|
||||
*\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);
|
||||
/*%<
|
||||
* Associate a new configuration with a logging context.
|
||||
@ -274,10 +266,6 @@ isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg);
|
||||
*
|
||||
* Ensures:
|
||||
*\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
|
||||
@ -388,7 +376,7 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]);
|
||||
* used with isc_log_usechannel() and isc_log_write().
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
|
||||
unsigned int type, int level,
|
||||
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.
|
||||
* Any channel that previously existed with the given name
|
||||
* 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
|
||||
@ -699,7 +681,7 @@ isc_log_getduplicateinterval(isc_logconfig_t *lcfg);
|
||||
*\li The current duplicate filtering interval.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
|
||||
/*%<
|
||||
* 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
|
||||
* 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
|
||||
* of the currently active isc_logconfig_t was inherited. this does not
|
||||
* currently happen.
|
||||
|
114
lib/isc/log.c
114
lib/isc/log.c
@ -196,11 +196,11 @@ LIBISC_EXTERNAL_DATA isc_log_t *isc_lctx = NULL;
|
||||
/*!
|
||||
* Forward declarations.
|
||||
*/
|
||||
static isc_result_t
|
||||
static void
|
||||
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
|
||||
const isc_logmodule_t *module, isc_logchannel_t *channel);
|
||||
|
||||
static isc_result_t
|
||||
static void
|
||||
sync_channellist(isc_logconfig_t *lcfg);
|
||||
|
||||
static isc_result_t
|
||||
@ -232,18 +232,16 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
|
||||
/*
|
||||
* 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_t *lctx;
|
||||
isc_logconfig_t *lcfg = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(lctxp != NULL && *lctxp == NULL);
|
||||
REQUIRE(lcfgp == NULL || *lcfgp == NULL);
|
||||
|
||||
lctx = isc_mem_get(mctx, sizeof(*lctx));
|
||||
if (lctx != NULL) {
|
||||
lctx->mctx = NULL;
|
||||
isc_mem_attach(mctx, &lctx->mctx);
|
||||
lctx->categories = NULL;
|
||||
@ -267,39 +265,22 @@ isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp) {
|
||||
|
||||
isc_log_registercategories(lctx, isc_categories);
|
||||
isc_log_registermodules(lctx, isc_modules);
|
||||
result = isc_logconfig_create(lctx, &lcfg);
|
||||
} else {
|
||||
result = ISC_R_NOMEMORY;
|
||||
}
|
||||
isc_logconfig_create(lctx, &lcfg);
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
result = sync_channellist(lcfg);
|
||||
}
|
||||
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_t *lcfg;
|
||||
isc_logdestination_t destination;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
int level = ISC_LOG_INFO;
|
||||
|
||||
REQUIRE(lcfgp != NULL && *lcfgp == NULL);
|
||||
@ -321,25 +302,18 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) {
|
||||
* Create the default channels:
|
||||
* default_syslog, default_stderr, default_debug and null.
|
||||
*/
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
destination.facility = LOG_DAEMON;
|
||||
result = isc_log_createchannel(lcfg, "default_syslog",
|
||||
ISC_LOG_TOSYSLOG, level,
|
||||
isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, level,
|
||||
&destination, 0);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
destination.file.stream = stderr;
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.suffix = isc_log_rollsuffix_increment;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(lcfg, "default_stderr",
|
||||
ISC_LOG_TOFILEDESC, level,
|
||||
isc_log_createchannel(lcfg, "default_stderr", ISC_LOG_TOFILEDESC, level,
|
||||
&destination, ISC_LOG_PRINTTIME);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
/*
|
||||
* Set the default category's channel to default_stderr,
|
||||
* which is at the head of the channels list because it was
|
||||
@ -352,29 +326,18 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) {
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.suffix = isc_log_rollsuffix_increment;
|
||||
destination.file.maximum_size = 0;
|
||||
result = isc_log_createchannel(
|
||||
lcfg, "default_debug", ISC_LOG_TOFILEDESC,
|
||||
isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
result = isc_log_createchannel(lcfg, "null", ISC_LOG_TONULL,
|
||||
ISC_LOG_DYNAMIC, NULL, 0);
|
||||
}
|
||||
isc_log_createchannel(lcfg, "null", ISC_LOG_TONULL, ISC_LOG_DYNAMIC,
|
||||
NULL, 0);
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
*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_t *old_cfg;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(VALID_CONTEXT(lctx));
|
||||
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
|
||||
* since any call to isc_log_registercategories.
|
||||
*/
|
||||
result = sync_channellist(lcfg);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
sync_channellist(lcfg);
|
||||
|
||||
old_cfg = (isc_logconfig_t *)atomic_exchange_acq_rel(&lctx->logconfig,
|
||||
(uintptr_t)lcfg);
|
||||
|
||||
isc_logconfig_destroy(&old_cfg);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
@ -650,7 +608,7 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
|
||||
unsigned int type, int level,
|
||||
const isc_logdestination_t *destination,
|
||||
@ -715,9 +673,7 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
|
||||
break;
|
||||
|
||||
default:
|
||||
isc_mem_free(mctx, channel->name);
|
||||
isc_mem_put(mctx, channel, sizeof(*channel));
|
||||
return (ISC_R_UNEXPECTED);
|
||||
ISC_UNREACHABLE();
|
||||
}
|
||||
|
||||
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) {
|
||||
default_channel.channel = channel;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
@ -739,7 +693,6 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
|
||||
const isc_logmodule_t *module) {
|
||||
isc_log_t *lctx;
|
||||
isc_logchannel_t *channel;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
unsigned int i;
|
||||
|
||||
REQUIRE(VALID_CONFIG(lcfg));
|
||||
@ -763,21 +716,18 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
|
||||
}
|
||||
|
||||
if (category != NULL) {
|
||||
result = assignchannel(lcfg, category->id, module, channel);
|
||||
assignchannel(lcfg, category->id, module, channel);
|
||||
} else {
|
||||
/*
|
||||
* Assign to all categories. Note that this includes
|
||||
* the default channel.
|
||||
*/
|
||||
for (i = 0; i < lctx->category_count; i++) {
|
||||
result = assignchannel(lcfg, i, module, channel);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
assignchannel(lcfg, i, module, channel);
|
||||
}
|
||||
}
|
||||
|
||||
return (result);
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
@ -888,7 +838,7 @@ isc_log_getduplicateinterval(isc_logconfig_t *lcfg) {
|
||||
return (lcfg->duplicate_interval);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
|
||||
REQUIRE(VALID_CONFIG(lcfg));
|
||||
|
||||
@ -903,8 +853,6 @@ isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
|
||||
}
|
||||
lcfg->tag = NULL;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
char *
|
||||
@ -947,12 +895,11 @@ isc_log_closefilelogs(isc_log_t *lctx) {
|
||||
**** Internal functions
|
||||
****/
|
||||
|
||||
static isc_result_t
|
||||
static void
|
||||
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
|
||||
const isc_logmodule_t *module, isc_logchannel_t *channel) {
|
||||
isc_logchannellist_t *new_item;
|
||||
isc_log_t *lctx;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(VALID_CONFIG(lcfg));
|
||||
|
||||
@ -965,10 +912,7 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
|
||||
/*
|
||||
* Ensure lcfg->channellist_count == lctx->category_count.
|
||||
*/
|
||||
result = sync_channellist(lcfg);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
sync_channellist(lcfg);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This would ideally be part of isc_log_registercategories(), except then
|
||||
* that function would have to return isc_result_t instead of void.
|
||||
*/
|
||||
static isc_result_t
|
||||
static void
|
||||
sync_channellist(isc_logconfig_t *lcfg) {
|
||||
unsigned int bytes;
|
||||
isc_log_t *lctx;
|
||||
@ -1011,7 +953,7 @@ sync_channellist(isc_logconfig_t *lcfg) {
|
||||
REQUIRE(lctx->category_count != 0);
|
||||
|
||||
if (lctx->category_count == lcfg->channellist_count) {
|
||||
return (ISC_R_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
bytes = lctx->category_count * sizeof(ISC_LIST(isc_logchannellist_t));
|
||||
@ -1029,8 +971,6 @@ sync_channellist(isc_logconfig_t *lcfg) {
|
||||
|
||||
lcfg->channellists = lists;
|
||||
lcfg->channellist_count = lctx->category_count;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
@ -1721,16 +1661,12 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
|
||||
size = sizeof(isc_logmessage_t) +
|
||||
strlen(lctx->buffer) + 1;
|
||||
message = isc_mem_get(lctx->mctx, size);
|
||||
{
|
||||
message->text = (char *)(message + 1);
|
||||
size -= sizeof(isc_logmessage_t);
|
||||
strlcpy(message->text, lctx->buffer,
|
||||
size);
|
||||
strlcpy(message->text, lctx->buffer, size);
|
||||
TIME_NOW(&message->time);
|
||||
ISC_LINK_INIT(message, link);
|
||||
ISC_LIST_APPEND(lctx->messages, message,
|
||||
link);
|
||||
}
|
||||
ISC_LIST_APPEND(lctx->messages, message, link);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,8 +116,7 @@ isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers) {
|
||||
isc_logconfig_t *logconfig = 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_setcontext(test_lctx);
|
||||
|
||||
@ -125,9 +124,8 @@ isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
|
||||
&destination, 0));
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ setup() {
|
||||
isc_logdestination_t destination;
|
||||
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_setcontext(lctx);
|
||||
|
||||
@ -81,8 +81,8 @@ setup() {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0));
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
@ -73,7 +73,7 @@ setup() {
|
||||
isc_logdestination_t destination;
|
||||
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_setcontext(lctx);
|
||||
|
||||
@ -81,8 +81,8 @@ setup() {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0));
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
@ -288,7 +288,7 @@ ns_test_begin(FILE *logfile, bool start_managers) {
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
|
||||
INSIST(lctx == NULL);
|
||||
CHECK(isc_log_create(mctx, &lctx, &logconfig));
|
||||
isc_log_create(mctx, &lctx, &logconfig);
|
||||
|
||||
isc_log_registercategories(lctx, categories);
|
||||
isc_log_setcontext(lctx);
|
||||
@ -299,9 +299,8 @@ ns_test_begin(FILE *logfile, bool start_managers) {
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr",
|
||||
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
|
||||
&destination, 0));
|
||||
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC, &destination, 0);
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user