]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 663] respect ntpq -c and -p order on command line.
authorDave Hart <hart@ntp.org>
Sat, 12 Sep 2009 07:25:45 +0000 (07:25 +0000)
committerDave Hart <hart@ntp.org>
Sat, 12 Sep 2009 07:25:45 +0000 (07:25 +0000)
bk: 4aab4cf9-HS0Zhx1WHUrAwJvDX_T8Q

ChangeLog
ntpq/ntpq-opts.def
ntpq/ntpq.c

index 59f9fee9fdf1899c56cc3cf4358e5f3527744289..c64a826fdb55f90ff1875924f025cc3b5d01f80f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 663] respect ntpq -c and -p order on command line.
 (4.2.5p210) 2009/09/06 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1294] Use OPENSSL_INC and OPENSSL_LIB macros for Windows
   and remove unnecessary reference to applink.c for Windows
index 928bd9df9b361fc975011067928f95a7c1a19890..9cbed0ab0b7a31a63eac97cfb7965a4f15dd35db 100644 (file)
@@ -41,7 +41,7 @@ flag = {
     descrip   = "run a command and exit";
     max       = NOLIMIT;
     arg-name  = cmd;
-    stack-arg;
+    call-proc = ntpq_custom_opt_handler;
     doc = <<-  _EndOfDoc_
        The following argument is interpreted as an interactive format command
        and is added to the list of commands to be executed on the specified
@@ -56,6 +56,7 @@ flag = {
     value     = p;
     descrip   = "Print a list of the peers";
     flags-cant = interactive;
+    call-proc = ntpq_custom_opt_handler;
     doc = <<-  _EndOfDoc_
        Print a list of the peers known to the server as well as a summary
        of their state. This is equivalent to the 'peers' interactive command.
index 86efb13ae36e70d6c03372a337a7e4be338c68c6..73170ade7f6ec347014a6209e5a2e395e49cbdcc 100644 (file)
@@ -292,6 +292,7 @@ static      int     assoccmp        (const void *, const void *);
 #else
 static int     assoccmp        (struct association *, struct association *);
 #endif /* sgi || bsdi */
+void   ntpq_custom_opt_handler (tOptions *, tOptDesc *);
 
 
 /*
@@ -537,6 +538,11 @@ ntpqmain(
                argv += optct;
        }
 
+       /*
+        * Process options other than -c and -p, which are specially
+        * handled by ntpq_custom_opt_handler().
+        */
+
        switch (WHICH_IDX_IPV4) {
            case INDEX_OPT_IPV4:
                ai_fam_templ = AF_INET;
@@ -549,15 +555,6 @@ ntpqmain(
                break;
        }
 
-       if (HAVE_OPT(COMMAND)) {
-               int             cmdct = STACKCT_OPT( COMMAND );
-               const char**    cmds  = STACKLST_OPT( COMMAND );
-
-               while (cmdct-- > 0) {
-                       ADDCMD(*cmds++);
-               }
-       }
-
        debug = DESC(DEBUG_LEVEL).optOccCt;
 
        if (HAVE_OPT(INTERACTIVE)) {
@@ -568,10 +565,6 @@ ntpqmain(
                showhostnames = 0;
        }
 
-       if (HAVE_OPT(PEERS)) {
-               ADDCMD("peers");
-       }
-
 #if 0
        while ((c = ntp_getopt(argc, argv, "46c:dinp")) != EOF)
            switch (c) {
@@ -3378,3 +3371,34 @@ assoccmp(
 }
 #endif /* not QSORT_USES_VOID_P */
 
+/*
+ * ntpq_custom_opt_handler - autoopts handler for -c and -p
+ *
+ * By default, autoopts loses the relative order of -c and -p options
+ * on the command line.  This routine replaces the default handler for
+ * those routines and builds a list of commands to execute preserving
+ * the order.
+ */
+void
+ntpq_custom_opt_handler(
+       tOptions *pOptions,
+       tOptDesc *pOptDesc
+       )
+{
+       switch (pOptDesc->optValue) {
+       
+       default:
+               fprintf(stderr, 
+                       "ntpq_custom_opt_handler unexpected option '%c' (%d)\n",
+                       pOptDesc->optValue, pOptDesc->optValue);
+               exit(-1);
+
+       case 'c':
+               ADDCMD(pOptDesc->pzLastArg);
+               break;
+
+       case 'p':
+               ADDCMD("peers");
+               break;
+       }
+}