# HG changeset patch # User Eric Blake # Date 1255145320 21600 # Node ID 3c9981d0d9c3832aeeb7cdb630a807f80cbeb51b # Parent a620bedbe9580b226566839dfced8fc694d285eb dup2: work around FreeBSD 6.1 bug dup2(1,1000000) needs to fail with EBADF (per POSIX), not EMFILE, based on our usage of it in other modules. * m4/dup2.m4 (gl_FUNC_DUP2): Detect bug. * doc/posix-functions/dup2.texi (dup2): Document it. Reported by Nelson H. F. Beebe and Jim Meyering. Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-10-09 Eric Blake + dup2: work around FreeBSD 6.1 bug + * m4/dup2.m4 (gl_FUNC_DUP2): Detect bug. + * doc/posix-functions/dup2.texi (dup2): Document it. + Reported by Nelson H. F. Beebe and Jim Meyering. + test-stat-time: port to buggy NFS clients * tests/test-stat-time.c (main) [W32]: Reduce ifdefs. (test_ctime): Also skip test if mtime and ctime are skewed. diff --git a/doc/posix-functions/dup2.texi b/doc/posix-functions/dup2.texi --- a/doc/posix-functions/dup2.texi +++ b/doc/posix-functions/dup2.texi @@ -25,6 +25,12 @@ Linux releases between July 2008 and May 2009 (versions 2.6.27 to 2.6.29). @item +This function returns @code{EMFILE} instead of @code{EBADF} for +extremely large targets, which interferes with using +@code{dup2(fd,fd)==fd)} as the minimal @code{EBADF} filter: +FreeBSD 6.1, Cygwin 1.5. + +@item This function is missing on some older platforms. @end itemize diff --git a/m4/dup2.m4 b/m4/dup2.m4 --- a/m4/dup2.m4 +++ b/m4/dup2.m4 @@ -1,4 +1,4 @@ -#serial 8 +#serial 9 dnl Copyright (C) 2002, 2005, 2007, 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, @@ -15,12 +15,16 @@ else AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works], [AC_RUN_IFELSE([ - AC_LANG_PROGRAM([[#include ]], + AC_LANG_PROGRAM([[#include +#include ]], [if (dup2 (1, 1) == 0) return 1; close (0); if (dup2 (0, 0) != -1) - return 1; + return 2; + /* Many gnulib modules require POSIX conformance of EBADF. */ + if (dup2 (1, 1000000) == -1 && errno != EBADF) + return 3; return 0; ]) ], @@ -33,6 +37,8 @@ linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a # closed fd may yield -EBADF instead of -1 / errno=EBADF. gl_cv_func_dup2_works=no;; + freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF. + gl_cv_func_dup2_works=no;; *) gl_cv_func_dup2_works=yes;; esac]) ])