]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
rtc: handle RTCs that don't support interrupts
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 10 Dec 2019 16:33:17 +0000 (17:33 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 10 Dec 2019 16:45:28 +0000 (17:45 +0100)
Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF
ioctls, which causes chronyd started with the -s option to get stuck in
the initial RTC mode.

After opening the RTC device in the initialization, return error if
the ioctls are not supported to prevent the upper layer from calling the
time_init() function and expecting it to finish.

rtc_linux.c

index f5bc9bdd6aa4ce6c96e238df0e7fa0d60e1ad552..fad95b5f85bda8613dae3de8897db3315d5e75e8 100644 (file)
@@ -484,17 +484,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
 
 /* ================================================== */
 
-static void
+static int
 switch_interrupts(int on_off)
 {
   if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) {
     LOG(LOGS_ERR, "Could not %s RTC interrupt : %s",
         on_off ? "enable" : "disable", strerror(errno));
-    return;
+    return 0;
   }
 
   if (on_off)
     skip_interrupts = 1;
+
+  return 1;
 }
 
 /* ================================================== */
@@ -513,6 +515,12 @@ RTC_Linux_Initialise(void)
     return 0;
   }
 
+  /* Make sure the RTC supports interrupts */
+  if (!switch_interrupts(0)) {
+    close(fd);
+    return 0;
+  }
+
   /* Close on exec */
   UTI_FdSetCloexec(fd);