From: Bruno Haible Date: Wed, 27 May 2020 17:36:54 +0000 (+0200) Subject: copy-file: Make more robust in multithreaded applications. X-Git-Tag: v1.0~4047 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a2fe36d527ab98e3a586ff3c830cbe9271f988c3;p=gnulib.git copy-file: Make more robust in multithreaded applications. * lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to open(). --- diff --git a/ChangeLog b/ChangeLog index fa18753a3d..744ab9f0e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-05-28 Bruno Haible + + 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 chown: Make more robust in multithreaded applications. diff --git a/lib/copy-file.c b/lib/copy-file.c index c574b751a3..8ae64b2d8f 100644 --- a/lib/copy-file.c +++ b/lib/copy-file.c @@ -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;