From: Dave Hart Date: Sat, 12 Sep 2009 07:25:45 +0000 (+0000) Subject: [Bug 663] respect ntpq -c and -p order on command line. X-Git-Tag: NTP_4_2_5P211~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6840b4d5f4121e487f801267b33a02b9a0a83e24;p=thirdparty%2Fntp.git [Bug 663] respect ntpq -c and -p order on command line. bk: 4aab4cf9-HS0Zhx1WHUrAwJvDX_T8Q --- diff --git a/ChangeLog b/ChangeLog index 59f9fee9f..c64a826fd 100644 --- 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 * [Bug 1294] Use OPENSSL_INC and OPENSSL_LIB macros for Windows and remove unnecessary reference to applink.c for Windows diff --git a/ntpq/ntpq-opts.def b/ntpq/ntpq-opts.def index 928bd9df9..9cbed0ab0 100644 --- a/ntpq/ntpq-opts.def +++ b/ntpq/ntpq-opts.def @@ -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. diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 86efb13ae..73170ade7 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -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; + } +}