diff options
author | Bruno Haible <bruno@clisp.org> | 2020-05-24 20:27:39 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-05-24 20:27:39 +0200 |
commit | ed8d8e847ab8c26165eaf8b446aee78c493dfce3 (patch) | |
tree | 078459b1e42fbe5100a6b13f969ddc59a827e205 | |
parent | a7e878621dc2fb8430fccb461b7b669b6bf86190 (diff) | |
download | gnulib-ed8d8e847ab8c26165eaf8b446aee78c493dfce3.tar.gz gnulib-ed8d8e847ab8c26165eaf8b446aee78c493dfce3.tar.bz2 |
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.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | lib/open.c | 2 | ||||
-rw-r--r-- | lib/openat.c | 2 | ||||
-rw-r--r-- | modules/fcntl-safer-tests | 1 | ||||
-rw-r--r-- | modules/open-tests | 1 | ||||
-rw-r--r-- | modules/openat-tests | 1 | ||||
-rw-r--r-- | tests/test-open.h | 20 |
7 files changed, 37 insertions, 2 deletions
@@ -1,5 +1,17 @@ 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. * lib/fopen.c (rpl_fopen): Parse the mode string. Recognize "r+" as a write access. Pass the right flags to open(). diff --git a/lib/open.c b/lib/open.c index bb180fde29..751b42d7dc 100644 --- a/lib/open.c +++ b/lib/open.c @@ -124,7 +124,7 @@ open (const char *filename, int flags, ...) #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) { diff --git a/lib/openat.c b/lib/openat.c index 974f1a8b3b..fbe1d2e6e6 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -114,7 +114,7 @@ rpl_openat (int dfd, char const *filename, int flags, ...) # 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) { diff --git a/modules/fcntl-safer-tests b/modules/fcntl-safer-tests index cb35aed252..b967c8aa78 100644 --- a/modules/fcntl-safer-tests +++ b/modules/fcntl-safer-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: stdbool +fcntl symlink configure.ac: diff --git a/modules/open-tests b/modules/open-tests index 5bc4e0f885..b2b6710e5c 100644 --- a/modules/open-tests +++ b/modules/open-tests @@ -6,6 +6,7 @@ tests/macros.h Depends-on: stdbool +fcntl symlink configure.ac: diff --git a/modules/openat-tests b/modules/openat-tests index 0b7370d6f2..c4a72f5fb8 100644 --- a/modules/openat-tests +++ b/modules/openat-tests @@ -5,6 +5,7 @@ tests/signature.h tests/macros.h Depends-on: +fcntl symlink configure.ac: diff --git a/tests/test-open.h b/tests/test-open.h index c57054f747..862c8dfa53 100644 --- a/tests/test-open.h +++ b/tests/test-open.h @@ -88,6 +88,26 @@ test_open (int (*func) (char const *, int, ...), bool print) 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) { |