]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
truncate: Make more robust in multithreaded applications.
authorBruno Haible <bruno@clisp.org>
Wed, 27 May 2020 18:09:49 +0000 (20:09 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 28 May 2020 19:40:17 +0000 (21:40 +0200)
* lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open().

ChangeLog
lib/truncate.c

index a3543f8a3139f6483fe7e744c9ac5b8d79da4434..7b837df3234f77952173ba3623a5694082378a5d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-28  Bruno Haible  <bruno@clisp.org>
+
+       truncate: Make more robust in multithreaded applications.
+       * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open().
+
 2020-05-28  Bruno Haible  <bruno@clisp.org>
 
        pagealign_alloc: Make more robust in multithreaded applications.
index 456f7aa486d11201785e6adc3b4d0cc9dcd5a203..b04f7c784155dfaa79080758201c7fe1bd04759a 100644 (file)
@@ -29,13 +29,13 @@ truncate (const char *filename, off_t length)
 
   if (length == 0)
     {
-      fd = open (filename, O_WRONLY | O_TRUNC);
+      fd = open (filename, O_WRONLY | O_TRUNC | O_CLOEXEC);
       if (fd < 0)
         return -1;
     }
   else
     {
-      fd = open (filename, O_WRONLY);
+      fd = open (filename, O_WRONLY | O_CLOEXEC);
       if (fd < 0)
         return -1;
       if (ftruncate (fd, length) < 0)