Add isc_log_createandusechannel() function to simplify usage

The new
isc_log_createandusechannel() function combines following calls:

    isc_log_createchannel()
    isc_log_usechannel()

calls into a single call that cannot fail and therefore can be used in
places where we know this cannot fail thus simplifying the error
handling.
This commit is contained in:
Ondřej Surý
2024-08-14 14:38:07 +02:00
parent 091d738c72
commit 679e90a57d
20 changed files with 210 additions and 338 deletions

View File

@@ -61,7 +61,6 @@ main(int argc, char **argv) {
isc_result_t result;
char *origin, *file1, *file2, *journal;
dns_db_t *olddb = NULL, *newdb = NULL;
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
if (argc != 5) {
@@ -78,18 +77,10 @@ main(int argc, char **argv) {
isc_mem_create(&mctx);
logconfig = isc_logconfig_get();
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
result = isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_ALL,
ISC_LOGMODULE_ALL);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
isc_log_createandusechannel(
logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, 0,
ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
result = loadzone(&olddb, origin, file1);
if (result != ISC_R_SUCCESS) {

View File

@@ -48,7 +48,6 @@ unsigned int bits = 2048U;
isc_mem_t *mctx;
isc_logconfig_t *logconfig;
int level = ISC_LOG_WARNING;
isc_logdestination_t destination;
char filename[255];
isc_result_t result;
isc_buffer_t buf;
@@ -110,17 +109,12 @@ main(int argc, char **argv) {
logconfig = isc_logconfig_get();
isc_log_settag(logconfig, "bigkey");
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
&destination,
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
isc_log_createandusechannel(
logconfig, "default_stderr", ISC_LOG_TOFILEDESC, level,
ISC_LOGDESTINATION_STDERR,
ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL, ISC_LOGCATEGORY_DEFAULT,
ISC_LOGMODULE_DEFAULT);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_"
"usechannel("
")");
name = dns_fixedname_initname(&fname);
isc_buffer_constinit(&buf, "example.", strlen("example."));
isc_buffer_add(&buf, strlen("example."));