From patchwork Tue Sep 18 22:47:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29453 Received: (qmail 24891 invoked by alias); 18 Sep 2018 22:47:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24882 invoked by uid 89); 18 Sep 2018 22:47:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.154) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Sep 2018 22:47:51 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway21.websitewelcome.com (Postfix) with ESMTP id A5DBA400C7FCD for ; Tue, 18 Sep 2018 17:47:49 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 2OmbgrSEgkBj62Ombg1Msd; Tue, 18 Sep 2018 17:47:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=rK8Cy+E65i46GcTEvl5tZSBUKUpoYunb8OcagWScJzY=; b=cYa9DqiNKatCA6xxDn+yFfM/Dm fc8CiekUkrJO4U2rTqj7GGlFu7n0H9spBDR8MyUfG4NtHt1sj/Wo50m0M+/hvuYHQp2uLdVsHJhPn 3f1pHaBZQExCfDZ5QrUqamR/n; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:55140 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g2Omb-003Zje-BS; Tue, 18 Sep 2018 17:47:49 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Mark more file descriptors close-on-exec Date: Tue, 18 Sep 2018 16:47:47 -0600 Message-Id: <20180918224747.6396-1-tom@tromey.com> I noticed a couple of spots in gdb that were opening files but not marking the file descriptors as close-on-exec. This patch fixes these. There are still a few more of these, but they are in code that I can't compile, so I'd prefer not to touch. gdb/ChangeLog 2018-09-18 Tom Tromey * ctf.c (ctf_start): Use gdb_fopen_cloexec. * common/scoped_mmap.c (mmap_file): Use gdb_open_cloexec. --- gdb/ChangeLog | 5 +++++ gdb/common/scoped_mmap.c | 3 ++- gdb/ctf.c | 7 +++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gdb/common/scoped_mmap.c b/gdb/common/scoped_mmap.c index 7eb729312f0..e1fffb9336c 100644 --- a/gdb/common/scoped_mmap.c +++ b/gdb/common/scoped_mmap.c @@ -20,13 +20,14 @@ #include "defs.h" #include "scoped_mmap.h" #include "scoped_fd.h" +#include "common/filestuff.h" #ifdef HAVE_SYS_MMAN_H scoped_mmap mmap_file (const char *filename) { - scoped_fd fd (open (filename, O_RDONLY)); + scoped_fd fd (gdb_open_cloexec (filename, O_RDONLY, 0)); if (fd.get () < 0) perror_with_name (("open")); diff --git a/gdb/ctf.c b/gdb/ctf.c index a156b1faf27..43bb18ecda1 100644 --- a/gdb/ctf.c +++ b/gdb/ctf.c @@ -31,6 +31,7 @@ #include "tracefile.h" #include #include +#include "common/filestuff.h" /* The CTF target. */ @@ -354,7 +355,8 @@ ctf_start (struct trace_file_writer *self, const char *dirname) std::string file_name = string_printf ("%s/%s", dirname, CTF_METADATA_NAME); - writer->tcs.metadata_fd = fopen (file_name.c_str (), "w"); + writer->tcs.metadata_fd + = gdb_fopen_cloexec (file_name.c_str (), "w").release (); if (writer->tcs.metadata_fd == NULL) error (_("Unable to open file '%s' for saving trace data (%s)"), file_name.c_str (), safe_strerror (errno)); @@ -362,7 +364,8 @@ ctf_start (struct trace_file_writer *self, const char *dirname) ctf_save_metadata_header (&writer->tcs); file_name = string_printf ("%s/%s", dirname, CTF_DATASTREAM_NAME); - writer->tcs.datastream_fd = fopen (file_name.c_str (), "w"); + writer->tcs.datastream_fd + = gdb_fopen_cloexec (file_name.c_str (), "w").release (); if (writer->tcs.datastream_fd == NULL) error (_("Unable to open file '%s' for saving trace data (%s)"), file_name.c_str (), safe_strerror (errno));