summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-05-27 19:35:28 +0200
committerBruno Haible <bruno@clisp.org>2020-05-28 21:39:45 +0200
commit2625e7d0916bc035a645c7b0fc697dc6e1c560c1 (patch)
tree715a3a0f93aa6eb43e6891ae79d5127e3d796a1e
parent721e499d98b4237164f0729f120990f0f7b5a98e (diff)
downloadgnulib-2625e7d0916bc035a645c7b0fc697dc6e1c560c1.tar.gz
chown: Make more robust in multithreaded applications.
* lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().
-rw-r--r--ChangeLog5
-rw-r--r--lib/chown.c2
2 files changed, 6 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f3de49807f..fa18753a3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-28 Bruno Haible <bruno@clisp.org>
+ chown: Make more robust in multithreaded applications.
+ * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().
+
+2020-05-28 Bruno Haible <bruno@clisp.org>
+
doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14).
* doc/posix-headers/fcntl.texi: Gnulib no longer defines O_CLOEXEC to 0.
diff --git a/lib/chown.c b/lib/chown.c
index 46e753e0e8..6a8a76c920 100644
--- a/lib/chown.c
+++ b/lib/chown.c
@@ -87,7 +87,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
on the symlink itself. To work around that, we open the
file (but this can fail due to lack of read or write permission) and
use fchown on the resulting descriptor. */
- int open_flags = O_NONBLOCK | O_NOCTTY;
+ int open_flags = O_NONBLOCK | O_NOCTTY | O_CLOEXEC;
int fd = open (file, O_RDONLY | open_flags);
if (0 <= fd
|| (errno == EACCES