From 7a914e7f3d3d53ccbde50d0933cbaf576720c24e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 28 Nov 2019 12:23:14 +0100 Subject: [PATCH] unix: retry on EINTR in uv_sleep() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reception of a signal makes nanosleep() return prematurely. Restart the system call when that happens. PR-URL: https://github.com/libuv/libuv/pull/2552 Reviewed-By: Santiago Gimeno Reviewed-By: Saúl Ibarra Corretgé Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig --- src/unix/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/unix/core.c b/src/unix/core.c index 6b10af56..04999dce 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1558,8 +1558,14 @@ int uv_gettimeofday(uv_timeval64_t* tv) { void uv_sleep(unsigned int msec) { struct timespec timeout; + int rc; timeout.tv_sec = msec / 1000; timeout.tv_nsec = (msec % 1000) * 1000 * 1000; - nanosleep(&timeout, NULL); + + do + rc = nanosleep(&timeout, &timeout); + while (rc == -1 && errno == EINTR); + + assert(rc == 0); }