Bug #21128
closeddir.c defines O_CLOEXEC before it is defined by the system.
Description
Building from master commit hash bfcf36fe2243d34a01b5707754be9164849150c9 on GNU/Linux, I see:
compiling dir.c
In file included from /usr/include/bits/fcntl.h:61,
from /usr/include/fcntl.h:35,
from dir.c:39:
/usr/include/bits/fcntl-linux.h:144:10: warning: "O_CLOEXEC" redefined
144 | # define O_CLOEXEC __O_CLOEXEC /* Set close_on_exec. */
| ^~~~~~~~~
dir.c:26:11: note: this is the location of the previous definition
26 | # define O_CLOEXEC 0
| ^~~~~~~~~
This is because the file includes unistd.h before falling back to 0 for O_CLOEXEC. But glibc requires inclusion of fcntl.h for O_CLOEXEC. Since that file is included after, it is redefined.
The C standard leaves the behavior of redefining a variable undefined and it is a simple fix, so I will create a pull request.
Updated by collinfunk (Collin Funk) 12 days ago
ยท Edited
Opened a pull request [1].
Also, POSIX requires unistd.h to define O_CLOEXEC, so this is a glibc bug that is easy to reproduce [2]. I'll have a look at fixing it in glibc and gnulib.
[1] https://github.com/ruby/ruby/pull/12735
[2] https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/unistd.h.html
Updated by collinfunk (Collin Funk) 7 days ago
- Status changed from Open to Closed
Applied in changeset git|c1c7934b63d7682216fed9dd7c9ddff5b72fea89.
[Bug #21128] Include fcntl.h before checking for O_CLOEXEC
On glibc O_CLOEXEC is defined in fcntl.h and not unistd.h so this change
prevents the macro from being redefined.