From: Jonathan Wakely Date: Mon, 5 Jun 2023 16:45:37 +0000 (+0100) Subject: libstdc++: Use close-on-exec for file descriptors in filesystem::copy_file X-Git-Tag: releases/gcc-11.5.0~537 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6152b026f6c80272391550faf2a655dac016db4e;p=thirdparty%2Fgcc.git libstdc++: Use close-on-exec for file descriptors in filesystem::copy_file libstdc++-v3/ChangeLog: * src/filesystem/ops-common.h (do_copy_file) [O_CLOEXEC]: Set close-on-exec flag on file descriptors. (cherry picked from commit 7e8e071c4b64f1b6ea5ddf528724fc793a0f0e36) --- diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h index 6423bc9c2d23..d46fbbc662de 100644 --- a/libstdc++-v3/src/filesystem/ops-common.h +++ b/libstdc++-v3/src/filesystem/ops-common.h @@ -456,25 +456,26 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM int fd; }; - int iflag = O_RDONLY; + int common_flags = 0; +#ifdef O_CLOEXEC + common_flags |= O_CLOEXEC; +#endif #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS - iflag |= O_BINARY; + common_flags |= O_BINARY; #endif + const int iflag = O_RDONLY | common_flags; CloseFD in = { posix::open(from, iflag) }; if (in.fd == -1) { ec.assign(errno, std::generic_category()); return false; } - int oflag = O_WRONLY|O_CREAT; + int oflag = O_WRONLY | O_CREAT | common_flags; if (options.overwrite || options.update) oflag |= O_TRUNC; else oflag |= O_EXCL; -#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS - oflag |= O_BINARY; -#endif CloseFD out = { posix::open(to, oflag, S_IWUSR) }; if (out.fd == -1) {