rtc: restore time from driftfile if later than RTC time

This is useful on computers that have an RTC, but there is no battery to
keep the time when they are turned off and start with the same time on
each boot.
This commit is contained in:
Miroslav Lichvar
2015-10-06 15:52:36 +02:00
parent 1714d3e8ae
commit 6a9c756cf0
5 changed files with 53 additions and 44 deletions

View File

@@ -974,7 +974,7 @@ RTC_Linux_WriteParameters(void)
RTC behaviour than we do for the rest of the module. */
int
RTC_Linux_TimePreInit(void)
RTC_Linux_TimePreInit(time_t driftfile_time)
{
int fd, status;
struct rtc_time rtc_raw, rtc_raw_retry;
@@ -1039,6 +1039,11 @@ RTC_Linux_TimePreInit(void)
UTI_AddDoubleToTimeval(&new_sys_time, -accumulated_error, &new_sys_time);
if (new_sys_time.tv_sec < driftfile_time) {
LOG(LOGS_WARN, LOGF_RtcLinux, "RTC time before last driftfile modification (ignored)");
return 0;
}
UTI_DiffTimevalsToDouble(&sys_offset, &old_sys_time, &new_sys_time);
/* Set system time only if the step is larger than 1 second */