[ntp:questions] Deciding whether NTP is synchronised?

Juliusz Chroboczek jch at pps.jussieu.fr
Fri Apr 24 18:45:38 UTC 2009


Hi,

How can a userspace application decide whether the current time is
trustworthy?

For a project of mine, I need to reliably find out whether the system
time is within 5 minutes of UTC.  The network will include both
unmanaged client nodes and routers that don't have a battery backed
clock, so incorrect time is rather common.

False negatives are okay (the system will work if clocks are detected as
broken, just a little less efficiently), but false positives would have
some rather unpleasant consequences.

I'm currently using the following on my Linux nodes:

    rc = adjtimex(&timex);
    return (rc >= 0 && rc != TIME_ERROR);

On BSD nodes, I'm doing:

    rc = ntp_gettime(&ntptv);
    return (rc >= 0 && ntptv.time_state != TIME_ERROR);

Is that correct?  Or is there a better way?

                                        Juliusz




More information about the questions mailing list