From: Tom Tromey <tromey@redhat.com>
To: Yao Qi <yao@codesourcery.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: RFC: close-on-exec internal file descriptors
Date: Wed, 24 Apr 2013 02:45:00 -0000 [thread overview]
Message-ID: <871ua1qmc3.fsf@fleche.redhat.com> (raw)
In-Reply-To: <5175DF3E.10800@codesourcery.com> (Yao Qi's message of "Tue, 23 Apr 2013 09:09:18 +0800")
>>>>> "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. */
next prev parent reply other threads:[~2013-04-23 15:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-18 17:45 Tom Tromey
2012-12-18 22:12 ` Andreas Schwab
2012-12-19 14:53 ` Tom Tromey
2013-01-03 16:17 ` Tom Tromey
2013-04-22 23:55 ` Tom Tromey
2013-04-23 1:51 ` Tom Tromey
2013-05-01 14:47 ` Joel Brobecker
2013-05-06 18:53 ` Tom Tromey
2013-05-07 6:46 ` Joel Brobecker
2013-05-10 17:00 ` Tom Tromey
2013-04-23 15:45 ` Yao Qi
2013-04-24 2:45 ` Tom Tromey [this message]
2013-04-24 20:35 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871ua1qmc3.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=yao@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox