#ifdef USE_WIN32API
#include <winsock2.h>
#include <windows.h>
-#else
+#define HAVE_SOCKETS 1
+#elif defined HAVE_SYS_SOCKET_H
#include <sys/socket.h>
/* Define HAVE_F_GETFD if we plan to use F_GETFD. */
#define HAVE_F_GETFD F_GETFD
+#define HAVE_SOCKETS 1
#endif
#ifdef HAVE_SYS_RESOURCE_H
don't use a hashtab because libiberty isn't linked into gdbserver;
and anyway we don't expect there to be many open fds. */
-DEF_VEC_I (int);
-
static VEC (int) *open_fds;
/* An fdwalk callback function used by notice_open_fds. It puts the
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. */
mark_cloexec (fd);
}
+#ifdef HAVE_SOCKETS
+
/* Like maybe_mark_cloexec, but for callers that use SOCK_CLOEXEC. */
static void
mark_cloexec (fd);
}
+#endif
+
\f
/* See filestuff.h. */
FILE *
gdb_fopen_cloexec (const char *filename, const char *opentype)
{
- FILE *result = NULL;
- static int fopen_e_ever_failed;
-
- if (!fopen_e_ever_failed)
+ FILE *result;
+ /* Probe for "e" support once. But, if we can tell the operating
+ system doesn't know about close on exec mode "e" without probing,
+ skip it. E.g., the Windows runtime issues an "Invalid parameter
+ passed to C runtime function" OutputDebugString warning for
+ unknown modes. Assume that if O_CLOEXEC is zero, then "e" isn't
+ supported. */
+ static int fopen_e_ever_failed_einval = O_CLOEXEC == 0;
+
+ if (!fopen_e_ever_failed_einval)
{
char *copy;
this path. */
strcat (copy, "e");
result = fopen (filename, copy);
- }
- if (result == NULL)
- {
- /* Fallback. */
- result = fopen (filename, opentype);
- if (result != NULL)
- fopen_e_ever_failed = 1;
+ if (result == NULL && errno == EINVAL)
+ {
+ result = fopen (filename, opentype);
+ if (result != NULL)
+ fopen_e_ever_failed_einval = 1;
+ }
}
+ else
+ result = fopen (filename, opentype);
if (result != NULL)
maybe_mark_cloexec (fileno (result));
return result;
}
+#ifdef HAVE_SOCKETS
/* See filestuff.h. */
int
return result;
}
+#endif
/* See filestuff.h. */