mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 18:35:06 -05:00
sys_timex: fix update of TAI offset on non-Linux systems
The tai field in struct timex is a Linux-specific feature. It's possible to read the current offset with ntp_gettime() (or ntp_gettimex() on Linux), but apparently not all libc implementations support it. Rework the code to save and adjust the last value instead of reading the current value from the kernel.
This commit is contained in:
15
sys_timex.c
15
sys_timex.c
@@ -63,6 +63,9 @@
|
||||
/* Saved timex status */
|
||||
static int sys_status;
|
||||
|
||||
/* Saved TAI-UTC offset */
|
||||
static int sys_tai_offset;
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static double
|
||||
@@ -115,10 +118,17 @@ set_leap(int leap, int tai_offset)
|
||||
txc.status = sys_status;
|
||||
|
||||
#ifdef MOD_TAI
|
||||
if (tai_offset && tai_offset != txc.tai) {
|
||||
if (tai_offset) {
|
||||
txc.modes |= MOD_TAI;
|
||||
txc.constant = tai_offset;
|
||||
LOG(LOGS_INFO, "System clock TAI offset set to %d seconds", tai_offset);
|
||||
|
||||
if (applied && !(sys_status & (STA_INS | STA_DEL)))
|
||||
sys_tai_offset += prev_status & STA_INS ? 1 : -1;
|
||||
|
||||
if (sys_tai_offset != tai_offset) {
|
||||
sys_tai_offset = tai_offset;
|
||||
LOG(LOGS_INFO, "System clock TAI offset set to %d seconds", tai_offset);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -177,6 +187,7 @@ initialise_timex(void)
|
||||
struct timex txc;
|
||||
|
||||
sys_status = STA_UNSYNC;
|
||||
sys_tai_offset = 0;
|
||||
|
||||
/* Reset PLL offset */
|
||||
txc.modes = MOD_OFFSET | MOD_STATUS;
|
||||
|
||||
Reference in New Issue
Block a user