]> Savannah Git Hosting - gnulib.git/commitdiff
chown: Make more robust in multithreaded applications.
authorBruno Haible <bruno@clisp.org>
Wed, 27 May 2020 17:35:28 +0000 (19:35 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 28 May 2020 19:39:45 +0000 (21:39 +0200)
* lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().

ChangeLog
lib/chown.c

index f3de49807f2039978d5c34f81ab0a63922bfa051..fa18753a3dc36519f06e8609e0c2be0492830ea5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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).
index 46e753e0e857331c6f6c8100aa9285edaf25fba1..6a8a76c9201bf7d6485fb61eaa68e32bc0d70e84 100644 (file)
@@ -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