summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2012-12-31 11:15:53 -0700
committerEric Blake <eblake@redhat.com>2012-12-31 11:51:32 -0700
commitcb83c6cb603abfa9cd8945013226e17c894309f2 (patch)
tree4996d34a82ed3f0798f243cfc801ef92c0060439
parent14ec011a3937faee6f4af6ea1655fffdf5691576 (diff)
downloadgnulib-cb83c6cb603abfa9cd8945013226e17c894309f2.tar.gz
dup2: work around cygwin bug
Detected by './gnulib-tool --test dup2 cloexec'. Reported upstream: http://cygwin.com/ml/cygwin/2012-12/msg00377.html and fixed already: http://cygwin.com/ml/cygwin-cvs/2012-q4/msg00202.html but as we want to work with older cygwin, we'll have to carry this in gnulib for a while. * m4/dup2.m4 (gl_FUNC_DUP2): Flush out cygwin core dump. * lib/dup2.c (rpl_dup2): Work around it. * doc/posix-functions/dup2.texi (dup2): Document it. Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r--ChangeLog7
-rw-r--r--doc/posix-functions/dup2.texi2
-rw-r--r--lib/dup2.c3
-rw-r--r--m4/dup2.m45
4 files changed, 15 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d1a69ba03..af52d73a13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-12-31 Eric Blake <eblake@redhat.com>
+
+ dup2: work around cygwin bug
+ * m4/dup2.m4 (gl_FUNC_DUP2): Flush out cygwin core dump.
+ * lib/dup2.c (rpl_dup2): Work around it.
+ * doc/posix-functions/dup2.texi (dup2): Document it.
+
2012-12-30 Paul Eggert <eggert@cs.ucla.edu>
regex: remove unnecessary dependency on localcharset.h
diff --git a/doc/posix-functions/dup2.texi b/doc/posix-functions/dup2.texi
index 012bb7f0e0..14e5236d4f 100644
--- a/doc/posix-functions/dup2.texi
+++ b/doc/posix-functions/dup2.texi
@@ -18,7 +18,7 @@ mingw, MSVC 9.
@item
This function crashes when invoked with invalid arguments on some platforms:
-MSVC 9.
+Cygwin 1.7.17, MSVC 9.
@item
This function resets the @code{FD_CLOEXEC} flag when duplicating an fd
diff --git a/lib/dup2.c b/lib/dup2.c
index f6d0f1c73c..36b3399067 100644
--- a/lib/dup2.c
+++ b/lib/dup2.c
@@ -95,7 +95,10 @@ rpl_dup2 (int fd, int desired_fd)
# ifdef F_GETFL
/* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
On Cygwin 1.5.x, dup2 (1, 1) returns 0.
+ On Cygwin 1.7.17, dup2 (1, -1) dumps core.
On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
+ if (desired_fd < 0)
+ fd = desired_fd;
if (fd == desired_fd)
return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
# endif
diff --git a/m4/dup2.m4 b/m4/dup2.m4
index fc86e8085b..fa7f6d5513 100644
--- a/m4/dup2.m4
+++ b/m4/dup2.m4
@@ -1,4 +1,4 @@
-#serial 18
+#serial 19
dnl Copyright (C) 2002, 2005, 2007, 2009-2012 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -39,6 +39,9 @@ AC_DEFUN([gl_FUNC_DUP2],
/* Many gnulib modules require POSIX conformance of EBADF. */
if (dup2 (2, 1000000) == -1 && errno != EBADF)
result |= 16;
+ /* Flush out a cygwin core dump. */
+ if (dup2 (2, -1) != -1 || errno != EBADF)
+ result |= 32;
return result;
])
],