]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: fix link failure on cygwin
authorEric Blake <ebb9@byu.net>
Mon, 23 Nov 2009 21:59:18 +0000 (14:59 -0700)
committerEric Blake <ebb9@byu.net>
Tue, 24 Nov 2009 13:36:07 +0000 (06:36 -0700)
Cygwin 1.5 has a broken sleep, and the gnulib tests dragged in
rpl_sleep which then caused a link failure because it wasn't in
libcoreutils.a.  We could solve it by using the gnulib sleep module.
However, sleep and usleep may interact poorly with SIGALRM, and they
have less granularity; so it is better to adopt a policy that if we
must sleep, prefer xnanosleep.

* src/sort.c (pipe_fork): Use xnanosleep, to avoid the need for
rpl_sleep on cygwin, and to reduce granularity.
(MAX_FORK_TRIES_COMPRESS, MAX_FORK_TRIES_DECOMPRESS): Increase,
to account for reduction in granularity.
* src/tail.c (tail_file): Use xnanosleep in debug code.
* cfg.mk (sc_prohibit_sleep): New rule.

cfg.mk
src/sort.c
src/tail.c

diff --git a/cfg.mk b/cfg.mk
index babd99b3c19ccf197cf825af50b7e37e734a7630..c57c0d3e9c7c923474864e3fb35ead01c24bda7f 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -239,4 +239,10 @@ sc_require_stdio_safer:
        else :;                                                         \
        fi
 
+# Prefer xnanosleep over other less-precise sleep methods
+sc_prohibit_sleep:
+       @re='\<(nano|u)?sleep \('                                       \
+       msg='prefer xnanosleep over other sleep interfaces'             \
+         $(_prohibit_regexp)
+
 include $(srcdir)/dist-check.mk
index 0213fee1f4861720649ba693d89b01943e32aed2..8709e53704f31c43629f705529935b6c88aa7b15 100644 (file)
@@ -44,6 +44,7 @@
 #include "strnumcmp.h"
 #include "xmemcoll.h"
 #include "xmemxfrm.h"
+#include "xnanosleep.h"
 #include "xstrtol.h"
 
 #if HAVE_SYS_RESOURCE_H
@@ -107,13 +108,13 @@ enum
     /* The number of times we should try to fork a compression process
        (we retry if the fork call fails).  We don't _need_ to compress
        temp files, this is just to reduce disk access, so this number
-       can be small.  */
-    MAX_FORK_TRIES_COMPRESS = 2,
+       can be small.  Each retry doubles in duration.  */
+    MAX_FORK_TRIES_COMPRESS = 4,
 
     /* The number of times we should try to fork a decompression process.
        If we can't fork a decompression process, we can't sort, so this
-       number should be big.  */
-    MAX_FORK_TRIES_DECOMPRESS = 8
+       number should be big.  Each retry doubles in duration.  */
+    MAX_FORK_TRIES_DECOMPRESS = 9
   };
 
 /* The representation of the decimal point in the current locale.  */
@@ -868,7 +869,7 @@ pipe_fork (int pipefds[2], size_t tries)
 #if HAVE_WORKING_FORK
   struct tempnode *saved_temphead;
   int saved_errno;
-  unsigned int wait_retry = 1;
+  double wait_retry = 0.25;
   pid_t pid IF_LINT (= -1);
   struct cs_status cs;
 
@@ -895,7 +896,7 @@ pipe_fork (int pipefds[2], size_t tries)
         break;
       else
         {
-          sleep (wait_retry);
+          xnanosleep (wait_retry);
           wait_retry *= 2;
           reap_some ();
         }
index 9a2f5ae828d9bbd6160dbd8d144bd67fbb820426..2bd9e3d654cecfc3a87e0398f057e6a6434a02a0 100644 (file)
@@ -1619,7 +1619,7 @@ tail_file (struct File_spec *f, uintmax_t n_units)
           /* Before the tail function provided `read_pos', there was
              a race condition described in the URL below.  This sleep
              call made the window big enough to exercise the problem.  */
-          sleep (1);
+          xnanosleep (1);
 #endif
           f->errnum = ok - 1;
           if (fstat (fd, &stats) < 0)