sys/mount.h vs fcntl.h
Florian Weimer
fweimer@redhat.com
Tue Feb 3 18:24:09 GMT 2026
* DJ Delorie:
> diff --git a/sysdeps/unix/sysv/linux/sys/mount.h b/sysdeps/unix/sysv/linux/sys/mount.h
> index 457d8dcff2..d52c0121a3 100644
> --- a/sysdeps/unix/sysv/linux/sys/mount.h
> +++ b/sysdeps/unix/sysv/linux/sys/mount.h
> @@ -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,7 +265,13 @@ enum fsconfig_command
>
> /* open_tree flags. */
> #define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */
> -#define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */
> +/* The kernel version of fcntl.h defines this as O_CLOEXEC but that is
> + not a valid flag according to the manual, so use our private
> + version instead to avoid namespace pollution and the fcntl.h
> + requirement. */
> +#include <bits/cloexec.h>
> +#undef OPEN_TREE_CLOEXEC
> +#define OPEN_TREE_CLOEXEC __O_CLOEXEC /* Close the file on execve() */
I suggest this instead:
#include <bits/cloexec.h>
#define O_CLOEXEC __O_CLOEXEC
#define OPEN_TREE_CLOEXEC O_CLOEXEC
So it's identical to the kernel macro definition and no #undef is
needed.
> diff --git a/sysdeps/unix/sysv/linux/tst-fcntl-cloexec.c b/sysdeps/unix/sysv/linux/tst-fcntl-cloexec.c
> new file mode 100644
> index 0000000000..442fa9f7d5
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-fcntl-cloexec.c
> @@ -0,0 +1,47 @@
> +/* Both fcntl.h and sys/mount.h include APIs that need O_CLOEXEC.
> +
> + So, there's an arch-specific header for this constant, just for
> + this purpose. We test that it is defined correctly here, and that
> + fcntl.h can use it. */
You can include both <bits/cloexec.h> and the kernel header
<linux/fcntl.h> and use static_assert.
Or write a tst-fcntl-consts.py test that checks all constants. This
would completely break the build if there's an inconsistency.
Thanks,
Florian
More information about the Libc-alpha
mailing list