+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.
+
2013-05-10 Freddie Chopin <freddie_chopin@op.pl>
Tom Tromey <tromey@redhat.com>
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. */
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. */
#include <mach/port.h>
#include "darwin-nat.h"
+#include "common/filestuff.h"
/* Quick overview.
Darwin kernel is Mach + BSD derived kernel. Note that they share the
ptrace_fds[1] = -1;
error (_("unable to create a pipe: %s"), safe_strerror (errno));
}
+
+ mark_fd_no_cloexec (ptrace_fds[0]);
+ mark_fd_no_cloexec (ptrace_fds[1]);
}
static void
close (ptrace_fds[0]);
close (ptrace_fds[1]);
+ unmark_fd_no_cloexec (ptrace_fds[0]);
+ unmark_fd_no_cloexec (ptrace_fds[1]);
+
darwin_init_thread_list (inf);
startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
#include "inf-child.h"
#include "inf-ttrace.h"
+#include "common/filestuff.h"
\f
close (inf_ttrace_pfd1[1]);
close (inf_ttrace_pfd2[0]);
close (inf_ttrace_pfd2[1]);
+
+ unmark_fd_no_cloexec (inf_ttrace_pfd1[0]);
+ unmark_fd_no_cloexec (inf_ttrace_pfd1[1]);
+ unmark_fd_no_cloexec (inf_ttrace_pfd2[0]);
+ unmark_fd_no_cloexec (inf_ttrace_pfd2[1]);
}
static void
close (inf_ttrace_pfd2[0]);
perror_with_name (("pipe"));
}
+
+ mark_fd_no_cloexec (inf_ttrace_pfd1[0]);
+ mark_fd_no_cloexec (inf_ttrace_pfd1[1]);
+ mark_fd_no_cloexec (inf_ttrace_pfd2[0]);
+ mark_fd_no_cloexec (inf_ttrace_pfd2[1]);
}
/* Prepare to be traced. */