mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
sys_timex: add workaround for broken ntp_adjtime() on macOS
On macOS 11.0 (Big Sur) beta, ntp_adjtime() incorrectly returns timex.freq as an unsigned number. This patch is a workaround for the bug and should be removed when Apple fix the problem (assuming they will).
This commit is contained in:
committed by
Miroslav Lichvar
parent
009f1a5ae8
commit
538e1c5eb1
23
sys_timex.c
23
sys_timex.c
@@ -68,6 +68,25 @@ static int sys_tai_offset;
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static double
|
||||
convert_timex_frequency(const struct timex *txc)
|
||||
{
|
||||
double freq_ppm;
|
||||
|
||||
freq_ppm = txc->freq / FREQ_SCALE;
|
||||
|
||||
#ifdef MACOSX
|
||||
/* Temporary workaround for Apple bug treating freq as unsigned number */
|
||||
if (freq_ppm > 32767) {
|
||||
freq_ppm -= 65536;
|
||||
}
|
||||
#endif
|
||||
|
||||
return -freq_ppm;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static double
|
||||
read_frequency(void)
|
||||
{
|
||||
@@ -77,7 +96,7 @@ read_frequency(void)
|
||||
|
||||
SYS_Timex_Adjust(&txc, 0);
|
||||
|
||||
return txc.freq / -FREQ_SCALE;
|
||||
return convert_timex_frequency(&txc);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
@@ -92,7 +111,7 @@ set_frequency(double freq_ppm)
|
||||
|
||||
SYS_Timex_Adjust(&txc, 0);
|
||||
|
||||
return txc.freq / -FREQ_SCALE;
|
||||
return convert_timex_frequency(&txc);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
Reference in New Issue
Block a user