>From 663fc0066a4aabce029451922abacdd5a614c03f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 27 May 2020 20:09:49 +0200 Subject: [PATCH 15/18] truncate: Make more robust in multithreaded applications. * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open(). --- ChangeLog | 5 +++++ lib/truncate.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c71ecf8..8922897 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-05-27 Bruno Haible + truncate: Make more robust in multithreaded applications. + * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open(). + +2020-05-27 Bruno Haible + pagealign_alloc: Make more robust in multithreaded applications. * lib/pagealign_alloc.c (pagealign_alloc): Pass an O_CLOEXEC flag to open(). diff --git a/lib/truncate.c b/lib/truncate.c index 456f7aa..b04f7c7 100644 --- a/lib/truncate.c +++ b/lib/truncate.c @@ -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) -- 2.7.4