]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] named -L option for default logfile
authorEvan Hunt <each@isc.org>
Wed, 30 Apr 2014 00:17:03 +0000 (17:17 -0700)
committerEvan Hunt <each@isc.org>
Wed, 30 Apr 2014 00:17:03 +0000 (17:17 -0700)
3832. [func] "named -L <filename>" causes named to send log
messages to the specified file by default instead
of to the system log. (Thanks to Tony Finch.)
[RT #35845]

CHANGES
README
bin/named/include/named/globals.h
bin/named/log.c
bin/named/main.c
bin/named/named.docbook
bin/tests/system/logfileconfig/clean.sh
bin/tests/system/logfileconfig/ns1/named.plainconf [new file with mode: 0644]
bin/tests/system/logfileconfig/tests.sh

diff --git a/CHANGES b/CHANGES
index 9248edd7a7683fc8bc94f22802d67ceb52b48e75..47bd4b4e11e7d6500b73797741143aa573e1a0fe 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+3832.  [func]          "named -L <filename>" causes named to send log
+                       messages to the specified file by default instead
+                       of to the system log. (Thanks to Tony Finch.)
+                       [RT #35845]
+
 3831.  [cleanup]       Reduce logging noise when EDNS state changes occur.
                        [RT #35843]
 
diff --git a/README b/README
index 499e3f5fe8e91004239ed827e2d80c1906296a06..824a87642d9414ca3914c1dbf67ef0bad4c7f32d 100644 (file)
--- a/README
+++ b/README
@@ -68,6 +68,8 @@ BIND 9.11.0
          the serial number will be set to the current date in YYYYMMDDNN
          format.
        - "dnssec-signzone -N date" sets the serial number to YYYYMMDDNN.
+       - "named -L <filename>" causes named to send log messages to
+          the specified file by default instead of to the system log.
 
 BIND 9.10.0
 
index 8ed18d1a0868189f378e99c1990b074a092e583e..3c261d3b5919df0e467219db65ac95b8fc3b255e 100644 (file)
@@ -128,6 +128,7 @@ EXTERN const char *         ns_g_chrootdir          INIT(NULL);
 EXTERN isc_boolean_t           ns_g_foreground         INIT(ISC_FALSE);
 EXTERN isc_boolean_t           ns_g_logstderr          INIT(ISC_FALSE);
 EXTERN isc_boolean_t           ns_g_nosyslog           INIT(ISC_FALSE);
+EXTERN const char *            ns_g_logfile            INIT(NULL);
 
 EXTERN const char *            ns_g_defaultsessionkeyfile
                                        INIT(NS_LOCALSTATEDIR "/run/named/"
index a34dea47ecb71e2eb22ca533b2de8cfca0eaa857..9f1b0fa2154e0b832eb2e9963b3702e2a744c2f7 100644 (file)
@@ -138,6 +138,22 @@ ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
                        goto cleanup;
        }
 
+       if (ns_g_logfile != NULL) {
+               destination.file.stream = NULL;
+               destination.file.name = ns_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_DYNAMIC,
+                                              &destination,
+                                              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",
@@ -161,9 +177,7 @@ ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
 isc_result_t
 ns_log_setsafechannels(isc_logconfig_t *lcfg) {
        isc_result_t result;
-#if ISC_FACILITY != LOG_DAEMON
        isc_logdestination_t destination;
-#endif
 
        if (! ns_g_logstderr) {
                result = isc_log_createchannel(lcfg, "default_debug",
@@ -182,6 +196,22 @@ ns_log_setsafechannels(isc_logconfig_t *lcfg) {
                isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
        }
 
+       if (ns_g_logfile != NULL) {
+               destination.file.stream = NULL;
+               destination.file.name = ns_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_DYNAMIC,
+                                              &destination,
+                                              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",
@@ -199,21 +229,23 @@ ns_log_setsafechannels(isc_logconfig_t *lcfg) {
 
 isc_result_t
 ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
-       isc_result_t result;
-
-       if (! ns_g_logstderr && ! ns_g_nosyslog) {
-               result = isc_log_usechannel(lcfg, "default_syslog",
-                                           ISC_LOGCATEGORY_DEFAULT, NULL);
-               if (result != ISC_R_SUCCESS)
-                       goto cleanup;
-       }
+       isc_result_t result = ISC_R_SUCCESS;
 
        result = isc_log_usechannel(lcfg, "default_debug",
                                    ISC_LOGCATEGORY_DEFAULT, NULL);
        if (result != ISC_R_SUCCESS)
                goto cleanup;
 
-       result = ISC_R_SUCCESS;
+       if (! ns_g_logstderr) {
+               if (ns_g_logfile != NULL)
+                       result = isc_log_usechannel(lcfg, "default_logfile",
+                                                   ISC_LOGCATEGORY_DEFAULT,
+                                                   NULL);
+               else if (! ns_g_nosyslog)
+                       result = isc_log_usechannel(lcfg, "default_syslog",
+                                                   ISC_LOGCATEGORY_DEFAULT,
+                                                   NULL);
+       }
 
  cleanup:
        return (result);
index b2104adda75959127b1d1aba56016e269e66df24..a6856bbe28bffefe400e40a20121cd999564dae4 100644 (file)
@@ -421,7 +421,7 @@ parse_command_line(int argc, char *argv[]) {
        save_command_line(argc, argv);
 
        /* PLEASE keep options synchronized when main is hooked! */
-#define CMDLINE_FLAGS "46c:C:d:D:E:fFgi:lm:n:N:p:P:sS:t:T:U:u:vVx:"
+#define CMDLINE_FLAGS "46c:C:d:D:E:fFgi:lL:m:n:N:p:P:sS:t:T:U:u:vVx:"
        isc_commandline_errprint = ISC_FALSE;
        while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
                switch (ch) {
@@ -478,6 +478,9 @@ parse_command_line(int argc, char *argv[]) {
                case 'l':
                        ns_g_lwresdonly = ISC_TRUE;
                        break;
+               case 'L':
+                       ns_g_logfile = isc_commandline_argument;
+                       break;
                case 'm':
                        set_flags(isc_commandline_argument, mem_debug_flags,
                                  &isc_mem_debugging);
index 595b207fefccd271a41e791922db0f0c79660a3e..0440feaa5a13e1a489e473010337030edc563205 100644 (file)
@@ -66,6 +66,7 @@
       <arg><option>-E <replaceable class="parameter">engine-name</replaceable></option></arg>
       <arg><option>-f</option></arg>
       <arg><option>-g</option></arg>
+      <arg><option>-L <replaceable class="parameter">logfile</replaceable></option></arg>
       <arg><option>-m <replaceable class="parameter">flag</replaceable></option></arg>
       <arg><option>-n <replaceable class="parameter">#cpus</replaceable></option></arg>
       <arg><option>-p <replaceable class="parameter">port</replaceable></option></arg>
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>-L <replaceable class="parameter">logfile</replaceable></term>
+        <listitem>
+          <para>
+            Log to the file <option>logfile</option> by default
+            instead of the system log.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>-m <replaceable class="parameter">flag</replaceable></term>
         <listitem>
index 0ceadbac7b09170e4550a7307697abddb52ba726..a63f0f01306505c79baa9fe5bfbdc4c598287829 100644 (file)
@@ -24,3 +24,4 @@ rm -f ns1/named.memstats ns1/dig.out
 rm -f ns1/named_log ns1/named_pipe ns1/named_sym
 rm -f ns1/named.conf
 rm -rf ns1/named_dir
+rm -f ns1/named_deflog
diff --git a/bin/tests/system/logfileconfig/ns1/named.plainconf b/bin/tests/system/logfileconfig/ns1/named.plainconf
new file mode 100644 (file)
index 0000000..3c5f900
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+options {
+       query-source address 10.53.0.1;
+       notify-source 10.53.0.1;
+       transfer-source 10.53.0.1;
+       port 5300;
+       pid-file "named.pid";
+       listen-on port 5300 {
+               10.53.0.1;
+       };
+       listen-on-v6 { none; };
+       recursion no;
+       notify yes;
+};
+
+controls {
+    inet 127.0.0.1 port 9593 allow {
+                        127.0.0.1/32; ::1/128; }
+                        keys { "rndc-key"; };
+};
+
+key "rndc-key" {
+       algorithm hmac-sha256;
+       secret "Am9vCg==";
+};
+
+zone "." {
+       type master;
+       file "root.db";
+};
index 3c4f52241f133c17025794b0de023f220690e5f8..d00848a1ddb8e8af789f58f0713dd0958978f230 100644 (file)
@@ -24,10 +24,12 @@ PLAINCONF="${THISDIR}/${CONFDIR}/named.plain"
 DIRCONF="${THISDIR}/${CONFDIR}/named.dirconf"
 PIPECONF="${THISDIR}/${CONFDIR}/named.pipeconf"
 SYMCONF="${THISDIR}/${CONFDIR}/named.symconf"
+PLAINCONF="${THISDIR}/${CONFDIR}/named.plainconf"
 PLAINFILE="named_log"
 DIRFILE="named_dir"
 PIPEFILE="named_pipe"
 SYMFILE="named_sym"
+DLFILE="named_deflog"
 PIDFILE="${THISDIR}/${CONFDIR}/named.pid"
 myRNDC="$RNDC -c ${THISDIR}/${CONFDIR}/rndc.conf"
 myNAMED="$NAMED -c ${THISDIR}/${CONFDIR}/named.conf -m record,size,mctx -T clienttest -T nosyslog -d 99 -U 4"
@@ -227,5 +229,27 @@ else
        echo "I: skipping symlink test (unable to create symlink)"
 fi
 
+status=0
+
+# Now stop the server again and test the -L option
+rm -f $DLFILE
+$myRNDC stop
+cp $PLAINCONF named.conf
+$myNAMED -L $DLFILE > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+       echo "I:failed to start $myNAMED"
+       echo "I:exit status: $status"
+       exit $status
+fi
+
+sleep 1
+if [ -f "$DLFILE" ]; then
+        echo "I: testing default logfile using named -L succeeded"
+else
+       echo "I:testing default logfile using named -L failed"
+       echo "I:exit status: 1"
+       exit 1
+fi
+
 echo "I:exit status: $status"
 exit $status