]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add isc_log_createandusechannel() function to simplify usage
authorOndřej Surý <ondrej@isc.org>
Wed, 14 Aug 2024 12:38:07 +0000 (14:38 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 20 Aug 2024 12:50:39 +0000 (12:50 +0000)
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.

20 files changed:
bin/check/check-tool.c
bin/delv/delv.c
bin/dig/dighost.c
bin/dnssec/dnssectool.c
bin/named/log.c
bin/named/logconf.c
bin/nsupdate/nsupdate.c
bin/rndc/rndc.c
bin/tests/system/makejournal.c
bin/tests/system/rsabigexponent/bigkey.c
bin/tools/named-journalprint.c
doc/dev/dev.md
doc/misc/cfg_test.c
lib/isc/include/isc/log.h
lib/isc/log.c
lib/isc/netmgr/netmgr.c
tests/bench/qpmulti.c
tests/dns/qpmulti_test.c
tests/isccfg/duration_test.c
tests/isccfg/parser_test.c

index 59a8fd7a2d9480139f58a33c06eb61ee74fc3d39..1f8e49902cba7b9c0d990efff6524400578023dc 100644 (file)
@@ -539,16 +539,10 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
 isc_result_t
 setup_logging(FILE *errout) {
        isc_logconfig_t *logconfig = isc_logconfig_get();
-       isc_logdestination_t destination = {
-               .file.stream = errout,
-               .file.versions = ISC_LOG_ROLLNEVER,
-       };
-       isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
-                             ISC_LOG_DYNAMIC, &destination, 0);
-
-       RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
-                                        ISC_LOGCATEGORY_ALL,
-                                        ISC_LOGMODULE_ALL) == ISC_R_SUCCESS);
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout), 0,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
 
        return (ISC_R_SUCCESS);
 }
index d31497095996b311db3f1f9e58bf9817cafd5a08..c0d643773a5c695bd5ad515d981af6e1dfe93c50 100644 (file)
@@ -308,67 +308,45 @@ static int loglevel = 0;
 
 static void
 setup_logging(FILE *errout) {
-       isc_result_t result;
        int packetlevel = 10;
 
+       isc_log_setdebuglevel(loglevel);
+
        isc_logconfig_t *logconfig = isc_logconfig_get();
-       isc_logdestination_t destination = {
-               .file.stream = errout,
-               .file.versions = ISC_LOG_ROLLNEVER,
-       };
-       isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
-                             ISC_LOG_DYNAMIC, &destination,
-                             ISC_LOG_PRINTPREFIX);
 
-       isc_log_setdebuglevel(loglevel);
        isc_log_settag(logconfig, ";; ");
 
-       result = isc_log_usechannel(logconfig, "stderr",
-                                   ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
-       if (result != ISC_R_SUCCESS) {
-               fatal("Couldn't attach to log channel 'stderr'");
-       }
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout),
+               ISC_LOG_PRINTPREFIX, ISC_LOGCATEGORY_DEFAULT,
+               ISC_LOGMODULE_DEFAULT);
 
        if (resolve_trace && loglevel < 1) {
-               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,
-                                           DNS_LOGMODULE_RESOLVER);
-               if (result != ISC_R_SUCCESS) {
-                       fatal("Couldn't attach to log channel 'resolver'");
-               }
+               isc_log_createandusechannel(
+                       logconfig, "resolver", ISC_LOG_TOFILEDESC,
+                       ISC_LOG_DEBUG(1), ISC_LOGDESTINATION_FILE(errout),
+                       ISC_LOG_PRINTPREFIX, DNS_LOGCATEGORY_RESOLVER,
+                       DNS_LOGMODULE_RESOLVER);
        }
 
        if (validator_trace && loglevel < 3) {
-               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,
-                                           DNS_LOGMODULE_VALIDATOR);
-               if (result != ISC_R_SUCCESS) {
-                       fatal("Couldn't attach to log channel 'validator'");
-               }
+               isc_log_createandusechannel(
+                       logconfig, "validator", ISC_LOG_TOFILEDESC,
+                       ISC_LOG_DEBUG(3), ISC_LOGDESTINATION_FILE(errout),
+                       ISC_LOG_PRINTPREFIX, DNS_LOGCATEGORY_DNSSEC,
+                       DNS_LOGMODULE_VALIDATOR);
        }
 
        if (send_trace) {
                packetlevel = 11;
        }
        if ((message_trace || send_trace) && loglevel < packetlevel) {
-               isc_log_createchannel(logconfig, "messages", ISC_LOG_TOFILEDESC,
-                                     ISC_LOG_DEBUG(packetlevel), &destination,
-                                     ISC_LOG_PRINTPREFIX);
-
-               result = isc_log_usechannel(logconfig, "messages",
-                                           DNS_LOGCATEGORY_RESOLVER,
-                                           DNS_LOGMODULE_PACKETS);
-               if (result != ISC_R_SUCCESS) {
-                       fatal("Couldn't attach to log channel 'messagse'");
-               }
+               isc_log_createandusechannel(
+                       logconfig, "messages", ISC_LOG_TOFILEDESC,
+                       ISC_LOG_DEBUG(packetlevel),
+                       ISC_LOGDESTINATION_FILE(errout), ISC_LOG_PRINTPREFIX,
+                       DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS);
        }
 }
 
index 36bd07cc43f785b1aec501de7ec8bfc9b0ef04f6..27a216490e31f3acd9f192f5b25fd8d3db4ca2cf 100644 (file)
@@ -1360,11 +1360,10 @@ setup_libs(void) {
        isc_managers_create(&mctx, 1, &loopmgr, &netmgr);
 
        logconfig = isc_logconfig_get();
-       result = isc_log_usechannel(logconfig, "default_debug",
-                                   ISC_LOGCATEGORY_ALL, ISC_LOGMODULE_ALL);
-
-       check_result(result, "isc_log_usechannel");
-
+       isc_log_createandusechannel(logconfig, "debug", ISC_LOG_TOFILEDESC,
+                                   ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+                                   ISC_LOG_PRINTTIME, ISC_LOGCATEGORY_DEFAULT,
+                                   ISC_LOGMODULE_DEFAULT);
        isc_log_setdebuglevel(0);
 
        isc_mem_setname(mctx, "dig");
index a34d12685a6f34aeeafa0749a7f8f8df5f399612..0d1163f8c6a2f42cc7d7007e3c989c6e1f729b35 100644 (file)
@@ -129,7 +129,6 @@ sig_format(dns_rdata_rrsig_t *sig, char *cp, unsigned int size) {
 
 void
 setup_logging(void) {
-       isc_logdestination_t destination;
        isc_logconfig_t *logconfig = NULL;
        int level;
 
@@ -162,17 +161,11 @@ setup_logging(void) {
         *  - the program name and logging level are printed
         *  - no time stamp is printed
         */
-       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);
-
-       RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
-                                        ISC_LOGCATEGORY_ALL,
-                                        ISC_LOGMODULE_ALL) == ISC_R_SUCCESS);
+       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);
 }
 
 static isc_stdtime_t
index 3023b34ee03b22b1f96937494681796be0c024e9..e477bd43ff644345a60b3f501f4b9942753c6bbe 100644 (file)
@@ -162,7 +162,6 @@ named_log_setdefaultsslkeylogfile(isc_logconfig_t *lcfg) {
                        .maximum_size = 100 * 1024 * 1024,
                },
        };
-       isc_result_t result;
 
        if (sslkeylogfile_path == NULL ||
            strcmp(sslkeylogfile_path, "config") == 0)
@@ -170,12 +169,10 @@ named_log_setdefaultsslkeylogfile(isc_logconfig_t *lcfg) {
                return;
        }
 
-       isc_log_createchannel(lcfg, "default_sslkeylogfile", ISC_LOG_TOFILE,
-                             ISC_LOG_INFO, &destination, 0);
-       result = isc_log_usechannel(lcfg, "default_sslkeylogfile",
-                                   ISC_LOGCATEGORY_SSLKEYLOG,
-                                   ISC_LOGMODULE_ALL);
-       RUNTIME_CHECK(result == ISC_R_SUCCESS);
+       isc_log_createandusechannel(lcfg, "default_sslkeylogfile",
+                                   ISC_LOG_TOFILE, ISC_LOG_INFO, &destination,
+                                   0, ISC_LOGCATEGORY_SSLKEYLOG,
+                                   ISC_LOGMODULE_DEFAULT);
 }
 
 isc_result_t
@@ -183,7 +180,8 @@ named_log_setdefaultcategory(isc_logconfig_t *lcfg) {
        isc_result_t result = ISC_R_SUCCESS;
 
        result = isc_log_usechannel(lcfg, "default_debug",
-                                   ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
+                                   ISC_LOGCATEGORY_DEFAULT,
+                                   ISC_LOGMODULE_DEFAULT);
        if (result != ISC_R_SUCCESS) {
                goto cleanup;
        }
@@ -192,11 +190,11 @@ named_log_setdefaultcategory(isc_logconfig_t *lcfg) {
                if (named_g_logfile != NULL) {
                        result = isc_log_usechannel(lcfg, "default_logfile",
                                                    ISC_LOGCATEGORY_DEFAULT,
-                                                   ISC_LOGMODULE_ALL);
+                                                   ISC_LOGMODULE_DEFAULT);
                } else if (!named_g_nosyslog) {
                        result = isc_log_usechannel(lcfg, "default_syslog",
                                                    ISC_LOGCATEGORY_DEFAULT,
-                                                   ISC_LOGMODULE_ALL);
+                                                   ISC_LOGMODULE_DEFAULT);
                }
        }
 
@@ -209,6 +207,6 @@ named_log_setunmatchedcategory(isc_logconfig_t *lcfg) {
        isc_result_t result;
 
        result = isc_log_usechannel(lcfg, "null", NAMED_LOGCATEGORY_UNMATCHED,
-                                   ISC_LOGMODULE_ALL);
+                                   ISC_LOGMODULE_DEFAULT);
        return (result);
 }
index 530b44b4816844a576f7f314db435689853832aa..c27e672b8a05e42c3e0963578f40ce43773aa992 100644 (file)
@@ -44,7 +44,6 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
        isc_result_t result;
        const char *catname;
        isc_logcategory_t category;
-       isc_logmodule_t module;
        const cfg_obj_t *destinations = NULL;
        const cfg_listelt_t *element = NULL;
 
@@ -63,8 +62,6 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
                return (ISC_R_SUCCESS);
        }
 
-       module = ISC_LOGMODULE_ALL;
-
        destinations = cfg_tuple_get(ccat, "destinations");
        for (element = cfg_list_first(destinations); element != NULL;
             element = cfg_list_next(element))
@@ -73,7 +70,7 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
                const char *channelname = cfg_obj_asstring(channel);
 
                result = isc_log_usechannel(logconfig, channelname, category,
-                                           module);
+                                           ISC_LOGMODULE_DEFAULT);
                if (result != ISC_R_SUCCESS) {
                        isc_log_write(CFG_LOGCATEGORY_CONFIG,
                                      NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
index e7162889aa5f8f418c355e96b787933efb9852fa..8285fa4aba9b75df23fa70edc0415d8415fac0a6 100644 (file)
@@ -811,10 +811,10 @@ setup_system(void *arg ISC_ATTR_UNUSED) {
        ddebug("setup_system()");
 
        logconfig = isc_logconfig_get();
-       result = isc_log_usechannel(logconfig, "default_debug",
-                                   ISC_LOGCATEGORY_ALL, ISC_LOGMODULE_ALL);
-       check_result(result, "isc_log_usechannel");
-
+       isc_log_createandusechannel(logconfig, "debug", ISC_LOG_TOFILEDESC,
+                                   ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+                                   ISC_LOG_PRINTTIME, ISC_LOGCATEGORY_DEFAULT,
+                                   ISC_LOGMODULE_DEFAULT);
        isc_log_setdebuglevel(logdebuglevel);
 
        result = irs_resconf_load(gmctx, resolvconf, &resconf);
index 8f9e3cbe9f6be54307b6dd90041cd5a1051774c3..0cdc162bb7304675cd4617c1d12a3696733eb2fe 100644 (file)
@@ -807,7 +807,6 @@ main(int argc, char **argv) {
        isc_result_t result = ISC_R_SUCCESS;
        bool show_final_mem = false;
        isc_logconfig_t *logconfig = NULL;
-       isc_logdestination_t logdest;
        cfg_parser_t *pctx = NULL;
        cfg_obj_t *config = NULL;
        const char *keyname = NULL;
@@ -955,16 +954,11 @@ main(int argc, char **argv) {
 
        logconfig = isc_logconfig_get();
        isc_log_settag(logconfig, progname);
-       logdest.file.stream = stderr;
-       logdest.file.name = NULL;
-       logdest.file.versions = ISC_LOG_ROLLNEVER;
-       logdest.file.maximum_size = 0;
-       isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
-                             ISC_LOG_INFO, &logdest,
-                             ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
-       DO("enabling log channel",
-          isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_ALL,
-                             ISC_LOGMODULE_ALL));
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO,
+               ISC_LOGDESTINATION_STDERR,
+               ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL, ISC_LOGCATEGORY_DEFAULT,
+               ISC_LOGMODULE_DEFAULT);
 
        parse_config(rndc_mctx, keyname, &pctx, &config);
 
index 4ebd534f0df08d169825d1bd07411ae27f9dda47..a1bc055a2fd2d9014d6b9011b083aa08141db164 100644 (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) {
index 707279a5fd33bab6dbb14a25f7e52af2d4a9f36f..19dd16aaffad52830dbafa79dfd4efc9eae04352 100644 (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);
-
-       CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_"
-                                                                  "usechannel("
-                                                                  ")");
+       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);
+
        name = dns_fixedname_initname(&fname);
        isc_buffer_constinit(&buf, "example.", strlen("example."));
        isc_buffer_add(&buf, strlen("example."));
index 3b6203b631d13c468cd932b4e59087e2b4140e58..3eebb27ed095daa89301a7968265f9d0a8196b5f 100644 (file)
@@ -37,20 +37,11 @@ usage(void) {
  */
 static void
 setup_logging(FILE *errout) {
-       isc_logdestination_t destination;
-       isc_logconfig_t *logconfig = NULL;
-
-       logconfig = isc_logconfig_get();
-       destination.file.stream = errout;
-       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);
-
-       RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
-                                        ISC_LOGCATEGORY_ALL,
-                                        ISC_LOGMODULE_ALL) == ISC_R_SUCCESS);
+       isc_logconfig_t *logconfig = isc_logconfig_get();
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout), 0,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
 }
 
 int
index e117ce17a8d6aaf09f42b18ac38d2182a1487155..e1c3960b5a33e81575be58969065c709cc9156d5 100644 (file)
@@ -1132,17 +1132,17 @@ the following steps need to be taken to initialize it.
    null, and all other messages to syslog.
 
         result = isc_log_usechannel(lcfg, "default_stderr",
-                                    DNS_LOGCATEGORY_SECURITY, NULL);
+                                    DNS_LOGCATEGORY_SECURITY, ISC_LOGMODULE_DEFAULT);
         if (result != ISC_R_SUCCESS)
                 oops_it_didnt_work();
 
         result = isc_log_usechannel(lcfg, "null",
-                                    DNS_LOGCATEGORY_DATABASE, NULL);
+                                    DNS_LOGCATEGORY_DATABASE, ISC_LOGMODULE_DEFAULT);
         if (result != ISC_R_SUCCESS)
                 oops_it_didnt_work();
 
         result = isc_log_usechannel(lcfg, "default_syslog",
-                                    ISC_LOGCATEGORY_DEFAULT, NULL);
+                                    ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
         if (result != ISC_R_SUCCESS)
                 oops_it_didnt_work();
 
index d54d08cfc10a2f35b5a9db077f653a0adaf90ace..befb8a8095053e330590913998b426c22b656103 100644 (file)
 #include <isccfg/namedconf.h>
 
 static void
-check_result(isc_result_t result, const char *format, ...) {
-       va_list args;
-
-       if (result == ISC_R_SUCCESS) {
-               return;
-       }
-
-       va_start(args, format);
-       vfprintf(stderr, format, args);
-       va_end(args);
-       fprintf(stderr, ": %s\n", isc_result_totext(result));
-       exit(EXIT_FAILURE);
-}
-
-static void
-output(void *closure, const char *text, int textlen) {
-       UNUSED(closure);
+output(void *closure ISC_ATTR_UNUSED, const char *text, int textlen) {
        (void)fwrite(text, 1, textlen, stdout);
 }
 
@@ -54,12 +38,19 @@ usage(void) {
        exit(EXIT_FAILURE);
 }
 
+static void
+setup_logging(void) {
+       isc_logconfig_t *logconfig = isc_logconfig_get();
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, ISC_LOG_PRINTTIME,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
+}
+
 int
 main(int argc, char **argv) {
        isc_result_t result;
        isc_mem_t *mctx = NULL;
-       isc_logconfig_t *lcfg = NULL;
-       isc_logdestination_t destination;
        cfg_parser_t *pctx = NULL;
        cfg_obj_t *cfg = NULL;
        cfg_type_t *type = NULL;
@@ -71,20 +62,7 @@ main(int argc, char **argv) {
 
        isc_mem_create(&mctx);
 
-       /*
-        * Create and install the default channel.
-        */
-       lcfg = 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(lcfg, "_default", ISC_LOG_TOFILEDESC,
-                             ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
-
-       result = isc_log_usechannel(lcfg, "_default", ISC_LOGCATEGORY_ALL,
-                                   ISC_LOGMODULE_ALL);
-       check_result(result, "isc_log_usechannel()");
+       setup_logging();
 
        /*
         * Set the initial debug level.
index 0143bfa15fa3cc7431baf6ce9227bd5a3517a3c2..579e96e4ff3dfaa400f71da769d6c12a048d0579 100644 (file)
@@ -24,6 +24,7 @@
 #include <isc/formatcheck.h>
 #include <isc/lang.h>
 #include <isc/types.h>
+#include <isc/util.h>
 
 typedef struct isc_logconfig isc_logconfig_t; /*%< Log Configuration */
 
@@ -106,10 +107,9 @@ typedef enum {
 typedef enum isc_logcategory isc_logcategory_t; /*%< Log Category */
 enum isc_logcategory {
        /*%
-        * Do not log directly to DEFAULT.  Use another category.
-        * When in doubt, use GENERAL.
+        * Logging to DEFAULT will end with assertion failure.  Use another
+        * category.  When in doubt, use GENERAL.
         */
-       ISC_LOGCATEGORY_ALL = -2,
        ISC_LOGCATEGORY_INVALID = -1,
        /* isc categories */
        ISC_LOGCATEGORY_DEFAULT = 0,
@@ -162,10 +162,9 @@ enum isc_logcategory {
  */
 typedef enum isc_logmodule isc_logmodule_t; /*%< Log Module */
 enum isc_logmodule {
-       ISC_LOGMODULE_ALL = -2,
        ISC_LOGMODULE_INVALID = -1,
        /* isc modules */
-       ISC_LOGMODULE_NONE = 0,
+       ISC_LOGMODULE_DEFAULT = 0,
        ISC_LOGMODULE_SOCKET,
        ISC_LOGMODULE_TIME,
        ISC_LOGMODULE_INTERFACE,
@@ -234,10 +233,10 @@ enum isc_logmodule {
  * The isc_logfile structure is initialized as part of an isc_logdestination
  * before calling isc_log_createchannel().
  *
- * When defining an #ISC_LOG_TOFILE
- * channel the name, versions and maximum_size should be set before calling
- * isc_log_createchannel().  To define an #ISC_LOG_TOFILEDESC channel set only
- * the stream before the call.
+ * When defining an #ISC_LOG_TOFILE channel, the name, versions and
+ * maximum_size should be set before calling isc_log_createchannel().  To
+ * define an #ISC_LOG_TOFILEDESC channel set only the stream before the
+ * call.
  *
  * Setting maximum_size to zero implies no maximum.
  */
@@ -268,14 +267,16 @@ typedef union isc_logdestination {
        int           facility;
 } isc_logdestination_t;
 
-#define ISC_LOGDESTINATION_STDERR                               \
+#define ISC_LOGDESTINATION_FILE(errout)                         \
        (&(isc_logdestination_t){                               \
                .file = {                                       \
-                       .stream = stderr,                       \
+                       .stream = errout,                       \
                        .versions = ISC_LOG_ROLLNEVER,          \
                        .suffix = isc_log_rollsuffix_increment, \
                } })
 
+#define ISC_LOGDESTINATION_STDERR ISC_LOGDESTINATION_FILE(stderr)
+
 #define ISC_LOGDESTINATION_SYSLOG(f) \
        (&(isc_logdestination_t){ .facility = (f) })
 
@@ -473,50 +474,52 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
  * Requires:
  *\li  lcfg is a valid logging configuration.
  *
- *\li  category is NULL or has an id that is in the range of known ids.
+ *\li  category is ISC_LOGCATEGORY_DEFAULT or has an id that is in the range of
+ *     known ids.
  *
- *     module is NULL or has an id that is in the range of known ids.
+ *     module is ISC_LOGMODULE_DEFAULT or has an id that is in the range of
+ *     known ids.
  *
  * Ensures:
- *\li  #ISC_R_SUCCESS
- *             The channel will be used by the indicated category/module
- *             arguments.
- *
- *\li  #ISC_R_NOMEMORY
- *             If assignment for a specific category has been requested,
- *             the channel has not been associated with the indicated
- *             category/module arguments and no additional memory is
- *             used by the logging context.
- *             If assignment for all categories has been requested
- *             then _some_ may have succeeded (starting with category
- *             "default" and progressing through the order of categories
- *             passed to isc_log_registercategories()) and additional memory
- *             is being used by whatever assignments succeeded.
- *
- * Returns:
- *\li  #ISC_R_SUCCESS  Success
- *\li  #ISC_R_NOMEMORY Resource limit: Out of memory
+ *     The channel will be used by the indicated category/module
+ *     arguments.
  */
 
-/* Attention: next four comments PRECEDE code */
-/*!
+void
+isc_log_createandusechannel(isc_logconfig_t *lcfg, const char *name,
+                           unsigned int type, int level,
+                           const isc_logdestination_t *destination,
+                           unsigned int                flags,
+                           const isc_logcategory_t     category,
+                           const isc_logmodule_t       module);
+
+/*%<
+ * The isc_log_createchannel() and isc_log_usechannel() functions, combined
+ * into one.  (This is for use by utilities that have simpler logging
+ * requirements than named, and don't have to define and assign channels
+ * dynamically.)
+ */
+
+void
+isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
+             const char *format, ...) ISC_FORMAT_PRINTF(4, 5);
+/*%<
  *   \brief
  * Write a message to the log channels.
  *
  * Notes:
- *\li  lctx can be NULL; this is allowed so that programs which use
- *     libraries that use the ISC logging system are not required to
- *     also use it.
- *
  *\li  The format argument is a printf(3) string, with additional arguments
  *     as necessary.
  *
  * Requires:
- *\li  lctx is a valid logging context.
- *
  *\li  The category and module arguments must have ids that are in the
- *     range of known ids, as established by isc_log_registercategories()
- *     and isc_log_registermodules().
+ *     range of known ids.
+ *
+ *\li  category != ISC_LOGCATEGORY_DEFAULT.  ISC_LOGCATEGORY_DEFAULT is used
+ *     only to define channels.
+ *
+ *\li  module != ISC_LOGMODULE_DEFAULT.  ISC_LOGMODULE_DEFAULT is used
+ *     only to define channels.
  *
  *\li  level != #ISC_LOG_DYNAMIC.  ISC_LOG_DYNAMIC is used only to define
  *     channels, and explicit debugging level must be identified for
@@ -532,29 +535,25 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
  *\li  Nothing.  Failure to log a message is not construed as a
  *     meaningful error.
  */
-void
-isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
-             const char *format, ...)
 
-       ISC_FORMAT_PRINTF(4, 5);
-
-/*%
+void
+isc_log_vwrite(isc_logcategory_t category, isc_logmodule_t module, int level,
+              const char *format, va_list args) ISC_FORMAT_PRINTF(4, 0);
+/*%<
  * Write a message to the log channels.
  *
- * Notes:
- *\li  lctx can be NULL; this is allowed so that programs which use
- *     libraries that use the ISC logging system are not required to
- *     also use it.
- *
  *\li  The format argument is a printf(3) string, with additional arguments
  *     as necessary.
  *
  * Requires:
- *\li  lctx is a valid logging context.
- *
  *\li  The category and module arguments must have ids that are in the
- *     range of known ids, as established by isc_log_registercategories()
- *     and isc_log_registermodules().
+ *     range of known ids.
+ *
+ *\li  category != ISC_LOGCATEGORY_DEFAULT.  ISC_LOGCATEGORY_DEFAULT is used
+ *     only to define channels.
+ *
+ *\li  module != ISC_LOGMODULE_DEFAULT.  ISC_LOGMODULE_DEFAULT is used
+ *     only to define channels.
  *
  *\li  level != #ISC_LOG_DYNAMIC.  ISC_LOG_DYNAMIC is used only to define
  *     channels, and explicit debugging level must be identified for
@@ -570,11 +569,6 @@ isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
  *\li  Nothing.  Failure to log a message is not construed as a
  *     meaningful error.
  */
-void
-isc_log_vwrite(isc_logcategory_t category, isc_logmodule_t module, int level,
-              const char *format, va_list args)
-
-       ISC_FORMAT_PRINTF(4, 0);
 
 void
 isc_log_setdebuglevel(unsigned int level);
index eb9c4d0d7ab23423fcb6734959f1d272fcaa1dee..4073ce4182a726b9cdc70ff1dde6b3721d486af1 100644 (file)
@@ -210,7 +210,7 @@ static const char *categories_description[] = {
  */
 static const char *modules_description[] = {
        /* isc modules */
-       [ISC_LOGMODULE_NONE] = "no_module",
+       [ISC_LOGMODULE_DEFAULT] = "no_module",
        [ISC_LOGMODULE_SOCKET] = "socket",
        [ISC_LOGMODULE_TIME] = "time",
        [ISC_LOGMODULE_INTERFACE] = "interface",
@@ -486,7 +486,7 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
        REQUIRE(level >= ISC_LOG_CRITICAL);
        REQUIRE((flags & ~permitted) == 0);
 
-       /* XXXDCL find duplicate names? */
+       /* FIXME: find duplicate names? */
 
        mctx = lcfg->lctx->mctx;
 
@@ -552,10 +552,9 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
                   const isc_logmodule_t module) {
        REQUIRE(VALID_CONFIG(lcfg));
        REQUIRE(name != NULL);
-       REQUIRE(category == ISC_LOGCATEGORY_ALL ||
-               (category >= 0 && category < ISC_LOGCATEGORY_MAX));
-       REQUIRE(module == ISC_LOGMODULE_ALL ||
-               (module >= 0 && module < ISC_LOGMODULE_MAX));
+       REQUIRE(category >= ISC_LOGCATEGORY_DEFAULT &&
+               category < ISC_LOGCATEGORY_MAX);
+       REQUIRE(module >= ISC_LOGMODULE_DEFAULT && module < ISC_LOGMODULE_MAX);
 
        isc_logchannel_t *channel;
        for (channel = ISC_LIST_HEAD(lcfg->channels); channel != NULL;
@@ -570,14 +569,16 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
                return (ISC_R_NOTFOUND);
        }
 
-       if (category != ISC_LOGCATEGORY_ALL) {
+       if (category != ISC_LOGCATEGORY_DEFAULT) {
                assignchannel(lcfg, category, module, channel);
        } else {
                /*
                 * Assign to all categories.  Note that this includes
                 * the default channel.
                 */
-               for (size_t i = 0; i < ISC_LOGCATEGORY_MAX; i++) {
+               for (size_t i = ISC_LOGCATEGORY_DEFAULT;
+                    i < ISC_LOGCATEGORY_MAX; i++)
+               {
                        assignchannel(lcfg, i, module, channel);
                }
        }
@@ -594,6 +595,18 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
        return (ISC_R_SUCCESS);
 }
 
+void
+isc_log_createandusechannel(isc_logconfig_t *lcfg, const char *name,
+                           unsigned int type, int level,
+                           const isc_logdestination_t *destination,
+                           unsigned int flags,
+                           const isc_logcategory_t category,
+                           const isc_logmodule_t module) {
+       isc_log_createchannel(lcfg, name, type, level, destination, flags);
+       RUNTIME_CHECK(isc_log_usechannel(lcfg, name, category, module) ==
+                     ISC_R_SUCCESS);
+}
+
 void
 isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
              const char *format, ...) {
@@ -721,10 +734,9 @@ assignchannel(isc_logconfig_t *lcfg, const isc_logcategory_t category,
 
        isc_log_t *lctx = lcfg->lctx;
 
-       REQUIRE(category > ISC_LOGCATEGORY_INVALID &&
+       REQUIRE(category >= ISC_LOGCATEGORY_DEFAULT &&
                category < ISC_LOGCATEGORY_MAX);
-       REQUIRE(module == ISC_LOGMODULE_ALL ||
-               (module > ISC_LOGMODULE_INVALID && module < ISC_LOGMODULE_MAX));
+       REQUIRE(module >= ISC_LOGMODULE_DEFAULT && module < ISC_LOGMODULE_MAX);
 
        isc_logchannellist_t *new_item = isc_mem_get(lctx->mctx,
                                                     sizeof(*new_item));
@@ -1257,8 +1269,9 @@ isc_log_doit(isc_logcategory_t category, isc_logmodule_t module, int level,
        isc_result_t result;
 
        REQUIRE(isc__lctx == NULL || VALID_CONTEXT(isc__lctx));
-       REQUIRE(category >= 0 && category < ISC_LOGCATEGORY_MAX);
-       REQUIRE(module >= 0 && module < ISC_LOGMODULE_MAX);
+       REQUIRE(category > ISC_LOGCATEGORY_DEFAULT &&
+               category < ISC_LOGCATEGORY_MAX);
+       REQUIRE(module > ISC_LOGMODULE_DEFAULT && module < ISC_LOGMODULE_MAX);
        REQUIRE(level != ISC_LOG_DYNAMIC);
        REQUIRE(format != NULL);
 
@@ -1311,7 +1324,7 @@ isc_log_doit(isc_logcategory_t category, isc_logmodule_t module, int level,
                        category_channels = &default_channel;
                }
 
-               if (category_channels->module != ISC_LOGMODULE_ALL &&
+               if (category_channels->module != ISC_LOGMODULE_DEFAULT &&
                    category_channels->module != module)
                {
                        category_channels = ISC_LIST_NEXT(category_channels,
index 83a0fd05d98f79e387f5cebd201ad6ee044ae8ce..8c55bc5fe6ec7d45c15b92b681b1dd201200b9b8 100644 (file)
@@ -2596,7 +2596,7 @@ isc__netmgr_log(const isc_nm_t *netmgr, int level, const char *fmt, ...) {
        vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
        va_end(ap);
 
-       isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR, level,
+       isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, level,
                      "netmgr %p: %s", netmgr, msgbuf);
 }
 
@@ -2613,7 +2613,7 @@ isc__nmsocket_log(const isc_nmsocket_t *sock, int level, const char *fmt, ...) {
        vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
        va_end(ap);
 
-       isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR, level,
+       isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, level,
                      "socket %p: %s", sock, msgbuf);
 }
 
@@ -2673,7 +2673,7 @@ isc__nm_received_proxy_header_log(isc_nmhandle_t *handle,
                       real_peer_fmt, real_local_fmt, proto);
 
        if (cmd == ISC_PROXY2_CMD_LOCAL) {
-               isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR,
+               isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR,
                              log_level, "%s: command: LOCAL (%s)", common_msg,
                              real_addresses_msg);
                return;
@@ -2686,7 +2686,7 @@ isc__nm_received_proxy_header_log(isc_nmhandle_t *handle,
 
                switch (socktype) {
                case 0:
-                       isc_log_write(ISC_LOGCATEGORY_DEFAULT,
+                       isc_log_write(ISC_LOGCATEGORY_GENERAL,
                                      ISC_LOGMODULE_NETMGR, log_level,
                                      "%s: command: PROXY (unspecified address "
                                      "and socket type, %s)",
@@ -2714,7 +2714,7 @@ isc__nm_received_proxy_header_log(isc_nmhandle_t *handle,
                        dst_addr_msg = dst_addr_fmt;
                }
 
-               isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR,
+               isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR,
                              log_level,
                              "%s: command: PROXY, socket type: %s, source: "
                              "%s, destination: %s, TLVs: %s",
index 6c3678bb35d926f03177d4906d11fd2cbd7a9ad8..6e0a544eee83337ff7e05a25a0ec39c2df69c7e8 100644 (file)
@@ -153,26 +153,15 @@ init_items(isc_mem_t *mctx) {
 
 static void
 init_logging(void) {
-       isc_result_t result;
-       isc_logdestination_t destination;
-       isc_logconfig_t *logconfig = NULL;
-
-       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,
-                             ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME |
-                                     ISC_LOG_ISO8601);
 #if VERBOSE
        isc_log_setdebuglevel(7);
 #endif
-
-       result = isc_log_usechannel(logconfig, "stderr",
-                                   ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
-       INSIST(result == ISC_R_SUCCESS);
+       isc_logconfig_t *logconfig = isc_logconfig_get();
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+               ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME | ISC_LOG_ISO8601,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
 }
 
 static void
index 04392c0b680b5cf74f60ad64ac43d16693c0aa37..5bb9262cac406ad857a17659c9472606169532a6 100644 (file)
 
 static void
 setup_logging(void) {
-       isc_result_t result;
-       isc_logdestination_t destination;
-       isc_logconfig_t *logconfig = NULL;
-
-       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,
-                             ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME |
-                                     ISC_LOG_ISO8601);
-
 #if VERBOSE
        isc_log_setdebuglevel(7);
 #endif
-
-       result = isc_log_usechannel(logconfig, "stderr",
-                                   ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       isc_logconfig_t *logconfig = isc_logconfig_get();
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+               ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME | ISC_LOG_ISO8601,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
 }
 
 static struct {
index 37e8b79c3bb2e622f988d9db46a6c1035407dff3..4a727d597bc6a73add97e0ceb7cae50c3ad4bfb5 100644 (file)
 #include <tests/isc.h>
 
 ISC_SETUP_TEST_IMPL(group) {
-       isc_result_t result;
-
        isc_logconfig_t *logconfig = isc_logconfig_get();
-       isc_logdestination_t destination = {
-               .file.stream = stderr,
-               .file.versions = ISC_LOG_ROLLNEVER,
-       };
-       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) {
-               return (-1);
-       }
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, 0,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
 
        return (0);
 }
index 1181f2fcde06db9ccde0943c37e2489c0442ae9f..cae29941eb69ef07118a166ee56aa8c4a1f391e8 100644 (file)
 #include <tests/isc.h>
 
 ISC_SETUP_TEST_IMPL(group) {
-       isc_result_t result;
        isc_logconfig_t *logconfig = isc_logconfig_get();
-       isc_logdestination_t destination = {
-               .file.stream = stderr,
-               .file.versions = ISC_LOG_ROLLNEVER,
-       };
-       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) {
-               return (-1);
-       }
+       isc_log_createandusechannel(
+               logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+               ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, 0,
+               ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
 
        return (0);
 }