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

ChangeLog
lib/copy-file.c

index fa18753a3dc36519f06e8609e0c2be0492830ea5..744ab9f0e2d17e849b37e227afc3408690a84710 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-28  Bruno Haible  <bruno@clisp.org>
+
+       copy-file: Make more robust in multithreaded applications.
+       * lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to
+       open().
+
 2020-05-28  Bruno Haible  <bruno@clisp.org>
 
        chown: Make more robust in multithreaded applications.
index c574b751a3b7f612fd5255f40ac0ea3138cdf33d..8ae64b2d8fa31ce1355f5b012bebe2d24c2cf3c5 100644 (file)
@@ -52,7 +52,7 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
   int mode;
   int dest_fd;
 
-  src_fd = open (src_filename, O_RDONLY | O_BINARY);
+  src_fd = open (src_filename, O_RDONLY | O_BINARY | O_CLOEXEC);
   if (src_fd < 0)
     return GL_COPY_ERR_OPEN_READ;
   if (fstat (src_fd, &statbuf) < 0)
@@ -65,7 +65,9 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
   off_t inbytes = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
   bool empty_regular_file = inbytes == 0;
 
-  dest_fd = open (dest_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600);
+  dest_fd = open (dest_filename,
+                  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC,
+                  0600);
   if (dest_fd < 0)
     {
       err = GL_COPY_ERR_OPEN_BACKUP_WRITE;