+2020-05-24 Bruno Haible <bruno@clisp.org>
+
+ open, openat: Really support O_CLOEXEC.
+ * lib/open.c (open): When have_cloexec is still undecided, do pass a
+ O_CLOEXEC flag to orig_open.
+ * lib/openat.c (rpl_openat): When have_cloexec is still undecided, do
+ pass a O_CLOEXEC flag to orig_openat.
+ * tests/test-open.h (test_open): Verify that O_CLOEXEC is honoured.
+ * modules/open-tests (Depends-on): Add fcntl.
+ * modules/openat-tests (Depends-on): Likewise.
+ * modules/fcntl-safer-tests (Depends-on): Likewise.
+
2020-05-24 Bruno Haible <bruno@clisp.org>
fopen: Fix the trailing slash workaround.
#endif
fd = orig_open (filename,
- flags & ~(have_cloexec <= 0 ? O_CLOEXEC : 0), mode);
+ flags & ~(have_cloexec < 0 ? O_CLOEXEC : 0), mode);
if (flags & O_CLOEXEC)
{
# endif
fd = orig_openat (dfd, filename,
- flags & ~(have_cloexec <= 0 ? O_CLOEXEC : 0), mode);
+ flags & ~(have_cloexec < 0 ? O_CLOEXEC : 0), mode);
if (flags & O_CLOEXEC)
{
Depends-on:
stdbool
+fcntl
symlink
configure.ac:
Depends-on:
stdbool
+fcntl
symlink
configure.ac:
tests/macros.h
Depends-on:
+fcntl
symlink
configure.ac:
ASSERT (0 <= fd);
ASSERT (close (fd) == 0);
+ /* O_CLOEXEC must be honoured. */
+ if (O_CLOEXEC)
+ {
+ /* Since the O_CLOEXEC handling goes through a special code path at its
+ first invocation, test it twice. */
+ int i;
+
+ for (i = 0; i < 2; i++)
+ {
+ int flags;
+
+ fd = func (BASE "file", O_CLOEXEC | O_RDONLY);
+ ASSERT (0 <= fd);
+ flags = fcntl (fd, F_GETFD);
+ ASSERT (flags >= 0);
+ ASSERT ((flags & FD_CLOEXEC) != 0);
+ ASSERT (close (fd) == 0);
+ }
+ }
+
/* Symlink handling, where supported. */
if (symlink (BASE "file", BASE "link") != 0)
{