]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Avoid blocking read in rtc_linux
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 18 Nov 2009 11:53:31 +0000 (12:53 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 18 Nov 2009 11:53:31 +0000 (12:53 +0100)
rtc_linux.c

index 1945d213588e5522ffe6521ae1dd4a1b42b1fcf1..0009817cf9003677557159224a85a13b4c317a99 100644 (file)
@@ -107,6 +107,8 @@ static int measurement_period = LOWEST_MEASUREMENT_PERIOD;
 static int timeout_running = 0;
 static SCH_TimeoutID timeout_id;
 
+static int skip_interrupts;
+
 /* ================================================== */
 
 /* Maximum number of samples held */
@@ -682,6 +684,7 @@ switch_interrupts(int onoff)
       LOG(LOGS_ERR, LOGF_RtcLinux, "Could not start measurement : %s", strerror(errno));
       return;
     }
+    skip_interrupts = 1;
   } else {
     status = ioctl(fd, RTC_UIE_OFF, 0);
     if (status < 0) {
@@ -873,8 +876,7 @@ read_from_device(void *any)
   int error = 0;
 
   status = read(fd, &data, sizeof(data));
-  if (operating_mode == OM_NORMAL)
-      status = read(fd, &data, sizeof(data));
+
   if (status < 0) {
     /* This looks like a bad error : the file descriptor was indicating it was
      * ready to read but we couldn't read anything.  Give up. */
@@ -891,6 +893,12 @@ read_from_device(void *any)
     return;
   }    
 
+  if (skip_interrupts > 0) {
+    /* Wait for the next interrupt, this one may be bogus */
+    skip_interrupts--;
+    return;
+  }
+
   if ((data & RTC_UIE) == RTC_UIE) {
     /* Update interrupt detected */