chiark / gitweb /
timedate: handle more nicely if something or somebody keeps open /dev/rtc and thus...
authorLennart Poettering <lennart@poettering.net>
Tue, 29 Oct 2013 18:31:41 +0000 (19:31 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 29 Oct 2013 18:34:59 +0000 (19:34 +0100)
chrony is appears to keep the RTC open continuously these days which is
a bad idea, and /dev/rtc is a single-user device, which is a bad idea
too. Together both bad ideas mean that nobody else can access the RTC
anymore. That's something to fix, but in the meantime we should handle
this more gracefully.

src/timedate/timedated.c

index 809c80bad11297acc1fdd6342f79d05f542fef97..3d450ca3fabdc8dbe3a62bcd5f0c544d72fe75c2 100644 (file)
@@ -467,12 +467,14 @@ static int property_get_rtc_time(
 
         zero(tm);
         r = hwclock_get_time(&tm);
-        if (r < 0) {
+        if (r == -EBUSY) {
+                log_warning("/dev/rtc is busy, is somebody keeping it open continously? That's not a good idea... Returning a bogus RTC timestamp.");
+                t = 0;
+        } else if (r < 0) {
                 sd_bus_error_set_errnof(error, -r, "Failed to read RTC: %s", strerror(-r));
                 return r;
-        }
-
-        t = (usec_t) mktime(&tm) * USEC_PER_SEC;
+        } else
+                t = (usec_t) mktime(&tm) * USEC_PER_SEC;
 
         r = sd_bus_message_append(reply, "t", t);
         if (r < 0)