summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-04-19 19:20:40 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-04-20 02:15:07 +0200
commit5c81de98fcb533c0889ed6c6f6cd8640bb626360 (patch)
treee87696b9b397fdd09c4ac4379eade05f6176f59b /src/shared
parentMerge pull request #31872 from tfg13/main (diff)
downloadsystemd-5c81de98fcb533c0889ed6c6f6cd8640bb626360.tar.xz
systemd-5c81de98fcb533c0889ed6c6f6cd8640bb626360.zip
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
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/clock-util.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c
index b0cbe30072..37d02325b7 100644
--- a/src/shared/clock-util.c
+++ b/src/shared/clock-util.c
@@ -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(). */