[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] fcntl-h: default O_SEARCH, O_EXEC to O_PATH if available
From: |
Paul Eggert |
Subject: |
Re: [PATCH] fcntl-h: default O_SEARCH, O_EXEC to O_PATH if available |
Date: |
Thu, 08 Nov 2012 01:26:25 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 |
On 11/07/2012 11:34 PM, Jim Meyering wrote:
> + mkdir -mu=rwx,g=rx,o=w,-s,+t t
> mkdir: cannot change permissions of 't': Bad file descriptor
Thanks for mentioning that. Yes, the O_PATH was the culprit.
I backed out most of it, as follows. Arguably this is a
Linux kernel bug with fchmod.
>From f859fdddb8e8c7535fbba06b5c5729ee0e96db1b Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Thu, 8 Nov 2012 01:23:20 -0800
Subject: [PATCH] fcntl-h: default O_SEARCH, O_EXEC back to O_RDONLY
O_PATH doesn't work with Linux kernel 3.6.5, as fchmod (fd, ...)
fails with errno == EBADF when fd is opened with O_PATH.
Reported by Jim Meyering in
<http://lists.gnu.org/archive/html/bug-gnulib/2012-11/msg00026.html>.
* doc/posix-headers/fcntl.texi (fcntl.h): Document this.
* lib/fcntl.in.h (O_EXEC, O_SEARCH) [O_PATH]: Default back to O_RDONLY.
---
ChangeLog | 10 ++++++++++
doc/posix-headers/fcntl.texi | 7 ++++---
lib/fcntl.in.h | 12 ++----------
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bd05f3c..9817769 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-11-08 Paul Eggert <address@hidden>
+
+ fcntl-h: default O_SEARCH, O_EXEC back to O_RDONLY
+ O_PATH doesn't work with Linux kernel 3.6.5, as fchmod (fd, ...)
+ fails with errno == EBADF when fd is opened with O_PATH.
+ Reported by Jim Meyering in
+ <http://lists.gnu.org/archive/html/bug-gnulib/2012-11/msg00026.html>.
+ * doc/posix-headers/fcntl.texi (fcntl.h): Document this.
+ * lib/fcntl.in.h (O_EXEC, O_SEARCH) [O_PATH]: Default back to O_RDONLY.
+
2012-11-07 Paul Eggert <address@hidden>
test-utimens: speed up by taking shorter naps
diff --git a/doc/posix-headers/fcntl.texi b/doc/posix-headers/fcntl.texi
index 4a75a54..7366513 100644
--- a/doc/posix-headers/fcntl.texi
+++ b/doc/posix-headers/fcntl.texi
@@ -28,9 +28,10 @@ non-zero value; otherwise, the gnulib replacement is 0.
@item
@samp{O_EXEC} and @samp{O_SEARCH} are not defined on some platforms.
-On platforms such as GNU/Linux 2.6.39 and later that have @samp{O_PATH},
-Gnulib defines these macros to @samp{O_PATH}.
-On other platforms, it defines them to @samp{O_RDONLY}, which is typically 0.
+Gnulib defines these macros to @samp{O_RDONLY}, which is typically 0.
+The @samp{O_PATH} macro of GNU/Linux is not a suitable substitute, as
+fchmod fails with @samp{errno==EBADF} when invoked on a file
+descriptor that was opened with @samp{O_PATH}.
@item
@samp{O_ACCMODE} is not defined on some platforms:
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index fb402ee..604c31b 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -213,11 +213,7 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
#endif
#ifndef O_EXEC
-# ifdef O_PATH
-# define O_EXEC O_PATH
-# else
-# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
-# endif
+# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
#endif
#ifndef O_IGNORE_CTTY
@@ -274,11 +270,7 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
#endif
#ifndef O_SEARCH
-# ifdef O_PATH
-# define O_SEARCH O_PATH
-# else
-# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
-# endif
+# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
#endif
#ifndef O_SYNC
--
1.7.11.7