]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2191. [func] named-checkzone now allows dumping to stdout (-).
authorMark Andrews <marka@isc.org>
Mon, 21 May 2007 02:47:25 +0000 (02:47 +0000)
committerMark Andrews <marka@isc.org>
Mon, 21 May 2007 02:47:25 +0000 (02:47 +0000)
                        named-checkconf now has -h for help.
                        named-checkzone now has -h for help.
                        Better handling of '-?' for usage summaries.
                        [RT #16707]

13 files changed:
CHANGES
bin/check/check-tool.c
bin/check/check-tool.h
bin/check/named-checkconf.c
bin/check/named-checkconf.docbook
bin/check/named-checkzone.c
bin/check/named-checkzone.docbook
bin/dnssec/dnssec-keygen.c
bin/dnssec/dnssec-signzone.c
bin/named/main.c
bin/nsupdate/nsupdate.c
bin/rndc/rndc-confgen.c
bin/rndc/rndc.c

diff --git a/CHANGES b/CHANGES
index b82b286dc15f793ad36e7f8e4b79cd8033cefd0d..fee85dcfad6b54e23d51249408f781c4f3eb16f3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+2191.  [func]          named-checkzone now allows dumping to stdout (-).
+                       named-checkconf now has -h for help.
+                       named-checkzone now has -h for help.
+                       Better handling of '-?' for usage summaries.
+                       [RT #16707]
+
 2190.  [func]          Make fallback to plain DNS from EDNS due to timeouts
                        more visible.  New logging category "edns-disabled".
                        [RT #16871]
index cb98066eede40eeeb4e9e10a107d0173e5ab2167..6f48b7db5fe8cae15676ce338823321fbe20c792 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: check-tool.c,v 1.26 2006/07/21 07:11:56 marka Exp $ */
+/* $Id: check-tool.c,v 1.27 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -494,7 +494,7 @@ checksrv(dns_zone_t *zone, dns_name_t *name, dns_name_t *owner) {
 }
 
 isc_result_t
-setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
+setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
        isc_logdestination_t destination;
        isc_logconfig_t *logconfig = NULL;
        isc_log_t *log = NULL;
@@ -506,7 +506,7 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
        dns_log_setcontext(log);
        cfg_log_init(log);
 
-       destination.file.stream = stdout;
+       destination.file.stream = errout;
        destination.file.name = NULL;
        destination.file.versions = ISC_LOG_ROLLNEVER;
        destination.file.maximum_size = 0;
@@ -590,14 +590,14 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
        FILE *output = stdout;
 
        if (debug) {
-               if (filename != NULL)
+               if (filename != NULL && strcmp(filename, "-") != 0)
                        fprintf(stderr, "dumping \"%s\" to \"%s\"\n",
                                zonename, filename);
                else
                        fprintf(stderr, "dumping \"%s\"\n", zonename);
        }
 
-       if (filename != NULL) {
+       if (filename != NULL && strcmp(filename, "-") != 0) {
                result = isc_stdio_open(filename, "w+", &output);
 
                if (result != ISC_R_SUCCESS) {
@@ -609,7 +609,7 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
 
        result = dns_zone_dumptostream2(zone, output, fileformat, style);
 
-       if (filename != NULL)
+       if (output != stdout)
                (void)isc_stdio_close(output);
 
        return (result);
index d6b78ad4260b50fbdf3d753d67e4c8b9bd63bd9b..23b4b722afaed34da735345d084eb5ecd9036a29 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: check-tool.h,v 1.11 2005/06/20 01:03:48 marka Exp $ */
+/* $Id: check-tool.h,v 1.12 2007/05/21 02:47:25 marka Exp $ */
 
 #ifndef CHECK_TOOL_H
 #define CHECK_TOOL_H
@@ -23,6 +23,7 @@
 /*! \file */
 
 #include <isc/lang.h>
+#include <isc/stdio.h>
 #include <isc/types.h>
 
 #include <dns/masterdump.h>
@@ -31,7 +32,7 @@
 ISC_LANG_BEGINDECLS
 
 isc_result_t
-setup_logging(isc_mem_t *mctx, isc_log_t **logp);
+setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp);
 
 isc_result_t
 load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
index be834bcb79b3230d45f2eced9a5f0e25b91c676e..32686483cd31541d3ea25d5bf353b4fed8b486fa 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named-checkconf.c,v 1.42 2006/02/28 02:39:51 marka Exp $ */
+/* $Id: named-checkconf.c,v 1.43 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -47,6 +47,8 @@
 
 #include "check-tool.h"
 
+static const char *program = "named-checkconf";
+
 isc_log_t *logc = NULL;
 
 #define CHECK(r)\
@@ -59,8 +61,8 @@ isc_log_t *logc = NULL;
 /*% usage */
 static void
 usage(void) {
-        fprintf(stderr, "usage: named-checkconf [-j] [-v] [-z] [-t directory] "
-               "[named.conf]\n");
+        fprintf(stderr, "usage: %s [-h] [-j] [-v] [-z] [-t directory] "
+               "[named.conf]\n", program);
         exit(1);
 }
 
@@ -397,7 +399,9 @@ main(int argc, char **argv) {
        isc_entropy_t *ectx = NULL;
        isc_boolean_t load_zones = ISC_FALSE;
        
-       while ((c = isc_commandline_parse(argc, argv, "djt:vz")) != EOF) {
+       isc_commandline_errprint = ISC_FALSE;
+
+       while ((c = isc_commandline_parse(argc, argv, "dhjt:vz")) != EOF) {
                switch (c) {
                case 'd':
                        debug++;
@@ -433,11 +437,22 @@ main(int argc, char **argv) {
                        dochecksrv = ISC_FALSE;
                        break;
 
-               default:
+               case '?':
+                       if (isc_commandline_option != '?')
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       program, isc_commandline_option);
+               case 'h':
                        usage();
+
+               default:
+                       fprintf(stderr, "%s: unhandled option -%c\n",
+                               program, isc_commandline_option);
+                       exit(1);
                }
        }
 
+       if (isc_commandline_index + 1 < argc)
+               usage();
        if (argv[isc_commandline_index] != NULL)
                conffile = argv[isc_commandline_index];
        if (conffile == NULL || conffile[0] == '\0')
@@ -445,7 +460,7 @@ main(int argc, char **argv) {
 
        RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
 
-       RUNTIME_CHECK(setup_logging(mctx, &logc) == ISC_R_SUCCESS);
+       RUNTIME_CHECK(setup_logging(mctx, stdout, &logc) == ISC_R_SUCCESS);
 
        RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
        RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
index d04395cf2ff4be4969f6884b58fe4e064380115e..f3f88efa6416c82b2e215ea8bbf18545509983a3 100644 (file)
@@ -18,7 +18,7 @@
  - PERFORMANCE OF THIS SOFTWARE.
 -->
 
-<!-- $Id: named-checkconf.docbook,v 1.16 2007/05/09 01:32:08 marka Exp $ -->
+<!-- $Id: named-checkconf.docbook,v 1.17 2007/05/21 02:47:25 marka Exp $ -->
 <refentry id="man.named-checkconf">
   <refentryinfo>
     <date>June 14, 2000</date>
@@ -53,6 +53,7 @@
   <refsynopsisdiv>
     <cmdsynopsis>
       <command>named-checkconf</command>
+      <arg><option>-h</option></arg>
       <arg><option>-v</option></arg>
       <arg><option>-j</option></arg>
       <arg><option>-t <replaceable class="parameter">directory</replaceable></option></arg>
     <title>OPTIONS</title>
 
     <variablelist>
+      <varlistentry>
+        <term>-h</term>
+        <listitem>
+          <para>
+            Print the usage summary and exit.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>-t <replaceable class="parameter">directory</replaceable></term>
         <listitem>
index cd96b0b86d53f7a9e061551acef1d2a46db1e52e..36f38e5ad4640c5693bf29978284466f52765e25 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named-checkzone.c,v 1.47 2007/03/29 23:47:04 tbox Exp $ */
+/* $Id: named-checkzone.c,v 1.48 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -105,6 +105,7 @@ main(int argc, char **argv) {
        const char *outputformatstr = NULL;
        dns_masterformat_t inputformat = dns_masterformat_text;
        dns_masterformat_t outputformat = dns_masterformat_text;
+       FILE *errout = stdout;
 
        outputstyle = &dns_master_style_full;
 
@@ -139,8 +140,10 @@ main(int argc, char **argv) {
 
 #define ARGCMP(X) (strcmp(isc_commandline_argument, X) == 0)
 
+       isc_commandline_errprint = ISC_FALSE;
+
        while ((c = isc_commandline_parse(argc, argv,
-                                         "c:df:i:jk:m:n:qs:t:o:vw:DF:M:S:W:"))
+                                        "c:df:hi:jk:m:n:qs:t:o:vw:DF:M:S:W:"))
               != EOF) {
                switch (c) {
                case 'c':
@@ -342,17 +345,17 @@ main(int argc, char **argv) {
                                zone_options &= ~DNS_ZONEOPT_CHECKWILDCARD;
                        break;
 
-               default:
+               case '?':
+                       if (isc_commandline_option != '?')
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       prog_name, isc_commandline_option);
+               case 'h':
                        usage();
-               }
-       }
 
-       if (progmode == progmode_compile) {
-               dumpzone = 1;   /* always dump */
-               if (output_filename == NULL) {
-                       fprintf(stderr,
-                               "output file required, but not specified\n");
-                       usage();
+               default:
+                       fprintf(stderr, "%s: unhandled option -%c\n",
+                                prog_name, isc_commandline_option);
+                       exit(1);
                }
        }
 
@@ -389,12 +392,36 @@ main(int argc, char **argv) {
                }
        }
 
-       if (isc_commandline_index + 2 > argc)
+       if (progmode == progmode_compile) {
+               dumpzone = 1;   /* always dump */
+               if (output_filename == NULL) {
+                       fprintf(stderr,
+                               "output file required, but not specified\n");
+                       usage();
+               }
+       }
+
+       if (output_filename != NULL)
+               dumpzone = 1;
+
+       /*
+        * If we are outputing to stdout then send the informational
+        * output to stderr.
+        */
+       if (dumpzone &&
+           (output_filename == NULL ||
+            strcmp(output_filename, "-") == 0 ||
+            strcmp(output_filename, "/dev/fd/1") == 0 ||
+            strcmp(output_filename, "/dev/stdout") == 0))
+               errout = stderr;
+
+       if (isc_commandline_index + 2 != argc)
                usage();
 
        RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
        if (!quiet)
-               RUNTIME_CHECK(setup_logging(mctx, &lctx) == ISC_R_SUCCESS);
+               RUNTIME_CHECK(setup_logging(mctx, errout, &lctx)
+                             == ISC_R_SUCCESS);
        RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
        RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
                      == ISC_R_SUCCESS);
@@ -408,17 +435,17 @@ main(int argc, char **argv) {
 
        if (result == ISC_R_SUCCESS && dumpzone) {
                if (!quiet && progmode == progmode_compile) {
-                       fprintf(stdout, "dump zone to %s...", output_filename);
-                       fflush(stdout);
+                       fprintf(errout, "dump zone to %s...", output_filename);
+                       fflush(errout);
                }
                result = dump_zone(origin, zone, output_filename,
                                   outputformat, outputstyle);
                if (!quiet && progmode == progmode_compile)
-                       fprintf(stdout, "done\n");
+                       fprintf(errout, "done\n");
        }
 
        if (!quiet && result == ISC_R_SUCCESS)
-               fprintf(stdout, "OK\n");
+               fprintf(errout, "OK\n");
        destroy();
        if (lctx != NULL)
                isc_log_destroy(&lctx);
index 54c0f886777287343a4f28ae138ea4028b72d237..486a4cdbef9fee9bee229ccedced13cf26c70cab 100644 (file)
@@ -18,7 +18,7 @@
  - PERFORMANCE OF THIS SOFTWARE.
 -->
 
-<!-- $Id: named-checkzone.docbook,v 1.31 2007/05/09 06:18:44 marka Exp $ -->
+<!-- $Id: named-checkzone.docbook,v 1.32 2007/05/21 02:47:25 marka Exp $ -->
 <refentry id="man.named-checkzone">
   <refentryinfo>
     <date>June 13, 2000</date>
@@ -56,6 +56,7 @@
     <cmdsynopsis>
       <command>named-checkzone</command>
       <arg><option>-d</option></arg>
+      <arg><option>-h</option></arg>
       <arg><option>-j</option></arg>
       <arg><option>-q</option></arg>
       <arg><option>-v</option></arg>
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>-h</term>
+        <listitem>
+          <para>
+            Print the usage summary and exit.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>-q</term>
         <listitem>
         <listitem>
           <para>
             Write zone output to <filename>filename</filename>.
+           If <filename>filename</filename> is <filename>-</filename> then
+           write to standard out.
            This is mandatory for <command>named-compilezone</command>.
           </para>
         </listitem>
index e21375717ed66524908fc230186bb4d7e3a62f03..ab6f06dc9f09d3ba1d0feb763c4994ae11f9b3c6 100644 (file)
@@ -16,7 +16,7 @@
  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dnssec-keygen.c,v 1.75 2007/01/09 23:49:38 marka Exp $ */
+/* $Id: dnssec-keygen.c,v 1.76 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -134,8 +134,10 @@ main(int argc, char **argv) {
 
        dns_result_register();
 
+       isc_commandline_errprint = ISC_FALSE;
+
        while ((ch = isc_commandline_parse(argc, argv,
-                                          "a:b:c:d:ef:g:kn:t:p:s:r:v:h")) != -1)
+                                        "a:b:c:d:ef:g:kn:t:p:s:r:v:h")) != -1)
        {
            switch (ch) {
                case 'a':
@@ -202,12 +204,17 @@ main(int argc, char **argv) {
                                fatal("-v must be followed by a number");
                        break;
 
+               case '?':
+                       if (isc_commandline_option != '?')
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       program, isc_commandline_option);
                case 'h':
                        usage();
+
                default:
-                       fprintf(stderr, "%s: invalid argument -%c\n",
-                               program, ch);
-                       usage();
+                       fprintf(stderr, "%s: unhandled option -%c\n",
+                               program, isc_commandline_option);
+                       exit(1);
                }
        }
 
index c1a8750d52ebe0491ddfbbe733d7ed804c0eb0b8..b3313683139f1583f13c139e5f5c6db036ea1348 100644 (file)
@@ -16,7 +16,7 @@
  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dnssec-signzone.c,v 1.201 2007/05/18 23:46:58 tbox Exp $ */
+/* $Id: dnssec-signzone.c,v 1.202 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -1862,8 +1862,10 @@ main(int argc, char *argv[]) {
 
        dns_result_register();
 
+       isc_commandline_errprint = ISC_FALSE;
+
        while ((ch = isc_commandline_parse(argc, argv,
-                                          "ac:d:e:f:ghi:I:j:k:l:n:N:o:O:pr:s:Stv:z"))
+                                   "ac:d:e:f:ghi:I:j:k:l:n:N:o:O:pr:s:Stv:z"))
               != -1) {
                switch (ch) {
                case 'a':
@@ -1890,11 +1892,19 @@ main(int argc, char *argv[]) {
                        generateds = ISC_TRUE;
                        break;
 
+               case '?':
+                       if (isc_commandline_option != '?')
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       program, isc_commandline_option);
                case 'h':
-               default:
                        usage();
                        break;
 
+               default:
+                       fprintf(stderr, "%s: unhandled option -%c\n",
+                               program, isc_commandline_option);
+                       exit(1);
+
                case 'i':
                        endp = NULL;
                        cycle = strtol(isc_commandline_argument, &endp, 0);
index cc0bbe1754203d27e2d2c70f8852a45ac0b55022..c69193c5ee1afffee3271abc0073129461bf8ba9 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: main.c,v 1.154 2006/12/21 06:02:29 marka Exp $ */
+/* $Id: main.c,v 1.155 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -447,6 +447,8 @@ parse_command_line(int argc, char *argv[]) {
                        exit(0);
                case '?':
                        usage();
+                       if (isc_commandline_option == '?')
+                               exit(0);
                        ns_main_earlyfatal("unknown option '-%c'",
                                           isc_commandline_option);
                default:
index 18e75946e3a8ee353579c6f87127ba51a207cd1b..4a00d2366571d7236d3087a7f9d41378f5c32ea7 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: nsupdate.c,v 1.149 2007/04/24 07:02:31 marka Exp $ */
+/* $Id: nsupdate.c,v 1.150 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -847,13 +847,19 @@ parse_args(int argc, char **argv) {
                                exit(1);
                        }
                        break;
-               default:
-                       fprintf(stderr, "%s: invalid argument -%c\n",
-                               argv[0], ch);
+               case '?':
+                       if (isc_commandline_option != '?')
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       argv[0], isc_commandline_option);
                        fprintf(stderr, "usage: nsupdate [-d] "
                                "[-g | -o | -y keyname:secret | -k keyfile] "
                                "[-v] [filename]\n");
                        exit(1);
+
+               default:
+                       fprintf(stderr, "%s: unhandled option: %c\n",
+                               argv[0], isc_commandline_option);
+                       exit(1);
                }
        }
        if (keyfile != NULL && keystr != NULL) {
index 3c1797038136434b503445597108753405c45fdd..467488f8c5a5f3f7a6317798d5cbfb82bf5c1395 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: rndc-confgen.c,v 1.21 2005/04/29 00:22:35 marka Exp $ */
+/* $Id: rndc-confgen.c,v 1.22 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -160,6 +160,8 @@ main(int argc, char **argv) {
        serveraddr = DEFAULT_SERVER;
        port = DEFAULT_PORT;
 
+       isc_commandline_errprint = ISC_FALSE;
+
        while ((ch = isc_commandline_parse(argc, argv,
                                           "ab:c:hk:Mmp:r:s:t:u:Vy")) != -1) {
                switch (ch) {
@@ -214,12 +216,17 @@ main(int argc, char **argv) {
                        verbose = ISC_TRUE;
                        break;
                case '?':
-                       usage(1);
+                       if (isc_commandline_option != '?') {
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       program, isc_commandline_option);
+                               usage(1);
+                       } else
+                               usage(0);
                        break;
                default:
-                       fatal("unexpected error parsing command arguments: "
-                             "got %c\n", ch);
-                       break;
+                       fprintf(stderr, "%s: unhandled option -%c\n",
+                               program, isc_commandline_option);
+                       exit(1);
                }
        }
 
index 80f446352ad5500484df3a705b58940c5bd06c19..378eee09a5193fb197a355a44b80407a5c0e0f3b 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: rndc.c,v 1.114 2006/12/04 01:52:45 marka Exp $ */
+/* $Id: rndc.c,v 1.115 2007/05/21 02:47:25 marka Exp $ */
 
 /*! \file */
 
@@ -690,6 +690,8 @@ main(int argc, char **argv) {
        if (result != ISC_R_SUCCESS)
                fatal("isc_app_start() failed: %s", isc_result_totext(result));
 
+       isc_commandline_errprint = ISC_FALSE;
+
        while ((ch = isc_commandline_parse(argc, argv, "b:c:k:Mmp:s:Vy:"))
               != -1) {
                switch (ch) {
@@ -741,13 +743,18 @@ main(int argc, char **argv) {
                        break;
  
                case '?':
+                       if (isc_commandline_option != '?') {
+                               fprintf(stderr, "%s: invalid argument -%c\n",
+                                       program, isc_commandline_option);
+                               usage(1);
+                       }
+               case 'h':
                        usage(0);
                        break;
-
                default:
-                       fatal("unexpected error parsing command arguments: "
-                             "got %c\n", ch);
-                       break;
+                       fprintf(stderr, "%s: unhandled option -%c\n",
+                               program, isc_commandline_option);
+                        exit(1);
                }
        }