From cc5be347286af59f809efa76f7f4fb0e18a0d782 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 27 May 2020 20:09:49 +0200 Subject: [PATCH] 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 a3543f8a31..7b837df323 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-28 Bruno Haible + + truncate: Make more robust in multithreaded applications. + * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open(). + 2020-05-28 Bruno Haible pagealign_alloc: Make more robust in multithreaded applications. diff --git a/lib/truncate.c b/lib/truncate.c index 456f7aa486..b04f7c7841 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.39.5