[commit: ghc] ghc-8.0: rts/posix/Itimer.c: Handle EINTR when reading timerfd (37936e2)

git at git.haskell.org git at git.haskell.org
Wed Mar 30 21:24:51 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/37936e2b23e58b8a855b7ece5a375b930d1a29bc/ghc

>---------------------------------------------------------------

commit 37936e2b23e58b8a855b7ece5a375b930d1a29bc
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date:   Mon Mar 28 14:29:37 2016 +1100

    rts/posix/Itimer.c: Handle EINTR when reading timerfd
    
    Commit 8626d76a72 added checking of the return value when reading from
    the `timer_fd` and calling `sysErrorBelch` to print a warning message.
    However some error causes (like EINTR) are benign and should just be
    ignored.
    
    Test Plan: validate
    
    Reviewers: hvr, austin, bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2040
    
    (cherry picked from commit 7aa4c52f9df1705258f43f9c003c17af97401693)


>---------------------------------------------------------------

37936e2b23e58b8a855b7ece5a375b930d1a29bc
 rts/posix/Itimer.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/rts/posix/Itimer.c b/rts/posix/Itimer.c
index b833295..8915446 100644
--- a/rts/posix/Itimer.c
+++ b/rts/posix/Itimer.c
@@ -202,10 +202,15 @@ static void *itimer_thread_func(void *_handle_tick)
 
     while (1) {
         if (USE_TIMERFD_FOR_ITIMER) {
-            if (read(timerfd, &nticks, sizeof(nticks)) != sizeof(nticks))
-                sysErrorBelch("Itimer: read(timer_fd) failed");
+            if (read(timerfd, &nticks, sizeof(nticks)) != sizeof(nticks)) {
+                if (errno != EINTR) {
+                    sysErrorBelch("Itimer: read(timerfd) failed");
+                }
+            }
         } else {
-            usleep(TimeToUS(itimer_interval));
+            if (usleep(TimeToUS(itimer_interval)) != 0 && errno != EINTR) {
+                sysErrorBelch("usleep(TimeToUS(itimer_interval) failed");
+            }
         }
         switch (itimer_state) {
             case RUNNING:
@@ -222,7 +227,7 @@ static void *itimer_thread_func(void *_handle_tick)
                 return NULL;
         }
     }
-    return NULL;
+    return NULL; // Never reached.
 }
 #endif
 



More information about the ghc-commits mailing list