]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Use nanosleep if it is available.
authorWayne Davison <wayned@samba.org>
Sun, 5 Apr 2020 16:22:00 +0000 (09:22 -0700)
committerWayne Davison <wayned@samba.org>
Sun, 5 Apr 2020 16:22:00 +0000 (09:22 -0700)
Fixes bug #14328.

configure.ac
util2.c

index 4f68e98a9e1d125f384a45b8f635a12f77e050fc..0756242f466bb6d44fef7cb5bd126b11f6ce3803 100644 (file)
@@ -599,7 +599,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \
     setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
     seteuid strerror putenv iconv_open locale_charset nl_langinfo getxattr \
     extattr_get_link sigaction sigprocmask setattrlist getgrouplist \
-    initgroups utimensat posix_fallocate attropen setvbuf usleep)
+    initgroups utimensat posix_fallocate attropen setvbuf nanosleep usleep)
 
 dnl cygwin iconv.h defines iconv_open as libiconv_open
 if test x"$ac_cv_func_iconv_open" != x"yes"; then
diff --git a/util2.c b/util2.c
index 619c92eb2c632dbe390d8d913b87937d7aa3f9fd..b46677c04af14c2c12faccc094c887d19312a2c0 100644 (file)
--- a/util2.c
+++ b/util2.c
 /**
  * Sleep for a specified number of milliseconds.
  *
- * Always returns TRUE.  (In the future it might return FALSE if
- * interrupted.)
+ * Always returns True.
  **/
 int msleep(int t)
 {
-#ifdef HAVE_USLEEP
+#ifdef HAVE_NANOSLEEP
+       struct timespec ts;
+
+       ts.tv_sec = t / 1000;
+       ts.tv_nsec = (t % 1000) * 1000000L;
+
+       while (nanosleep(&ts, &ts) < 0 && errno == EINTR) {}
+
+#elif defined HAVE_USLEEP
        usleep(t*1000);
+
 #else
        int tdiff = 0;
        struct timeval tval, t1, t2;