24 #include <sys/types.h> 31 #define HAVE_SOCKETS 1 32 #elif defined HAVE_SYS_SOCKET_H 33 #include <sys/socket.h> 35 #define HAVE_F_GETFD F_GETFD 36 #define HAVE_SOCKETS 1 39 #ifdef HAVE_SYS_RESOURCE_H 40 #include <sys/resource.h> 48 #define SOCK_CLOEXEC 0 73 dir = opendir (
"/proc/self/fd");
79 for (entry = readdir (dir); entry != NULL; entry = readdir (dir))
86 fd = strtol (entry->d_name, &tail, 10);
87 if (*tail !=
'\0' || errno != 0)
95 if (fd == dirfd (dir))
98 result =
func (arg, fd);
112 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE) 115 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0 && rlim.rlim_max != RLIM_INFINITY)
121 max = sysconf (_SC_OPEN_MAX);
128 for (fd = 0; fd < max; ++fd)
134 if (fstat (fd, &sb) == -1)
137 result =
func (arg, fd);
239 int old = fcntl (fd, F_GETFD, 0);
243 fcntl (fd, F_SETFD, old | FD_CLOEXEC);
247 if ((old & FD_CLOEXEC) != 0)
305 static int fopen_e_ever_failed_einval =
O_CLOEXEC == 0;
307 if (!fopen_e_ever_failed_einval)
311 copy = (
char *) alloca (strlen (opentype) + 2);
312 strcpy (copy, opentype);
316 result = fopen (filename, copy);
318 if (result == NULL && errno == EINVAL)
320 result = fopen (filename, opentype);
322 fopen_e_ever_failed_einval = 1;
326 result = fopen (filename, opentype);
341 #ifdef HAVE_SOCKETPAIR 342 int result = socketpair (domain, style |
SOCK_CLOEXEC, protocol, filedes);
361 int result = socket (domain, style |
SOCK_CLOEXEC, protocol);
386 result = pipe (filedes);
405 int *fd = (
int *) arg;
415 int *saved_fd =
XNEW (
int);
static void mark_cloexec(int fd)
static int do_mark_open_fd(void *ignore, int fd)
void notice_open_fds(void)
static int fdwalk(int(*func)(void *, int), void *arg)
static void socket_mark_cloexec(int fd)
int gdb_pipe_cloexec(int filedes[2])
int gdb_socketpair_cloexec(int domain, int style, int protocol, int filedes[2])
int gdb_socket_cloexec(int domain, int style, int protocol)
static void do_close_cleanup(void *arg)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
void unmark_fd_no_cloexec(int fd)
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
static int do_close(void *ignore, int fd)
struct cleanup * make_cleanup_dtor(make_cleanup_ftype *function, void *arg, make_cleanup_dtor_ftype *dtor)
#define gdb_assert_not_reached(message)
struct cleanup * make_cleanup_close(int fd)
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
void close_most_fds(void)
static int trust_o_cloexec
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
static std::vector< int > open_fds
void mark_fd_no_cloexec(int fd)
static void maybe_mark_cloexec(int fd)