>From d4a01ed426a9f3ce87807406e1714667cf1e6377 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 27 May 2020 19:36:54 +0200 Subject: [PATCH 03/18] copy-file: Make more robust in multithreaded applications. * lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to open(). --- ChangeLog | 6 ++++++ lib/copy-file.c | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc937d2..1c279d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-05-27 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-27 Bruno Haible + chown: Make more robust in multithreaded applications. * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). diff --git a/lib/copy-file.c b/lib/copy-file.c index c574b75..8ae64b2 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; -- 2.7.4