mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 22:45:07 -05:00
rtc: use LCL functions to read and step system clock
This commit is contained in:
18
rtc_linux.c
18
rtc_linux.c
@@ -980,7 +980,7 @@ RTC_Linux_TimePreInit(void)
|
|||||||
struct rtc_time rtc_raw, rtc_raw_retry;
|
struct rtc_time rtc_raw, rtc_raw_retry;
|
||||||
struct tm rtc_tm;
|
struct tm rtc_tm;
|
||||||
time_t rtc_t;
|
time_t rtc_t;
|
||||||
double accumulated_error;
|
double accumulated_error, sys_offset;
|
||||||
struct timeval new_sys_time, old_sys_time;
|
struct timeval new_sys_time, old_sys_time;
|
||||||
|
|
||||||
coefs_file_name = CNF_GetRtcFile();
|
coefs_file_name = CNF_GetRtcFile();
|
||||||
@@ -1004,6 +1004,9 @@ RTC_Linux_TimePreInit(void)
|
|||||||
}
|
}
|
||||||
} while (status >= 0 && rtc_raw.tm_sec != rtc_raw_retry.tm_sec);
|
} while (status >= 0 && rtc_raw.tm_sec != rtc_raw_retry.tm_sec);
|
||||||
|
|
||||||
|
/* Read system clock */
|
||||||
|
LCL_ReadCookedTime(&old_sys_time, NULL);
|
||||||
|
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
/* Convert to seconds since 1970 */
|
/* Convert to seconds since 1970 */
|
||||||
rtc_tm.tm_sec = rtc_raw.tm_sec;
|
rtc_tm.tm_sec = rtc_raw.tm_sec;
|
||||||
@@ -1034,18 +1037,13 @@ RTC_Linux_TimePreInit(void)
|
|||||||
|
|
||||||
UTI_AddDoubleToTimeval(&new_sys_time, -accumulated_error, &new_sys_time);
|
UTI_AddDoubleToTimeval(&new_sys_time, -accumulated_error, &new_sys_time);
|
||||||
|
|
||||||
/* Set system time only if the step is larger than 1 second */
|
UTI_DiffTimevalsToDouble(&sys_offset, &old_sys_time, &new_sys_time);
|
||||||
if (!(gettimeofday(&old_sys_time, NULL) < 0) &&
|
|
||||||
(old_sys_time.tv_sec - new_sys_time.tv_sec > 1 ||
|
|
||||||
old_sys_time.tv_sec - new_sys_time.tv_sec < -1)) {
|
|
||||||
|
|
||||||
|
/* Set system time only if the step is larger than 1 second */
|
||||||
|
if (fabs(sys_offset) >= 1.0) {
|
||||||
LOG(LOGS_INFO, LOGF_RtcLinux, "Set system time, error in RTC = %f",
|
LOG(LOGS_INFO, LOGF_RtcLinux, "Set system time, error in RTC = %f",
|
||||||
accumulated_error);
|
accumulated_error);
|
||||||
|
LCL_ApplyStepOffset(sys_offset);
|
||||||
/* Tough luck if this fails */
|
|
||||||
if (settimeofday(&new_sys_time, NULL) < 0) {
|
|
||||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not settimeofday");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not convert RTC reading to seconds since 1/1/1970");
|
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not convert RTC reading to seconds since 1/1/1970");
|
||||||
|
|||||||
Reference in New Issue
Block a user