From: Bruno Haible Date: Thu, 6 Sep 2018 16:36:02 +0000 (+0200) Subject: fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku. X-Git-Tag: v1.0~5438 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c4af52baedd099698d83e204f67510678230cd16;p=gnulib.git fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku. * lib/fcntl.c (rpl_fcntl): For F_DUPFD_CLOEXEC, don't even try the system fcntl. * doc/posix-functions/fcntl.texi: Document the issue. --- diff --git a/ChangeLog b/ChangeLog index a66610f119..57cdd8ea7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-09-06 Bruno Haible + + fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku. + * lib/fcntl.c (rpl_fcntl): For F_DUPFD_CLOEXEC, don't even try the + system fcntl. + * doc/posix-functions/fcntl.texi: Document the issue. + 2018-09-06 Bruno Haible count-trailing-zeros tests: Rely on limits-h module. diff --git a/doc/posix-functions/fcntl.texi b/doc/posix-functions/fcntl.texi index f606ead057..df896079b6 100644 --- a/doc/posix-functions/fcntl.texi +++ b/doc/posix-functions/fcntl.texi @@ -21,6 +21,11 @@ IRIX 6.5, OSF/1 5.1, Solaris 11 2010-11, Cygwin 1.7.1, Interix 3.5, BeOS. Note that the gnulib replacement code is functional but not atomic. +@item +The @code{F_DUPFD_CLOEXEC} action of this function sets the +@code{FD_CLOEXEC} flag on the wrong file descriptor on some platforms: +Haiku. + @item The @code{F_DUPFD} action of this function does not reject out-of-range targets properly on some platforms: @@ -28,7 +33,7 @@ AIX 7.1, Cygwin 1.5.x, Haiku. @item The @code{F_DUPFD} action of this function mistakenly clears -FD_CLOEXEC on the source descriptor on some platforms: +@code{FD_CLOEXEC} on the source descriptor on some platforms: Haiku. @end itemize diff --git a/lib/fcntl.c b/lib/fcntl.c index 80ff8c42dc..c985a7eddc 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -329,6 +329,12 @@ rpl_fcntl (int fd, int action, /* arg */...) result = dupfd (fd, target, O_CLOEXEC); break; #else /* HAVE_FCNTL */ +# if defined __HAIKU__ + /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets + the O_CLOEXEC flag on fd, not on target. Therefore avoid the + system fcntl in this case. */ +# define have_dupfd_cloexec -1 +# else /* Try the system call first, if the headers claim it exists (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we may be running with a glibc that has the macro but with an @@ -343,10 +349,10 @@ rpl_fcntl (int fd, int action, /* arg */...) if (0 <= result || errno != EINVAL) { have_dupfd_cloexec = 1; -# if REPLACE_FCHDIR +# if REPLACE_FCHDIR if (0 <= result) result = _gl_register_dup (fd, result); -# endif +# endif } else { @@ -357,6 +363,7 @@ rpl_fcntl (int fd, int action, /* arg */...) } } else +# endif result = rpl_fcntl (fd, F_DUPFD, target); if (0 <= result && have_dupfd_cloexec == -1) {