timedate: handle gracefully if RTC lost time because of power loss
Apparently some RTC drivers return EINVAL in that case when we try to read it. Handle that reasonably gracefully. Fixes: #31854
This commit is contained in:
committed by
Yu Watanabe
parent
bf49f3bb44
commit
5c81de98fc
@@ -27,10 +27,11 @@ int clock_get_hwclock(struct tm *tm) {
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
/* This leaves the timezone fields of struct tm
|
||||
* uninitialized! */
|
||||
/* This leaves the timezone fields of struct tm uninitialized! */
|
||||
if (ioctl(fd, RTC_RD_TIME, tm) < 0)
|
||||
return -errno;
|
||||
/* Some drivers return -EINVAL in case the time could not be kept, i.e. power loss
|
||||
* happened. Let's turn that into a clearly recognizable error */
|
||||
return errno == EINVAL ? -ENODATA : -errno;
|
||||
|
||||
/* We don't know daylight saving, so we reset this in order not
|
||||
* to confuse mktime(). */
|
||||
|
||||
Reference in New Issue
Block a user