From: Pádraig Brady Date: Mon, 21 Sep 2015 22:46:05 +0000 (+0100) Subject: nanosleep: fix return code for interrupted replacement X-Git-Tag: v1.0~6960 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=6439a0af0ca6b0256a4273a8ae0175e896bcc8da;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 7c83566007..c552225b64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-09-21 Pádraig Brady + + 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 Diagnose ERE '()|\1' diff --git a/lib/nanosleep.c b/lib/nanosleep.c index 3060db0936..1364f7a019 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -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