This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: close-on-exec internal file descriptors
- From: Tom Tromey <tromey at redhat dot com>
- To: Yao Qi <yao at codesourcery dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Tue, 23 Apr 2013 09:49:00 -0600
- Subject: Re: RFC: close-on-exec internal file descriptors
- References: <874njjs1aa dot fsf at fleche dot redhat dot com> <5175DF3E dot 10800 at codesourcery dot com>
>>>>> "Yao" == Yao Qi <yao@codesourcery.com> writes:
Yao> This patch causes a build regression with mingw32 cross gcc, reported
Yao> here http://sourceware.org/ml/gdb-patches/2013-04/msg00682.html and I
Yao> can reproduce it on my fedora 16:
Thanks for the note. I'm Sorry about the breakage.
Yao> Your patch doesn't mention much on why not to check
Yao> sys/socket.h. Probably we still need to check it.
I looked and other places use USE_WIN32API.
I am checking in the appended. It fixes the mingw build for me using
the mingw cross compilers that come with Fedora 18. I also built and
regression tested this natively.
I did consider gnulib but it seems we already have a reasonably working
solution; and using it just for mode_t (see the patch) seemed like
overkill.
Tom
2013-04-23 Tom Tromey <tromey@redhat.com>
* common/filestuff.c: Check USE_WIN32API before including
sys/socket.h.
(HAVE_F_GETFD): New define.
(mark_cloexec): Check HAVE_F_GETFD.
(gdb_open_cloexec): Change 'mode' to unsigned long.
(gdb_socketpair_cloexec): Check HAVE_SOCKETPAIR.
(gdb_pipe_cloexec): Check HAVE_PIPE.
* common/filestuff.h (gdb_open_cloexec): Change 'mode' to unsigned
long.
Index: common/filestuff.c
===================================================================
RCS file: /cvs/src/src/gdb/common/filestuff.c,v
retrieving revision 1.1
diff -u -r1.1 filestuff.c
--- common/filestuff.c 22 Apr 2013 16:46:15 -0000 1.1
+++ common/filestuff.c 23 Apr 2013 15:43:46 -0000
@@ -28,10 +28,18 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
-#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef USE_WIN32API
+#include <winsock2.h>
+#include <windows.h>
+#else
+#include <sys/socket.h>
+/* Define HAVE_F_GETFD if we plan to use F_GETFD. */
+#define HAVE_F_GETFD F_GETFD
+#endif
+
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif /* HAVE_SYS_RESOURCE_H */
@@ -215,6 +223,7 @@
static void
mark_cloexec (int fd)
{
+#ifdef HAVE_F_GETFD
int old = fcntl (fd, F_GETFD, 0);
if (old != -1)
@@ -229,6 +238,7 @@
trust_o_cloexec = -1;
}
}
+#endif /* HAVE_F_GETFD */
}
/* Depending on TRUST_O_CLOEXEC, mark FD as close-on-exec. */
@@ -254,7 +264,7 @@
/* See filestuff.h. */
int
-gdb_open_cloexec (const char *filename, int flags, mode_t mode)
+gdb_open_cloexec (const char *filename, int flags, unsigned long mode)
{
int fd = open (filename, flags | O_CLOEXEC, mode);
@@ -303,6 +313,7 @@
int
gdb_socketpair_cloexec (int namespace, int style, int protocol, int filedes[2])
{
+#ifdef HAVE_SOCKETPAIR
int result = socketpair (namespace, style | SOCK_CLOEXEC, protocol, filedes);
if (result != -1)
@@ -312,6 +323,9 @@
}
return result;
+#else
+ gdb_assert_not_reached (_("socketpair not available on this host"));
+#endif
}
/* See filestuff.h. */
@@ -342,13 +356,17 @@
maybe_mark_cloexec (filedes[1]);
}
#else
+#ifdef HAVE_PIPE
result = pipe (filedes);
if (result != -1)
{
mark_cloexec (filedes[0]);
mark_cloexec (filedes[1]);
}
-#endif
+#else /* HAVE_PIPE */
+ gdb_assert_not_reached (_("pipe not available on this host"));
+#endif /* HAVE_PIPE */
+#endif /* HAVE_PIPE2 */
return result;
}
Index: common/filestuff.h
===================================================================
RCS file: /cvs/src/src/gdb/common/filestuff.h,v
retrieving revision 1.1
diff -u -r1.1 filestuff.h
--- common/filestuff.h 22 Apr 2013 16:46:15 -0000 1.1
+++ common/filestuff.h 23 Apr 2013 15:43:46 -0000
@@ -33,7 +33,8 @@
/* Like 'open', but ensures that the returned file descriptor has the
close-on-exec flag set. */
-extern int gdb_open_cloexec (const char *filename, int flags, mode_t mode);
+extern int gdb_open_cloexec (const char *filename, int flags,
+ /* mode_t */ unsigned long mode);
/* Like 'fopen', but ensures that the returned file descriptor has the
close-on-exec flag set. */