Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "timedate: handle gracefully if RTC lost time because of power loss" (v254) #445

Open
wants to merge 1 commit into
base: v254-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/shared/clock-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(). */
Expand Down
2 changes: 2 additions & 0 deletions src/timedate/timedated.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ static int property_get_rtc_time(
log_warning("/dev/rtc is busy. Is somebody keeping it open continuously? That's not a good idea... Returning a bogus RTC timestamp.");
else if (r == -ENOENT)
log_debug("/dev/rtc not found.");
else if (r == -ENODATA)
log_debug("/dev/rtc has no valid time, power loss probably occurred?");
else if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to read RTC: %m");
else
Expand Down
Loading