From: Bruno Haible Date: Wed, 27 May 2020 17:35:28 +0000 (+0200) Subject: chown: Make more robust in multithreaded applications. X-Git-Tag: v1.0~4048 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=2625e7d0916bc035a645c7b0fc697dc6e1c560c1;p=gnulib.git chown: Make more robust in multithreaded applications. * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). --- diff --git a/ChangeLog b/ChangeLog index f3de49807f..fa18753a3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-28 Bruno Haible + + chown: Make more robust in multithreaded applications. + * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). + 2020-05-28 Bruno Haible doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14). 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