Mark more file descriptors close-on-exec
authorTom Tromey <tom@tromey.com>
Tue, 18 Sep 2018 22:45:59 +0000 (16:45 -0600)
committerTom Tromey <tom@tromey.com>
Sun, 23 Sep 2018 18:11:16 +0000 (12:11 -0600)
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-23  Tom Tromey  <tom@tromey.com>

* ctf.c (ctf_start): Use gdb_fopen_cloexec.
* common/scoped_mmap.c (mmap_file): Use gdb_open_cloexec.

gdb/ChangeLog
gdb/common/scoped_mmap.c
gdb/ctf.c

index 686c99a10807555e1060cf3df84e91d508385685..d864e431f5606fb69c64e5f3e70219ce2591495a 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-23  Tom Tromey  <tom@tromey.com>
+
+       * ctf.c (ctf_start): Use gdb_fopen_cloexec.
+       * common/scoped_mmap.c (mmap_file): Use gdb_open_cloexec.
+
 2018-09-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * amd64-sol2-tdep.c (amd64_sol2_sigtramp_p): Also recognize
index 7eb729312f0f6316c8ecd88f107edf907f024ee5..e1fffb9336c680ce0c8aed58782cee8a73e7df29 100644 (file)
 #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"));
 
index a156b1faf27d9016690826af1e0feda9a8b18e8d..43bb18ecda18918f2deb2003da967ddbbfda3f31 100644 (file)
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -31,6 +31,7 @@
 #include "tracefile.h"
 #include <ctype.h>
 #include <algorithm>
+#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));
This page took 0.037042 seconds and 4 git commands to generate.