]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1332] ntpq -c 'rv 0 variablename' returns extra stuff.
authorDave Hart <hart@ntp.org>
Mon, 5 Oct 2009 06:35:21 +0000 (06:35 +0000)
committerDave Hart <hart@ntp.org>
Mon, 5 Oct 2009 06:35:21 +0000 (06:35 +0000)
add ntpq --old-rv
fix ipv4/ipv6 which are not equivalent in the libopts sense

bk: 4ac993a9f_zwL_k0n6FmckQNIcvRmQ

ChangeLog
ntpq/ntpq-opts.c
ntpq/ntpq-opts.def
ntpq/ntpq-opts.h
ntpq/ntpq-opts.texi
ntpq/ntpq-subs.c
ntpq/ntpq.1
ntpq/ntpq.c
ntpq/ntpq.h

index 6ef0a9e8d451f5ed2d41c71892b6d332f3b53aab..4a516f40515c95e6345ff7e8edda8159abce0f4c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 * [Bug 1330] disallow interface/nic rules when --novirtualips or
   --interface are used.
+* [Bug 1332] ntpq -c 'rv 0 variablename' returns extra stuff.
 * Add test of ntpd --saveconfigquit fidelity using new complete.conf.
 * Documentation updates from Dave Hart/Dave Mills.
 (4.2.5p226) 2009/10/04 Released by Harlan Stenn <stenn@ntp.org>
index d2a65d38890e3d0d0fc8e125b0d62b74d40fef4a..d6e1153e8a70e0ea1f0a29095b03a99c3e3d376a 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  *  EDIT THIS FILE WITH CAUTION  (ntpq-opts.c)
  *  
- *  It has been AutoGen-ed  October  4, 2009 at 07:42:10 AM by AutoGen 5.9.9pre5
+ *  It has been AutoGen-ed  Monday October  5, 2009 at 06:18:35 AM UTC
  *  From the definitions    ntpq-opts.def
  *  and the template file   options
  *
@@ -19,7 +19,7 @@
  *
  * This source file is copyrighted and licensed under the following terms:
  *
- * ntpq copyright (c) 1970-2009 David L. Mills and/or others - all rights reserved
+ * ntpq copyright 1970-2009 David L. Mills and/or others - all rights reserved
  *
  * see html/copyright.html
  */
@@ -66,21 +66,29 @@ extern tUsageProc optionUsage;
 #  define  EXIT_FAILURE 1
 #endif
 /*
- *  Ipv4 option description:
+ *  Ipv4 option description with
+ *  "Must also have options" and "Incompatible options":
  */
 tSCC    zIpv4Text[] =
         "Force IPv4 DNS name resolution";
 tSCC    zIpv4_NAME[]               = "IPV4";
 tSCC    zIpv4_Name[]               = "ipv4";
+static const int
+    aIpv4CantList[] = {
+    INDEX_OPT_IPV6, NO_EQUIVALENT };
 #define IPV4_FLAGS       (OPTST_DISABLED)
 
 /*
- *  Ipv6 option description:
+ *  Ipv6 option description with
+ *  "Must also have options" and "Incompatible options":
  */
 tSCC    zIpv6Text[] =
         "Force IPv6 DNS name resolution";
 tSCC    zIpv6_NAME[]               = "IPV6";
 tSCC    zIpv6_Name[]               = "ipv6";
+static const int
+    aIpv6CantList[] = {
+    INDEX_OPT_IPV4, NO_EQUIVALENT };
 #define IPV6_FLAGS       (OPTST_DISABLED)
 
 /*
@@ -148,6 +156,15 @@ tSCC    zNumeric_NAME[]            = "NUMERIC";
 tSCC    zNumeric_Name[]            = "numeric";
 #define NUMERIC_FLAGS       (OPTST_DISABLED)
 
+/*
+ *  Old_Rv option description:
+ */
+tSCC    zOld_RvText[] =
+        "Always output status line with readvar";
+tSCC    zOld_Rv_NAME[]             = "OLD_RV";
+tSCC    zOld_Rv_Name[]             = "old-rv";
+#define OLD_RV_FLAGS       (OPTST_DISABLED)
+
 /*
  *  Help/More_Help/Version option descriptions:
  */
@@ -217,25 +234,25 @@ static tOptProc
  */
 static tOptDesc optDesc[ OPTION_CT ] = {
   {  /* entry idx, value */ 0, VALUE_OPT_IPV4,
-     /* equiv idx, value */ NO_EQUIVALENT, 0,
+     /* equiv idx, value */ 0, VALUE_OPT_IPV4,
      /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
      /* opt state flags  */ IPV4_FLAGS, 0,
      /* last opt argumnt */ { NULL },
      /* arg list/cookie  */ NULL,
-     /* must/cannot opts */ NULL, NULL,
+     /* must/cannot opts */ NULL, aIpv4CantList,
      /* option proc      */ NULL,
      /* desc, NAME, name */ zIpv4Text, zIpv4_NAME, zIpv4_Name,
      /* disablement strs */ NULL, NULL },
 
   {  /* entry idx, value */ 1, VALUE_OPT_IPV6,
-     /* equiv idx, value */ NOLIMIT, NOLIMIT,
-     /* equivalenced to  */ INDEX_OPT_IPV4,
+     /* equiv idx, value */ 1, VALUE_OPT_IPV6,
+     /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
      /* opt state flags  */ IPV6_FLAGS, 0,
      /* last opt argumnt */ { NULL },
      /* arg list/cookie  */ NULL,
-     /* must/cannot opts */ NULL, NULL,
+     /* must/cannot opts */ NULL, aIpv6CantList,
      /* option proc      */ NULL,
      /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name,
      /* disablement strs */ NULL, NULL },
@@ -312,6 +329,18 @@ static tOptDesc optDesc[ OPTION_CT ] = {
      /* desc, NAME, name */ zNumericText, zNumeric_NAME, zNumeric_Name,
      /* disablement strs */ NULL, NULL },
 
+  {  /* entry idx, value */ 8, VALUE_OPT_OLD_RV,
+     /* equiv idx, value */ 8, VALUE_OPT_OLD_RV,
+     /* equivalenced to  */ NO_EQUIVALENT,
+     /* min, max, act ct */ 0, 1, 0,
+     /* opt state flags  */ OLD_RV_FLAGS, 0,
+     /* last opt argumnt */ { NULL },
+     /* arg list/cookie  */ NULL,
+     /* must/cannot opts */ NULL, NULL,
+     /* option proc      */ NULL,
+     /* desc, NAME, name */ zOld_RvText, zOld_Rv_NAME, zOld_Rv_Name,
+     /* disablement strs */ NULL, NULL },
+
 #ifdef NO_OPTIONAL_OPT_ARGS
 #  define VERSION_OPT_FLAGS     OPTST_IMM | OPTST_NO_INIT
 #else
@@ -450,7 +479,7 @@ tOptions ntpqOptions = {
       NO_EQUIVALENT, /* '-#' option index */
       NO_EQUIVALENT /* index of default opt */
     },
-    13 /* full option count */, 8 /* user option count */,
+    14 /* full option count */, 9 /* user option count */,
     ntpq_full_usage, ntpq_short_usage,
     NULL, NULL
 };
index 9cbed0ab0b7a31a63eac97cfb7965a4f15dd35db..8845aa32045673f8e368cd0e34e1ff3a09e5ac17 100644 (file)
@@ -14,8 +14,8 @@ test-main;
 
 flag = {
     name      = ipv4;
+    flags-cant = ipv6;
     value     = 4;
-    equivalence = ipv4;
     descrip   = "Force IPv4 DNS name resolution";
     doc = <<-  _EndOfDoc_
        Force DNS resolution of following host names on the command line
@@ -25,8 +25,8 @@ flag = {
 
 flag = {
     name      = ipv6;
+    flags-cant = ipv4;
     value     = 6;
-    equivalence = ipv4;
     descrip   = "Force IPv6 DNS name resolution";
     doc = <<-  _EndOfDoc_
        Force DNS resolution of following host names on the command line
@@ -84,6 +84,20 @@ flag = {
        _EndOfDoc_;
 };
 
+flag = {
+    name      = old-rv;
+    descrip   = "Always output status line with readvar";
+    doc = <<-  _EndOfDoc_
+       By default, ntpq now suppresses the associd=... line that
+       precedes the output of "readvar" (alias "rv") when a single
+       variable is requested, such as ntpq -c "rv 0 offset".  This
+       option causes ntpq to include both lines of output for a
+       single-variable readvar.  Using an environment variable to
+       preset this option in a script will enable both older and
+       newer ntpq to behave identically in this regard.
+       _EndOfDoc_;
+};
+
 detail = <<-  _END_DETAIL
        The
        [= prog-name =]
index 5c82d6c7f89c955176e74b09098031bd3a38d613..dd73deed3e876d22cd124ea813bc4bfd5500b2b9 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  *  EDIT THIS FILE WITH CAUTION  (ntpq-opts.h)
  *  
- *  It has been AutoGen-ed  October  4, 2009 at 07:42:09 AM by AutoGen 5.9.9pre5
+ *  It has been AutoGen-ed  Monday October  5, 2009 at 06:18:35 AM UTC
  *  From the definitions    ntpq-opts.def
  *  and the template file   options
  *
@@ -19,7 +19,7 @@
  *
  * This source file is copyrighted and licensed under the following terms:
  *
- * ntpq copyright (c) 1970-2009 David L. Mills and/or others - all rights reserved
+ * ntpq copyright 1970-2009 David L. Mills and/or others - all rights reserved
  *
  * see html/copyright.html
  */
@@ -60,14 +60,15 @@ typedef enum {
     INDEX_OPT_PEERS            =  5,
     INDEX_OPT_INTERACTIVE      =  6,
     INDEX_OPT_NUMERIC          =  7,
-    INDEX_OPT_VERSION          =  8,
-    INDEX_OPT_HELP             =  9,
-    INDEX_OPT_MORE_HELP        = 10,
-    INDEX_OPT_SAVE_OPTS        = 11,
-    INDEX_OPT_LOAD_OPTS        = 12
+    INDEX_OPT_OLD_RV           =  8,
+    INDEX_OPT_VERSION          =  9,
+    INDEX_OPT_HELP             = 10,
+    INDEX_OPT_MORE_HELP        = 11,
+    INDEX_OPT_SAVE_OPTS        = 12,
+    INDEX_OPT_LOAD_OPTS        = 13
 } teOptIndex;
 
-#define OPTION_CT    13
+#define OPTION_CT    14
 #define NTPQ_VERSION       "4.2.5p226"
 #define NTPQ_FULL_VERSION  "ntpq - standard NTP query program - Ver. 4.2.5p226"
 
@@ -128,6 +129,10 @@ typedef enum {
 #  warning undefining NUMERIC due to option name conflict
 #  undef   NUMERIC
 # endif
+# ifdef    OLD_RV
+#  warning undefining OLD_RV due to option name conflict
+#  undef   OLD_RV
+# endif
 #else  /* NO_OPTION_NAME_WARNINGS */
 # undef IPV4
 # undef IPV6
@@ -137,6 +142,7 @@ typedef enum {
 # undef PEERS
 # undef INTERACTIVE
 # undef NUMERIC
+# undef OLD_RV
 #endif  /*  NO_OPTION_NAME_WARNINGS */
 
 /* * * * * *
@@ -144,8 +150,6 @@ typedef enum {
  *  Interface defines for specific options.
  */
 #define VALUE_OPT_IPV4           '4'
-#define WHICH_OPT_IPV4           (DESC(IPV4).optActualValue)
-#define WHICH_IDX_IPV4           (DESC(IPV4).optActualIndex)
 #define VALUE_OPT_IPV6           '6'
 #define VALUE_OPT_COMMAND        'c'
 #define VALUE_OPT_DEBUG_LEVEL    'd'
@@ -153,6 +157,7 @@ typedef enum {
 #define VALUE_OPT_PEERS          'p'
 #define VALUE_OPT_INTERACTIVE    'i'
 #define VALUE_OPT_NUMERIC        'n'
+#define VALUE_OPT_OLD_RV         8
 #define VALUE_OPT_HELP          '?'
 #define VALUE_OPT_MORE_HELP     '!'
 #define VALUE_OPT_VERSION       INDEX_OPT_VERSION
index 6fbf70e483a61630fd7bc5dfa6a39180abf684e3..3fd1cda76666f0e4f85230ee80185b79e0049d67 100644 (file)
@@ -6,7 +6,7 @@
 # 
 # EDIT THIS FILE WITH CAUTION  (ntpq-opts.texi)
 # 
-# It has been AutoGen-ed  October  4, 2009 at 07:42:13 AM by AutoGen 5.9.9pre5
+# It has been AutoGen-ed  Monday October  5, 2009 at 06:18:38 AM UTC
 # From the definitions    ntpq-opts.def
 # and the template file   aginfo.tpl
 @end ignore
@@ -34,6 +34,7 @@ This software is released under a specialized copyright license.
 * ntpq ipv4::                   ipv4 option (-4)
 * ntpq ipv6::                   ipv6 option (-6)
 * ntpq numeric::                numeric option (-n)
+* ntpq old-rv::                 old-rv option
 * ntpq peers::                  peers option (-p)
 * ntpq set-debug-level::        set-debug-level option (-D)
 @end menu
@@ -78,8 +79,8 @@ Options are specified by doubled hyphens and their name
 or by a single hyphen and the flag character.
 
 The following option preset mechanisms are supported:
- - reading file /users/stenn/.ntprc
- - reading file /deacon/backroom/snaps/ntp-dev/ntpq/.ntprc
+ - reading file /m/pogo/users/hart/.ntprc
+ - reading file /m/pogo/users/hart/ntp-dev-1332/ntpq/.ntprc
  - examining environment variables named NTPQ_*
 
 The
@@ -104,7 +105,8 @@ This is the ``force ipv4 dns name resolution'' option.
 This option has some usage constraints.  It:
 @itemize @bullet
 @item
-is a member of the ipv4 class of options.
+must not appear in combination with any of the following options:
+ipv6.
 @end itemize
 
 Force DNS resolution of following host names on the command line
@@ -119,7 +121,8 @@ This is the ``force ipv6 dns name resolution'' option.
 This option has some usage constraints.  It:
 @itemize @bullet
 @item
-is a member of the ipv4 class of options.
+must not appear in combination with any of the following options:
+ipv4.
 @end itemize
 
 Force DNS resolution of following host names on the command line
@@ -209,3 +212,16 @@ to the standard output and commands read from the standard input.
 This is the ``numeric host addresses'' option.
 Output all host addresses in dotted-quad numeric format rather than
 converting to the canonical host names. 
+
+@node ntpq old-rv
+@subsection old-rv option
+@cindex ntpq-old-rv
+
+This is the ``always output status line with readvar'' option.
+By default, ntpq now suppresses the associd=... line that
+precedes the output of "readvar" (alias "rv") when a single
+variable is requested, such as ntpq -c "rv 0 offset".  This
+option causes ntpq to include both lines of output for a
+single-variable readvar.  Using an environment variable to
+preset this option in a script will enable both older and
+newer ntpq to behave identically in this regard.
index a45b6c59e785b59206040e1edd6326d8963a7bb9..c371764f067da654b850022258884b792ed4030c 100644 (file)
@@ -7,8 +7,9 @@
 #include <sys/types.h>
 #include <sys/time.h>
 
-#include "ntpq.h"
 #include "ntp_stdlib.h"
+#include "ntpq.h"
+#include "ntpq-opts.h"
 
 extern char *  chosts[];
 extern char currenthost[];
@@ -24,23 +25,25 @@ static      void    doaddvlist      (struct varlist *, char *);
 static void    dormvlist       (struct varlist *, char *);
 static void    doclearvlist    (struct varlist *);
 static void    makequerydata   (struct varlist *, int *, char *);
-static int doquerylist (struct varlist *, int, int, int, u_short *, int *, char **);
+static int     doquerylist     (struct varlist *, int, int, int, 
+                                u_short *, int *, char **);
 static void    doprintvlist    (struct varlist *, FILE *);
 static void    addvars         (struct parse *, FILE *);
 static void    rmvars          (struct parse *, FILE *);
 static void    clearvars       (struct parse *, FILE *);
 static void    showvars        (struct parse *, FILE *);
-static int dolist              (struct varlist *, int, int, int, FILE *);
+static int     dolist          (struct varlist *, int, int, int,
+                                FILE *);
 static void    readlist        (struct parse *, FILE *);
 static void    writelist       (struct parse *, FILE *);
 static void    readvar         (struct parse *, FILE *);
 static void    writevar        (struct parse *, FILE *);
 static void    clocklist       (struct parse *, FILE *);
 static void    clockvar        (struct parse *, FILE *);
-static int findassidrange      (u_int32, u_int32, int *, int *);
+static int     findassidrange  (u_int32, u_int32, int *, int *);
 static void    mreadlist       (struct parse *, FILE *);
 static void    mreadvar        (struct parse *, FILE *);
-static int dogetassoc  (FILE *);
+static int     dogetassoc      (FILE *);
 static void    printassoc      (int, FILE *);
 static void    associations    (struct parse *, FILE *);
 static void    lassociations   (struct parse *, FILE *);
@@ -193,7 +196,7 @@ char flash3[] = " x.-+#*o"; /* flash decode for peer status version 3 */
 struct varlist {
        char *name;
        char *value;
-} varlist[MAXLIST] = { { 0, 0 } };
+} g_varlist[MAXLIST] = { { 0, 0 } };
 
 /*
  * Imported from ntpq.c
@@ -307,7 +310,7 @@ dormvlist(
                        free((void *)vl->name);
                        if (vl->value != 0)
                            free(vl->value);
-                       for ( ; (vl+1) < (varlist+MAXLIST)
+                       for ( ; (vl+1) < (g_varlist + MAXLIST)
                                      && (vl+1)->name != 0; vl++) {
                                vl->name = (vl+1)->name;
                                vl->value = (vl+1)->value;
@@ -441,7 +444,7 @@ addvars(
        FILE *fp
        )
 {
-       doaddvlist(varlist, pcmd->argval[0].string);
+       doaddvlist(g_varlist, pcmd->argval[0].string);
 }
 
 
@@ -455,7 +458,7 @@ rmvars(
        FILE *fp
        )
 {
-       dormvlist(varlist, pcmd->argval[0].string);
+       dormvlist(g_varlist, pcmd->argval[0].string);
 }
 
 
@@ -469,7 +472,7 @@ clearvars(
        FILE *fp
        )
 {
-       doclearvlist(varlist);
+       doclearvlist(g_varlist);
 }
 
 
@@ -483,7 +486,7 @@ showvars(
        FILE *fp
        )
 {
-       doprintvlist(varlist, fp);
+       doprintvlist(g_varlist, fp);
 }
 
 
@@ -503,6 +506,16 @@ dolist(
        int res;
        int dsize;
        u_short rstatus;
+       int quiet;
+
+       /*
+        * if we're asking for specific variables don't include the
+        * status header line in the output.
+        */
+       if (HAVE_OPT( OLD_RV ))
+               quiet = 0;
+       else
+               quiet = (vlist->name != NULL);
 
        res = doquerylist(vlist, op, associd, 0, &rstatus, &dsize, &datap);
 
@@ -522,8 +535,9 @@ dolist(
                return 1;
        }
 
-       (void) fprintf(fp,"associd=%d ",associd);
-       printvars(dsize, datap, (int)rstatus, type, fp);
+       if (!quiet)
+               fprintf(fp,"associd=%d ",associd);
+       printvars(dsize, datap, (int)rstatus, type, quiet, fp);
        return 1;
 }
 
@@ -549,7 +563,7 @@ readlist(
                        return;
        }
 
-       (void) dolist(varlist, associd, CTL_OP_READVAR,
+       (void) dolist(g_varlist, associd, CTL_OP_READVAR,
                          (associd == 0) ? TYPE_SYS : TYPE_PEER, fp);
 }
 
@@ -579,7 +593,7 @@ writelist(
                        return;
        }
 
-       res = doquerylist(varlist, CTL_OP_WRITEVAR, associd, 1, &rstatus,
+       res = doquerylist(g_varlist, CTL_OP_WRITEVAR, associd, 1, &rstatus,
                          &dsize, &datap);
 
        if (res != 0)
@@ -592,7 +606,7 @@ writelist(
        else {
                (void) fprintf(fp,"associd=%d ",associd);
                printvars(dsize, datap, (int)rstatus,
-                         (associd != 0) ? TYPE_PEER : TYPE_SYS, fp);
+                         (associd != 0) ? TYPE_PEER : TYPE_SYS, 0, fp);
        }
        return;
 }
@@ -667,7 +681,10 @@ writevar(
        else {
                (void) fprintf(fp,"associd=%d ",associd);
                printvars(dsize, datap, (int)rstatus,
-                         (associd != 0) ? TYPE_PEER : TYPE_SYS, fp);
+                         (associd != 0)
+                             ? TYPE_PEER 
+                             : TYPE_SYS, 
+                         0, fp);
        }
        return;
 }
@@ -694,7 +711,7 @@ clocklist(
                        return;
        }
 
-       (void) dolist(varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
+       (void) dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
 }
 
 
@@ -806,7 +823,7 @@ mreadlist(
        for (i = from; i <= to; i++) {
                if (i != from)
                        (void) fprintf(fp, "\n");
-               if (!dolist(varlist, (int)assoc_cache[i].assid,
+               if (!dolist(g_varlist, (int)assoc_cache[i].assid,
                                CTL_OP_READVAR, TYPE_PEER, fp))
                        return;
        }
@@ -840,7 +857,7 @@ mreadvar(
        for (i = from; i <= to; i++) {
                if (i != from)
                        (void) fprintf(fp, "\n");
-               if (!dolist(varlist, (int)assoc_cache[i].assid,
+               if (!dolist(g_varlist, (int)assoc_cache[i].assid,
                                CTL_OP_READVAR, TYPE_PEER, fp))
                        break;
        }
@@ -1246,7 +1263,7 @@ pstatus(
        }
 
        (void) fprintf(fp,"associd=%d ",associd);
-       printvars(dsize, datap, (int)rstatus, TYPE_PEER, fp);
+       printvars(dsize, datap, (int)rstatus, TYPE_PEER, 0, fp);
 }
 
 
index df34a8eabbaf0d241be49935ecb98b37ccbd87e1..855c5930c862f709b428255bf4c13d06bc01ecfe 100644 (file)
@@ -1,7 +1,7 @@
-.TH NTPQ 1 2009-10-04 "( 4.2.5p226)" "Programmer's Manual"
+.TH NTPQ 1 2009-10-05 "( 4.2.5p226)" "Programmer's Manual"
 .\"  EDIT THIS FILE WITH CAUTION  (ntpq.1)
 .\"  
-.\"  It has been AutoGen-ed  October  4, 2009 at 07:42:11 AM by AutoGen 5.9.9pre5
+.\"  It has been AutoGen-ed  Monday October  5, 2009 at 06:18:37 AM UTC
 .\"  From the definitions    ntpq-opts.def
 .\"  and the template file   agman1.tpl
 .\"
@@ -281,14 +281,16 @@ a timeout will be twice the timeout value set.
 .TP
 .BR \-4 ", " \--ipv4
 Force IPv4 DNS name resolution.
-This option is a member of the ipv4 class of options.
+This option must not appear in combination with any of the following options:
+ipv6.
 .sp
 Force DNS resolution of following host names on the command line
 to the IPv4 namespace.
 .TP
 .BR \-6 ", " \--ipv6
 Force IPv6 DNS name resolution.
-This option is a member of the ipv4 class of options.
+This option must not appear in combination with any of the following options:
+ipv4.
 .sp
 Force DNS resolution of following host names on the command line
 to the IPv6 namespace.
@@ -336,6 +338,17 @@ numeric host addresses.
 Output all host addresses in dotted-quad numeric format rather than
 converting to the canonical host names. 
 .TP
+.BR \--old-rv
+Always output status line with readvar.
+.sp
+By default, ntpq now suppresses the associd=... line that
+precedes the output of "readvar" (alias "rv") when a single
+variable is requested, such as ntpq \-c "rv 0 offset".  This
+option causes ntpq to include both lines of output for a
+single-variable readvar.  Using an environment variable to
+preset this option in a script will enable both older and
+newer ntpq to behave identically in this regard.
+.TP
 .BR \-? , " \--help"
 Display usage information and exit.
 .TP
index 5472b655885ac4b685fe73349b90f38114bf6942..c432376ed19c184b8828a1d89f245935cf16c1dc 100644 (file)
@@ -289,12 +289,12 @@ static    void    error           (const char *, const char *, const char *);
 static u_long  getkeyid        (const char *);
 static void    atoascii        (int, char *, char *);
 static void    makeascii       (int, char *, FILE *);
-static void    rawprint        (int, int, char *, int, FILE *);
+static void    cookedprint     (int, int, char *, int, int, FILE *);
+static void    rawprint        (int, int, char *, int, int, FILE *);
 static void    startoutput     (void);
 static void    output          (FILE *, char *, char *);
 static void    endoutput       (FILE *);
 static void    outputarr       (FILE *, char *, int, l_fp *);
-static void    cookedprint     (int, int, char *, int, FILE *);
 #ifdef QSORT_USES_VOID_P
 static int     assoccmp        (const void *, const void *);
 #else
@@ -536,27 +536,20 @@ ntpqmain(
         * handled by ntpq_custom_opt_handler().
         */
 
-       switch (WHICH_IDX_IPV4) {
-           case INDEX_OPT_IPV4:
+       debug = DESC(DEBUG_LEVEL).optOccCt;
+
+       if (HAVE_OPT(IPV4))
                ai_fam_templ = AF_INET;
-               break;
-           case INDEX_OPT_IPV6:
+       else if (HAVE_OPT(IPV6))
                ai_fam_templ = AF_INET6;
-               break;
-           default:
+       else
                ai_fam_templ = ai_fam_default;
-               break;
-       }
 
-       debug = DESC(DEBUG_LEVEL).optOccCt;
-
-       if (HAVE_OPT(INTERACTIVE)) {
+       if (HAVE_OPT(INTERACTIVE))
                interactive = 1;
-       }
 
-       if (HAVE_OPT(NUMERIC)) {
+       if (HAVE_OPT(NUMERIC))
                showhostnames = 0;
-       }
 
 #if 0
        while ((c = ntp_getopt(argc, argv, "46c:dinp")) != EOF)
@@ -2908,13 +2901,14 @@ printvars(
        char *data,
        int status,
        int sttype,
+       int quiet,
        FILE *fp
        )
 {
        if (rawmode)
-           rawprint(sttype, length, data, status, fp);
+           rawprint(sttype, length, data, status, quiet, fp);
        else
-           cookedprint(sttype, length, data, status, fp);
+           cookedprint(sttype, length, data, status, quiet, fp);
 }
 
 
@@ -2927,6 +2921,7 @@ rawprint(
        int length,
        char *data,
        int status,
+       int quiet,
        FILE *fp
        )
 {
@@ -2939,7 +2934,8 @@ rawprint(
        cp = data;
        cpend = data + length;
 
-       (void) fprintf(fp, "status=0x%04x,\n", status);
+       if (!quiet)
+               (void) fprintf(fp, "status=0x%04x,\n", status);
 
        while (cp < cpend) {
                if (*cp == '\r') {
@@ -2948,13 +2944,12 @@ rawprint(
                         * \n, supress this, else pretty print it.  Otherwise
                         * just output the character.
                         */
-                       if (cp == (cpend-1) || *(cp+1) != '\n')
+                       if (cp == (cpend - 1) || *(cp + 1) != '\n')
                            makeascii(1, cp, fp);
-               } else if (isspace((int)*cp) || isprint((int)*cp)) {
+               } else if (isspace(*cp) || isprint(*cp))
                        putc(*cp, fp);
-               } else {
+               else
                        makeascii(1, cp, fp);
-               }
                cp++;
        }
 }
@@ -3119,6 +3114,7 @@ cookedprint(
        int length,
        char *data,
        int status,
+       int quiet,
        FILE *fp
        )
 {
@@ -3150,8 +3146,9 @@ cookedprint(
                return;
        }
 
-       (void) fprintf(fp, "status=%04x %s,\n", status,
-                      statustoa(datatype, status));
+       if (!quiet)
+               (void) fprintf(fp, "status=%04x %s,\n", status,
+                              statustoa(datatype, status));
 
        startoutput();
        while (nextvar(&length, &data, &name, &value)) {
index 4da356c4e7b4f1d31080cfd2e7a5e7d0265dd198..ac95292c766ca890c6d6a2115d242dff9abe520e 100644 (file)
@@ -90,6 +90,6 @@ extern        int     decodets        (char *, l_fp *);
 extern int     decodeuint      (char *, u_long *);
 extern int     nextvar         (int *, char **, char **, char **);
 extern int     decodetime      (char *, l_fp *);
-extern void    printvars       (int, char *, int, int, FILE *);
+extern void    printvars       (int, char *, int, int, int, FILE *);
 extern int     decodeint       (char *, long *);
 extern int     findvar         (char *, struct ctl_var *, int code);