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);
270 socket_mark_cloexec (
int fd)
285 int fd = open (filename, flags |
O_CLOEXEC, mode);
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);
346 socket_mark_cloexec (filedes[0]);
347 socket_mark_cloexec (filedes[1]);
361 int result = socket (domain, style |
SOCK_CLOEXEC, protocol);
364 socket_mark_cloexec (result);
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)
static void xfree(T *ptr)
int gdb_socketpair_cloexec(int domain, int style, int protocol, int filedes[2])
void notice_open_fds(void)
static int fdwalk(int(*func)(void *, int), void *arg)
int gdb_socket_cloexec(int domain, int style, int protocol)
int gdb_pipe_cloexec(int filedes[2])
static void do_close_cleanup(void *arg)
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 std::vector< int > open_fds
void mark_fd_no_cloexec(int fd)
static void maybe_mark_cloexec(int fd)