Tolerate declared but missing dup3 syscall.
authorBruno Haible <bruno@clisp.org>
Sun, 23 Aug 2009 22:56:31 +0000 (00:56 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 23 Aug 2009 22:56:31 +0000 (00:56 +0200)
ChangeLog
lib/dup3.c
lib/unistd.in.h
m4/dup3.m4
modules/dup3

index 3f8349d..a24ed56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-08-23  Bruno Haible  <bruno@clisp.org>
 
+       Tolerate declared but missing dup3 syscall.
+       * lib/dup3.c (dup3): Invoke original dup3 function first, if available.
+       * lib/unistd.in.h (dup3): If the function is already present,
+       override it.
+       * m4/dup3.m4 (gl_FUNC_DUP3): Remove AC_LIBOBJ invocation.
+       * modules/dup3 (Makefile.am): Compile dup3.c always.
+       Reported by Paolo Bonzini.
+
+2009-08-23  Bruno Haible  <bruno@clisp.org>
+
        Tolerate declared but missing pipe2 syscall.
        * lib/pipe2.c (pipe2): Invoke original pipe2 function first, if
        available.
index b9fb341..62cdb53 100644 (file)
 int
 dup3 (int oldfd, int newfd, int flags)
 {
+#if HAVE_DUP3
+# undef dup3
+  /* Try the system call first, if it exists.  (We may be running with a glibc
+     that has the function but with an older kernel that lacks it.)  */
+  {
+    int result = dup3 (oldfd, newfd, flags);
+    if (!(result < 0 && errno == ENOSYS))
+      return result;
+  }
+#endif
+
   if (oldfd < 0 || newfd < 0 || newfd >= getdtablesize ())
     {
       errno = EBADF;
index 2f3be17..e81d35c 100644 (file)
@@ -179,7 +179,6 @@ extern int dup2 (int oldfd, int newfd);
 
 
 #if @GNULIB_DUP3@
-# if !@HAVE_DUP3@
 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
    specified flags.
    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
@@ -188,8 +187,10 @@ extern int dup2 (int oldfd, int newfd);
    Return newfd if successful, otherwise -1 and errno set.
    See the Linux man page at
    <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>.  */
-extern int dup3 (int oldfd, int newfd, int flags);
+# if @HAVE_DUP3@
+#  define dup3 rpl_dup3
 # endif
+extern int dup3 (int oldfd, int newfd, int flags);
 #elif defined GNULIB_POSIXCHECK
 # undef dup3
 # define dup3(o,n,f) \
index e4fe7a6..0640ca9 100644 (file)
@@ -1,4 +1,4 @@
-# dup3.m4 serial 1
+# dup3.m4 serial 2
 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,
@@ -14,6 +14,5 @@ AC_DEFUN([gl_FUNC_DUP3],
   AC_CHECK_FUNCS_ONCE([dup3])
   if test $ac_cv_func_dup3 != yes; then
     HAVE_DUP3=0
-    AC_LIBOBJ([dup3])
   fi
 ])
index 38bdcf0..4665044 100644 (file)
@@ -16,6 +16,7 @@ gl_FUNC_DUP3
 gl_UNISTD_MODULE_INDICATOR([dup3])
 
 Makefile.am:
+lib_SOURCES += dup3.c
 
 Include:
 <unistd.h>