]> Savannah Git Hosting - gnulib.git/commitdiff
nanosleep: Avoid test failure on mingw when it has nanosleep.
authorBruno Haible <bruno@clisp.org>
Sat, 12 May 2018 11:27:04 +0000 (13:27 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 12 May 2018 11:27:04 +0000 (13:27 +0200)
Reported by Eli Zaretskii <eliz@gnu.org>.

* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Check whether alarm() exists.
If it does not exist, use a simpler test program that does not call
alarm().

ChangeLog
m4/nanosleep.m4

index 3d3924a1427ee123c7fdd208ffd09ee15f9ec05c..95a4203631c2d67f86b376e6d7edee87d63fc65f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-05-12  Bruno Haible  <bruno@clisp.org>
+
+       nanosleep: Avoid test failure on mingw when it has nanosleep.
+       Reported by Eli Zaretskii <eliz@gnu.org>.
+       * m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Check whether alarm() exists.
+       If it does not exist, use a simpler test program that does not call
+       alarm().
+
 2018-05-10  Bruno Haible  <bruno@clisp.org>
 
        lock, cond, thread, tls: Use a different symbol as libpthread witness.
index 89037346e15a7d6351cffc2035c71b21ee4e65f2..7c945cc3a6bd309a2bf69af8fb818bac66f3710c 100644 (file)
@@ -1,4 +1,4 @@
-# serial 37
+# serial 38
 
 dnl From Jim Meyering.
 dnl Check for the nanosleep function.
@@ -22,6 +22,8 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
  AC_CHECK_HEADERS_ONCE([sys/time.h])
  AC_REQUIRE([gl_FUNC_SELECT])
 
+ AC_CHECK_DECLS_ONCE([alarm])
+
  nanosleep_save_libs=$LIBS
 
  # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
@@ -62,40 +64,49 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
                   ? (t) -1 \
                   : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
 
+          #if HAVE_DECL_ALARM
           static void
           check_for_SIGALRM (int sig)
           {
             if (sig != SIGALRM)
               _exit (1);
           }
+          #endif
 
           int
           main ()
           {
             static struct timespec ts_sleep;
             static struct timespec ts_remaining;
-            static struct sigaction act;
             /* Test for major problems first.  */
             if (! nanosleep)
               return 2;
-            act.sa_handler = check_for_SIGALRM;
-            sigemptyset (&act.sa_mask);
-            sigaction (SIGALRM, &act, NULL);
             ts_sleep.tv_sec = 0;
             ts_sleep.tv_nsec = 1;
-            alarm (1);
-            if (nanosleep (&ts_sleep, NULL) != 0)
+            #if HAVE_DECL_ALARM
+            {
+              static struct sigaction act;
+              act.sa_handler = check_for_SIGALRM;
+              sigemptyset (&act.sa_mask);
+              sigaction (SIGALRM, &act, NULL);
+              alarm (1);
+              if (nanosleep (&ts_sleep, NULL) != 0)
+                return 3;
+              /* Test for a minor problem: the handling of large arguments.  */
+              ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
+              ts_sleep.tv_nsec = 999999999;
+              alarm (1);
+              if (nanosleep (&ts_sleep, &ts_remaining) != -1)
+                return 4;
+              if (errno != EINTR)
+                return 5;
+              if (ts_remaining.tv_sec <= TYPE_MAXIMUM (time_t) - 10)
+                return 6;
+            }
+            #else /* A simpler test for native Windows.  */
+            if (nanosleep (&ts_sleep, &ts_remaining) < 0)
               return 3;
-            /* Test for a minor problem: the handling of large arguments.  */
-            ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
-            ts_sleep.tv_nsec = 999999999;
-            alarm (1);
-            if (nanosleep (&ts_sleep, &ts_remaining) != -1)
-              return 4;
-            if (errno != EINTR)
-              return 5;
-            if (ts_remaining.tv_sec <= TYPE_MAXIMUM (time_t) - 10)
-              return 6;
+            #endif
             return 0;
           }]])],
        [gl_cv_func_nanosleep=yes],