MRU update status

Eric S. Raymond esr at thyrsus.com
Tue Dec 27 12:09:11 UTC 2016


Hal Murray <hmurray at megapathdsl.net>:
> My current problem is that I need to fix ntpq to not give up if it asks for a 
> slot that that ntpd doesn't support.  Can you either fix it, or give me some 
> guidance on where the fix should go?
> 
> You can test with "rv 0 leap,foo" and/or hacking in a bogus slot in one of 
> the tables such as the one used for monlist.
> 
> I'd be happy if it either skipped printing slots that don't exist, or printed 
> something conspicuous like "foo: ???" to indicate that the server doesn't 
> support that named value.

That's going to be slightly tricky; the Mode 6 protocol is not
designed to support it.

When you ship an explicit query list like "leap,foo" and one of the variable
names is unknown, the protocol handler in ntpd stops processing the request
immediately and ships back an error notification.  The problem is that this
error notification does not explicitly tell you which name was bad.

The simplest way to get the behavior you want would be to ship
requests for each variable in the list individually, watch which ones
produce an error response, and accumulate the dictionary of returned
values across those calls.

I recommend modifying the readvar() method of ControlSession so
that if the initial call to get all variables fails you do that loop.

> There is another area that could use some TCL.  ntp_control has several 
> tables that need to be kept in sync with some #define-s.  It's things like:
> 
> #define CS_LEAP                 1
> #define CS_STRATUM              2
> 
> static const struct ctl_var sys_var[] = {
>         { 0,            PADDING, "" },          /* 0 */
>         { CS_LEAP,      RW, "leap" },           /* 1 */
>         { CS_STRATUM,   RO, "stratum" },        /* 2 */
>         { CS_PRECISION, RO, "precision" },      /* 3 */
> 
> The problem is that they are long and there is no checking so it's easy to 
> screwup.  It's also a pain to add a new one.  You can either append it so the 
> editing is easy or insert it in the appropriate place and risk botching the 
> long chain of bump-by-1 edits that need to be done in two places.
> 
> Nobody cares what the value of CS_LEAP is, but the slot for it has to be at 
> that offset in the table.
> 
> We should be able to come up with a macro that will both assign the next tag 
> value and build a slot.  Have you done that before?  (Or know why it won't 
> work, or ...)

I don't think this can be done in the C macro language.  There's no counter
primitive to base it on.  The designers of Go apparently felt the lack; they
added one named 'iota'.

When I have to do this sort of thing, I write a small code generator
in Python.
--
		<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>


More information about the devel mailing list