[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] fcntl: work around Haiku F_DUPFD bugs
From: |
Eric Blake |
Subject: |
[PATCH] fcntl: work around Haiku F_DUPFD bugs |
Date: |
Wed, 26 Jan 2011 08:45:56 -0700 |
* m4/fcntl.m4 (gl_FUNC_FCNTL): Also catch Haiku errno bug.
* lib/fcntl.c (rpl_fcntl) [F_DUPFD]: Work around Haiku losing
cloexec bit on duplication.
* doc/posix-functions/fcntl.texi (fcntl): Document the bug.
Signed-off-by: Eric Blake <address@hidden>
---
This fixes the fcntl side of things; I'm still working on dup2,
and suspect that I may need to add a gnulib module for dup as well.
ChangeLog | 8 ++++++++
doc/posix-functions/fcntl.texi | 7 ++++++-
lib/fcntl.c | 10 ++++++++++
m4/fcntl.m4 | 9 +++++++--
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c6700ec..4528062 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-01-26 Eric Blake <address@hidden>
+
+ fcntl: work around Haiku F_DUPFD bugs
+ * m4/fcntl.m4 (gl_FUNC_FCNTL): Also catch Haiku errno bug.
+ * lib/fcntl.c (rpl_fcntl) [F_DUPFD]: Work around Haiku losing
+ cloexec bit on duplication.
+ * doc/posix-functions/fcntl.texi (fcntl): Document the bug.
+
2011-01-26 Bruno Haible <address@hidden>
Enable memory leak tests on AIX.
diff --git a/doc/posix-functions/fcntl.texi b/doc/posix-functions/fcntl.texi
index a0511ec..161af1e 100644
--- a/doc/posix-functions/fcntl.texi
+++ b/doc/posix-functions/fcntl.texi
@@ -19,7 +19,12 @@ fcntl
@item
The @code{F_DUPFD} action of this function does not reject
out-of-range targets properly on some platforms:
-Cygwin 1.5.x.
+Cygwin 1.5.x, Haiku.
+
address@hidden
+The @code{F_DUPFD} action of this function mistakenly clears
+FD_CLOEXEC on the source descriptor on some platforms:
+Haiku.
@item
This function is missing on some platforms:
diff --git a/lib/fcntl.c b/lib/fcntl.c
index 25a79c5..17b1784 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -187,7 +187,17 @@ rpl_fcntl (int fd, int action, /* arg */...)
errno = EINVAL;
else
{
+ /* Haiku alpha 2 loses fd flags on original. */
+ int flags = fcntl (fd, F_GETFD);
+ int saved_errno;
result = fcntl (fd, action, target);
+ saved_errno = errno;
+ if (flags < 0 || fcntl (fd, F_SETFD, flags) == -1)
+ {
+ close (result);
+ result = -1;
+ errno = saved_errno;
+ }
# if REPLACE_FCHDIR
if (0 <= result)
result = _gl_register_dup (fd, result);
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4
index 3a86f2c..a93ed85 100644
--- a/m4/fcntl.m4
+++ b/m4/fcntl.m4
@@ -1,4 +1,4 @@
-# fcntl.m4 serial 3
+# fcntl.m4 serial 4
dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -24,11 +24,16 @@ AC_DEFUN([gl_FUNC_FCNTL],
gl_REPLACE_FCNTL
else
dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
+ dnl haiku alpha 2 F_DUPFD has wrong errno
AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
[gl_cv_func_fcntl_f_dupfd_works],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <fcntl.h>
-]], [[return fcntl (0, F_DUPFD, -1) != -1;
+#include <errno.h>
+]], [[int result = 0;
+ if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
+ if (errno != EINVAL) result |= 2;
+ return result;
]])],
[gl_cv_func_fcntl_f_dupfd_works=yes],
[gl_cv_func_fcntl_f_dupfd_works=no],
--
1.7.3.5