>From 244e67314cfbc3d0e20b893c66cec9e48e2ddb67 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 27 May 2020 19:35:28 +0200 Subject: [PATCH 02/18] chown: Make more robust in multithreaded applications. * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). --- ChangeLog | 5 +++++ lib/chown.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d26c96a..cc937d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-05-27 Bruno Haible + chown: Make more robust in multithreaded applications. + * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). + +2020-05-27 Bruno Haible + 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 46e753e..6a8a76c 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 -- 2.7.4