]> Savannah Git Hosting - gnulib.git/commitdiff
nanosleep: fix return code for interrupted replacement
authorPádraig Brady <P@draigBrady.com>
Mon, 21 Sep 2015 22:46:05 +0000 (23:46 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 21 Sep 2015 22:50:25 +0000 (23:50 +0100)
* lib/nanosleep.c (nanosleep): In the replaced nanosleep, ensure
that we return -1 in the case the call is interrupted by a signal,
rather than the current value of 1.
Diagnosed and tested by Daniel Richard G.

ChangeLog
lib/nanosleep.c

index 7c8356600745f31a40bce5290a1b4252bfc41f39..c552225b64747bdac7068eb2d777f1999714d58f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-09-21  Pádraig Brady  <P@draigBrady.com>
+
+       nanosleep: fix return code for interrupted replacement
+       * lib/nanosleep.c (nanosleep): In the replaced nanosleep, ensure
+       that we return -1 in the case the call is interrupted by a signal,
+       rather than the current value of 1.
+       Diagnosed and tested by Daniel Richard G.
+
 2015-09-19  Paul Eggert  <eggert@cs.ucla.edu>
 
        Diagnose ERE '()|\1'
index 3060db09366bbb3a234fdc46905d61c1194732f5..1364f7a019b4c5dc16e5700debe73db8a4def3aa 100644 (file)
@@ -202,7 +202,7 @@ sighandler (int sig)
 
 /* Suspend execution for at least *TS_DELAY seconds.  */
 
-static void
+static int
 my_usleep (const struct timespec *ts_delay)
 {
   struct timeval tv_delay;
@@ -218,7 +218,7 @@ my_usleep (const struct timespec *ts_delay)
           tv_delay.tv_usec = 0;
         }
     }
-  select (0, NULL, NULL, NULL, &tv_delay);
+  return select (0, NULL, NULL, NULL, &tv_delay);
 }
 
 /* Suspend execution for at least *REQUESTED_DELAY seconds.  The
@@ -256,19 +256,21 @@ nanosleep (const struct timespec *requested_delay,
 
   suspended = 0;
 
-  my_usleep (requested_delay);
-
-  if (suspended)
+  if (my_usleep (requested_delay) == -1)
     {
-      /* Calculate time remaining.  */
-      /* FIXME: the code in sleep doesn't use this, so there's no
-         rush to implement it.  */
+      if (suspended)
+        {
+          /* Calculate time remaining.  */
+          /* FIXME: the code in sleep doesn't use this, so there's no
+             rush to implement it.  */
 
-      errno = EINTR;
+          errno = EINTR;
+        }
+      return -1;
     }
 
   /* FIXME: Restore sig handler?  */
 
-  return suspended;
+  return 0;
 }
 #endif