Eli Zaretskii wrote: > While building the latest pretest of wget2, I saw that the Gnulib's > detection of nanosleep fails to detect its presence in mingw.org's > MinGW runtime. The test program used for that fails for unrelated > reason: it uses SIGALRM, which is unavailable on MS-Windows. > > I'm guessing that SIGALRM is used to guard against buggy nanosleep > implementations
Yes, when SIGALRM was introduced in this test, it was in the commit 2006-08-31 "Work around a bug in both the Linux and SunOS 64-bit kernels". > perhaps the test program could be modified > to avoid using SIGALRM on Windows. Indeed. I'm pushing this patch. Please complain if it does not work. 2018-05-12 Bruno Haible <br...@clisp.org> nanosleep: Avoid test failure on mingw when it has nanosleep. Reported by Eli Zaretskii <e...@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(). diff --git a/m4/nanosleep.m4 b/m4/nanosleep.m4 index 8903734..7c945cc 100644 --- a/m4/nanosleep.m4 +++ b/m4/nanosleep.m4 @@ -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],