aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-05-10 17:01:00 +0000
committerTom Tromey <tromey@redhat.com>2013-05-10 17:01:00 +0000
commit21ff46861c35d99dbbafc42d0854128270ef8f30 (patch)
tree695d5c1355aa6d9a74417ee617656c18be640b79 /gdb/common
parentd3685d60d601f0ae817beb920fc1156f1f0885ee (diff)
downloadgdb-21ff46861c35d99dbbafc42d0854128270ef8f30.zip
gdb-21ff46861c35d99dbbafc42d0854128270ef8f30.tar.gz
gdb-21ff46861c35d99dbbafc42d0854128270ef8f30.tar.bz2
2013-05-10 Joel Brobecker <brobecker@adacore.com>
Tom Tromey <tromey@redhat.com> * common/filestuff.c (mark_fd_no_cloexec, unmark_fd_no_cloexec): New functions. * common/filestuff.c (mark_fd_no_cloexec, unmark_fd_no_cloexec): Declare. * darwin-nat.c (darwin_pre_ptrace): Use mark_fd_no_cloexec. (darwin_ptrace_him): Use unmark_fd_no_cloexec. * inf-ttrace.c (do_cleanup_pfds): Use unmark_fd_no_cloexec. (inf_ttrace_prepare): Use mark_fd_no_cloexec.
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/filestuff.c27
-rw-r--r--gdb/common/filestuff.h10
2 files changed, 37 insertions, 0 deletions
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index 68f66ca..e7af3a5 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -177,6 +177,33 @@ notice_open_fds (void)
fdwalk (do_mark_open_fd, NULL);
}
+/* See filestuff.h. */
+
+void
+mark_fd_no_cloexec (int fd)
+{
+ do_mark_open_fd (NULL, fd);
+}
+
+/* See filestuff.h. */
+
+void
+unmark_fd_no_cloexec (int fd)
+{
+ int i, val;
+
+ for (i = 0; VEC_iterate (int, open_fds, i, val); ++i)
+ {
+ if (fd == val)
+ {
+ VEC_unordered_remove (int, open_fds, i);
+ return;
+ }
+ }
+
+ gdb_assert_not_reached (_("fd not found in open_fds"));
+}
+
/* Helper function for close_most_fds that closes the file descriptor
if appropriate. */
diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
index 0db33f0..b162a0c 100644
--- a/gdb/common/filestuff.h
+++ b/gdb/common/filestuff.h
@@ -24,6 +24,16 @@
extern void notice_open_fds (void);
+/* Mark a file descriptor as inheritable across an exec. */
+
+extern void mark_fd_no_cloexec (int fd);
+
+/* Mark a file descriptor as no longer being inheritable across an
+ exec. This is only meaningful when FD was previously passed to
+ mark_fd_no_cloexec. */
+
+extern void unmark_fd_no_cloexec (int fd);
+
/* Close all open file descriptors other than those marked by
'notice_open_fds', and stdin, stdout, and stderr. Errors that
occur while closing are ignored. */