From patchwork Tue Jun 6 11:38:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 103736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3325929vqr; Tue, 6 Jun 2023 04:40:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Q7Qf26ruvOuAHWtCbRxrFbNCOOdviuIygbLBsdZmt7Hz2zkGU1Bji4f/hkp71yJcZFDTB X-Received: by 2002:a17:906:9750:b0:974:6216:8dd2 with SMTP id o16-20020a170906975000b0097462168dd2mr2546062ejy.27.1686051635538; Tue, 06 Jun 2023 04:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686051635; cv=none; d=google.com; s=arc-20160816; b=eLSkem2cqrJQKopz//2HRxPbCxw3lt+1a/yjVVo2zC6B9NKYke41VPLV/ifEW2SJXQ 3fOzS24ny02s/uXUTBnq+boAw52rHaupQCVD1yGOKSLUt2oXgqZKXeXoO+S1xM3+6j4x jHJ+2O10dkH2Re1JBCgoOoIQBzTrLBpDTP/jh3FqGSJ8dbBq3FNdaWuEdQXu1CZOkrOD 9k7nVC5bu36i+/7JRM/qPvXUbQ1T+MchSzL0tgUeY6FPVBwdMtvvRcap91cYb1oohWYh EkpZs5OM3ciOqkEn+TTn6Xwylk48SGYIJWeewNSVlA+VlRyF5rxO5ftDLUX6sqratd4e JPzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=20xcK5PRT8QpElpuKk+eF4Nr0o9pL4wcj/uGsO8Nmac=; b=oOYA1yrGQczobnh286hTBqJbnwf7fOOP1Src8viv6DMROQuNBndKNVGD6kdJmM4N0N jSAuLR8hFxDFNfxd+Ci1Y936KcA8p1FeXKX8kMMY0U5yuxmBi7N8fOpUPGMMMd90xLLG 3PRDTGfyk8LlGlzNFgQJEiflJ0QBbIcf42kL8TJmIIi8rdB6HNAqk2gNJd84GCU9bSk3 uhZ7uLBEZGGRVMvLYbSKUhVynycxEU3o/BNcZDDERuiWNlAGPRgEOd2n154UtkukK8K2 rPdRjce3+6wDdy4gb58Sx3lUG4EVam/uoLDE25oN5cwCh9H0vF8Rx2IV8dsEG+WN7c8o AtWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=G4Ecpk95; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hv12-20020a17090760cc00b00977878c3965si6215713ejc.824.2023.06.06.04.40.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 04:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=G4Ecpk95; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8973F3856631 for ; Tue, 6 Jun 2023 11:39:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8973F3856631 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686051561; bh=20xcK5PRT8QpElpuKk+eF4Nr0o9pL4wcj/uGsO8Nmac=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=G4Ecpk95qHbPQokC+mWGas1+TYAP2LSp0rj7qfKTQp7YO4QA/A3TiERiksbT91cQW bEZf27XjKdfMNiZOnLobzMkwTffyT/GteV1caf2KKG7Hd9cPZQoiTkLfWxqjwzz64T NYdu0lTYJkL30pxc+JkUpFtlrdHKgpIK1/nD5Mno= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0187B3856631 for ; Tue, 6 Jun 2023 11:38:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0187B3856631 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-470-flKTT3G4OL61zmlF0Kj6rw-1; Tue, 06 Jun 2023 07:38:36 -0400 X-MC-Unique: flKTT3G4OL61zmlF0Kj6rw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 29A3E185A78B; Tue, 6 Jun 2023 11:38:36 +0000 (UTC) Received: from localhost (unknown [10.42.28.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C758640CFD46; Tue, 6 Jun 2023 11:38:35 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Use close-on-exec for file descriptors in filesystem::copy_file Date: Tue, 6 Jun 2023 12:38:33 +0100 Message-Id: <20230606113833.857327-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767953279589146416?= X-GMAIL-MSGID: =?utf-8?q?1767953279589146416?= Tested x86_64-linux. Pushed to trunk. This is worth backporting. -- >8 -- libstdc++-v3/ChangeLog: * src/filesystem/ops-common.h (do_copy_file) [O_CLOEXEC]: Set close-on-exec flag on file descriptors. --- libstdc++-v3/src/filesystem/ops-common.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h index 901f166514f..f04bbc66d7d 100644 --- a/libstdc++-v3/src/filesystem/ops-common.h +++ b/libstdc++-v3/src/filesystem/ops-common.h @@ -515,25 +515,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) {