From b5b8e4ac7a2c0e565507c81f0d4aff3eb46f7084 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 9 Oct 2009 21:28:40 -0600 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ doc/posix-functions/dup2.texi | 6 ++++++ m4/dup2.m4 | 12 +++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90c436b411..94f910681b 100644 --- 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 index fd2cb07538..febbd53cc9 100644 --- a/doc/posix-functions/dup2.texi +++ b/doc/posix-functions/dup2.texi @@ -24,6 +24,12 @@ Cygwin 1.5.x. This function may return @code{-EBADF} instead of @code{-1} on some platforms: 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 index 816a734068..a74e915bb4 100644 --- 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 @@ AC_DEFUN([gl_FUNC_DUP2], 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 @@ AC_DEFUN([gl_FUNC_DUP2], 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]) ]) -- 2.30.2