If the refclock has the "tai" option set, get the current TAI offset and include it when adding the sample. --- refclock.c | 28 ++++++++++++++++++++++++++-- reference.c | 11 +++++++++++ reference.h | 3 +++ 3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/refclock.c b/refclock.c index 6ca9118..23dbe18 100644 --- a/refclock.c +++ b/refclock.c @@ -76,6 +76,7 @@ struct RCL_Instance_Record { int poll; int leap_status; int pps_forced; + int tai; int pps_rate; int pps_active; int max_lock_age; @@ -189,6 +190,12 @@ RCL_AddRefclock(RefclockParameters *params) return 0; } + if (params->tai && !CNF_GetLeapSecTimezone()) { + LOG(LOGS_WARN, + "Refclock %s configured for auto tai offset, but no leapsectz configured", + UTI_RefidToString(params->ref_id)); + } + inst->data = NULL; inst->driver_parameter = params->driver_parameter; inst->driver_parameter_length = 0; @@ -197,6 +204,7 @@ RCL_AddRefclock(RefclockParameters *params) inst->driver_polled = 0; inst->leap_status = LEAP_Normal; inst->pps_forced = params->pps_forced; + inst->tai = params->tai; inst->pps_rate = params->pps_rate; inst->pps_active = 0; inst->max_lock_age = params->max_lock_age; @@ -360,6 +368,7 @@ int RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset, int leap) { double correction, dispersion; + int tai_offset; struct timespec cooked_time; if (instance->pps_forced) @@ -385,10 +394,25 @@ RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset return 0; } - filter_add_sample(&instance->filter, &cooked_time, offset - correction + instance->offset, dispersion); + if (instance->tai) { + tai_offset = REF_GetTaiOffset(); + } else { + tai_offset = 0; + } + + filter_add_sample(&instance->filter, + &cooked_time, + offset - correction + instance->offset - tai_offset, + dispersion); instance->pps_active = 0; - log_sample(instance, &cooked_time, 0, 0, offset, offset - correction + instance->offset, dispersion); + log_sample(instance, + &cooked_time, + 0, + 0, + offset, + offset - correction + instance->offset - tai_offset, + dispersion); /* for logging purposes */ if (!instance->driver->poll) diff --git a/reference.c b/reference.c index 8138b8c..24b8543 100644 --- a/reference.c +++ b/reference.c @@ -1355,6 +1355,17 @@ int REF_IsLeapSecondClose(void) } /* ================================================== */ +int REF_GetTaiOffset(void) +{ + time_t now; + int tai_offset; + + now = time(NULL); + get_tz_leap(now, &tai_offset); + return tai_offset; +} + +/* ================================================== */ void REF_GetTrackingReport(RPT_TrackingReport *rep) diff --git a/reference.h b/reference.h index e376770..2311e93 100644 --- a/reference.h +++ b/reference.h @@ -184,6 +184,9 @@ extern void REF_DisableLocal(void); and is better to discard any measurements */ extern int REF_IsLeapSecondClose(void); +/* Return the current TAI - UTC offset calculated from timezone files */ +extern int REF_GetTaiOffset(void); + extern void REF_GetTrackingReport(RPT_TrackingReport *rep); #endif /* GOT_REFERENCE_H */ -- 2.13.5 -- To unsubscribe email chrony-dev-requ...@chrony.tuxfamily.org with "unsubscribe" in the subject. For help email chrony-dev-requ...@chrony.tuxfamily.org with "help" in the subject. Trouble? Email listmas...@chrony.tuxfamily.org.