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:
parent
4fe0e6b7fd
commit
760285218f
1 changed files with 13 additions and 2 deletions
13
sys_timex.c
13
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,11 +118,18 @@ 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;
|
||||
|
||||
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
|
||||
|
||||
SYS_Timex_Adjust(&txc, 0);
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue