[ntp:questions] Programmatically monitoring / controlling NTP service
Martin Burnicki
martin.burnicki at meinberg.de
Tue Jan 31 09:05:55 UTC 2012
Robert,
Robert Hegner wrote:
> I'm developing a distributed system where time synchronization is done using NTP. I'd like to give the user the possibility to do some basic monitoring / controlling of all the NTP clients in the system from the main control program. So for example I'd like to show the status of all remote NTP clients like Meinberg's NTP Time Server Monitor does.
>
> Is there some library I can link against to gain access to the local (or even better: a remote) instance of the NTP service?
>
> I took a look into the sources of NTP and noticed that there is a static library called libntp. But I didn't find any documentation of what that library exactly does.
>
> Can I use that library in my own software for the purpose described above? I would also be happy to get some links (to documentation) and hints to get started.
>
> Btw, I'm aware of the ntpq and ntpdc command line tools. But I'd prefer direct access via (dynamic) library.
Basically libntp has been written to do exactly this, and is based on
the source code of ntpq.
The problem is that this code is not thread-safe.
ntpq stores some data between subsequent calls to the running ntpd in
some global variables. In this case this doesn't matter since it's a
single process which only talks to one instance of ntpd at the same time.
The libntp code has only minor changes to allow using the functionality
of ntpq from an own application. However, since this still uses global
variables, the functionality is messed up if the libntp functions are
called from several threads.
IMO, a proper solution would be to collect all global variables required
by ntpq in a data structure, use something like "open()" to create an
instance of this data structure for each ntpd node to be accessed, and
let open() return the pointer to this structure (like a FILE *) which
can then be used with subsequent library calls.
This approach would make libntp thread safe, and the optimum solution
would be (once more IMO) if the ntpq program would make use of this
library to avoid duplicate code in the NTP code base.
Martin
--
Martin Burnicki
Meinberg Funkuhren
Bad Pyrmont
Germany
More information about the questions
mailing list