]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
include: isolate __O_CLOEXEC flag for sys/mount.h and fcntl.h
authorDJ Delorie <dj@redhat.com>
Tue, 27 Jan 2026 03:24:42 +0000 (22:24 -0500)
committerDJ Delorie <dj@redhat.com>
Wed, 11 Feb 2026 20:05:10 +0000 (15:05 -0500)
Including sys/mount.h should not implicitly include fcntl.h
as that causes namespace pollution and conflicts with kernel
headers.  It only needs O_CLOEXEC for OPEN_TREE_CLOEXEC
(although it shouldn't need that, but it's defined that way)
so we provide that define (via a private version) separately.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Tested-by: Florian Weimer <fweimer@redhat.com>
io/fcntl.c
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/alpha/bits/cloexec.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/bits/cloexec.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/bits/fcntl-linux.h
sysdeps/unix/sysv/linux/hppa/bits/cloexec.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/sparc/bits/cloexec.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/sys/mount.h
sysdeps/unix/sysv/linux/tst-mount.c

index c13546e4fd6a6b9337e32e3eb859ccd5edc4622b..4fbc5226242e28046ba6e4e232ca0b4eb92aeec8 100644 (file)
 #include <errno.h>
 #include <fcntl.h>
 
+#ifndef __O_CLOEXEC
+# error __O_CLOEXEC not defined by fcntl.h/cloexec.h
+#endif
+
 /* Perform file control operations on FD.  */
 int
 __fcntl (int fd, int cmd, ...)
index 955d3163625e09bbaa082dd17cc37f5b21f66e58..c6bd97abf1acf4d0db206ca9a1ccee71bd8b7b08 100644 (file)
@@ -129,6 +129,7 @@ CFLAGS-test-errno-linux.c += $(no-fortify-source)
 
 sysdep_headers += \
   bits/a.out.h \
+  bits/cloexec.h \
   bits/epoll.h \
   bits/eventfd.h \
   bits/inotify.h \
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/cloexec.h b/sysdeps/unix/sysv/linux/alpha/bits/cloexec.h
new file mode 100644 (file)
index 0000000..f381f28
--- /dev/null
@@ -0,0 +1 @@
+#define __O_CLOEXEC 010000000
diff --git a/sysdeps/unix/sysv/linux/bits/cloexec.h b/sysdeps/unix/sysv/linux/bits/cloexec.h
new file mode 100644 (file)
index 0000000..3059fb6
--- /dev/null
@@ -0,0 +1 @@
+#define __O_CLOEXEC 02000000
index ad7f7c98c61a10069f9c94df5bf28ef6612a120f..221a71aa62e19246a2852eca08681f5eb0ea780c 100644 (file)
@@ -81,9 +81,7 @@
 #ifndef __O_NOFOLLOW
 # define __O_NOFOLLOW  0400000
 #endif
-#ifndef __O_CLOEXEC
-# define __O_CLOEXEC   02000000
-#endif
+#include <bits/cloexec.h>
 #ifndef __O_DIRECT
 # define __O_DIRECT     040000
 #endif
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/cloexec.h b/sysdeps/unix/sysv/linux/hppa/bits/cloexec.h
new file mode 100644 (file)
index 0000000..f381f28
--- /dev/null
@@ -0,0 +1 @@
+#define __O_CLOEXEC 010000000
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/cloexec.h b/sysdeps/unix/sysv/linux/sparc/bits/cloexec.h
new file mode 100644 (file)
index 0000000..6706eaa
--- /dev/null
@@ -0,0 +1 @@
+#define __O_CLOEXEC 0x400000
index 457d8dcff26a81b759e1e59bc5cf0dfa9cd4ef1c..5e496caf2f1a7453232cbc59e219ff40e41039ff 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef _SYS_MOUNT_H
 #define _SYS_MOUNT_H   1
 
-#include <fcntl.h>
 #include <features.h>
 #include <stdint.h>
 #include <stddef.h>
@@ -266,6 +265,11 @@ enum fsconfig_command
 
 /* open_tree flags.  */
 #define OPEN_TREE_CLONE    1         /* Clone the target tree and attach the clone */
+#ifndef O_CLOEXEC
+# include <bits/cloexec.h>
+# define O_CLOEXEC __O_CLOEXEC
+#endif
+#undef  OPEN_TREE_CLOEXEC
 #define OPEN_TREE_CLOEXEC  O_CLOEXEC /* Close the file on execve() */
 
 
index 8e3ffbd56f838aa66762f13ab3d28d100383220c..84dcd448d465d4cbef7f085559d9114142116a56 100644 (file)
@@ -20,6 +20,7 @@
 #include <support/check.h>
 #include <support/xunistd.h>
 #include <support/namespace.h>
+#include <fcntl.h> /* For AT_ constants.  */
 #include <sys/mount.h>
 
 _Static_assert (sizeof (struct mount_attr) == MOUNT_ATTR_SIZE_VER0,