From: Bruno Haible Date: Wed, 27 May 2020 18:09:49 +0000 (+0200) Subject: truncate: Make more robust in multithreaded applications. X-Git-Tag: v1.0~4035 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc5be347286af59f809efa76f7f4fb0e18a0d782;p=thirdparty%2Fgnulib.git truncate: Make more robust in multithreaded applications. * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open(). --- 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)