nanosleep: improve port to mingw
authorEric Blake <ebb9@byu.net>
Thu, 19 Nov 2009 05:14:39 +0000 (22:14 -0700)
committerEric Blake <ebb9@byu.net>
Fri, 20 Nov 2009 14:12:32 +0000 (07:12 -0700)
test-nanosleep failed to link, and exposed a need for argument
validation when nanosleep is missing.

* lib/nanosleep.c (rpl_nanosleep): Reject invalid arguments.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Incorporate LIBSOCKET into
LIB_NANOSLEEP, but only when needed.
* modules/select (Link): Document LIBSOCKET.
* m4/select.m4 (gl_FUNC_SELECT): Ensure LIBSOCKET is defined early
enough.

ChangeLog
lib/nanosleep.c
m4/nanosleep.m4
m4/select.m4
modules/select

index 10f2c74..f7a77a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2009-11-20  Eric Blake  <ebb9@byu.net>
 
+       nanosleep: improve port to mingw
+       * lib/nanosleep.c (rpl_nanosleep): Reject invalid arguments.
+       * m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Incorporate LIBSOCKET into
+       LIB_NANOSLEEP, but only when needed.
+       * modules/select (Link): Document LIBSOCKET.
+       * m4/select.m4 (gl_FUNC_SELECT): Ensure LIBSOCKET is defined early
+       enough.
+
        nanosleep: work around cygwin bug
        * lib/nanosleep.c (rpl_nanosleep) [HAVE_BUG_BIG_NANOSLEEP]:
        Fix logic bug when nanosleep fails.  Work around cygwin 1.5.x
index a9311f8..2b5bf5a 100644 (file)
@@ -134,6 +134,12 @@ rpl_nanosleep (const struct timespec *requested_delay,
 {
   static bool initialized;
 
+  if (requested_delay->tv_nsec < 0 || BILLION <= requested_delay->tv_nsec)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
   /* set up sig handler */
   if (! initialized)
     {
index 211b367..2251e93 100644 (file)
@@ -1,4 +1,4 @@
-# serial 29
+# serial 30
 
 dnl From Jim Meyering.
 dnl Check for the nanosleep function.
@@ -18,6 +18,7 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
 
  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  AC_CHECK_HEADERS_ONCE([sys/time.h])
+ AC_REQUIRE([gl_FUNC_SELECT])
 
  nanosleep_save_libs=$LIBS
 
@@ -102,6 +103,13 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
     if test "$gl_cv_func_nanosleep" = 'no (mishandles large arguments)'; then
       AC_DEFINE([HAVE_BUG_BIG_NANOSLEEP], [1],
        [Define to 1 if nanosleep mishandles large arguments.])
+    else
+      for ac_lib in $LIBSOCKET; do
+        case " $LIB_NANOSLEEP " in
+        *" $ac_lib "*) ;;
+        *) LIB_NANOSLEEP="$LIB_NANOSLEEP $ac_lib";;
+        esac
+      done
     fi
     AC_LIBOBJ([nanosleep])
     gl_PREREQ_NANOSLEEP
index 53cc059..d801c38 100644 (file)
@@ -1,4 +1,4 @@
-# select.m4 serial 2
+# select.m4 serial 3
 dnl Copyright (C) 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,7 @@ AC_DEFUN([gl_FUNC_SELECT],
 [
   AC_REQUIRE([gl_HEADER_SYS_SELECT])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SOCKETS])
   if test "$ac_cv_header_winsock2_h" = yes; then
     AC_LIBOBJ([select])
   else
index 299d105..dbdaa72 100644 (file)
@@ -18,6 +18,9 @@ Makefile.am:
 Include:
 <sys/select.h>
 
+Link:
+$(LIBSOCKET)
+
 License:
 LGPLv2+