From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27354 invoked by alias); 23 Apr 2013 15:49:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 27343 invoked by uid 89); 23 Apr 2013 15:49:06 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,TW_FC autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 23 Apr 2013 15:49:05 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3NFn2Or030439 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 23 Apr 2013 11:49:02 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3NFn0fs014660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 23 Apr 2013 11:49:01 -0400 From: Tom Tromey To: Yao Qi Cc: Subject: Re: RFC: close-on-exec internal file descriptors References: <874njjs1aa.fsf@fleche.redhat.com> <5175DF3E.10800@codesourcery.com> Date: Wed, 24 Apr 2013 02:45:00 -0000 In-Reply-To: <5175DF3E.10800@codesourcery.com> (Yao Qi's message of "Tue, 23 Apr 2013 09:09:18 +0800") Message-ID: <871ua1qmc3.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-04/txt/msg00710.txt.bz2 >>>>> "Yao" == Yao Qi 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 * 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 #include #include -#include #include #include +#ifdef USE_WIN32API +#include +#include +#else +#include +/* Define HAVE_F_GETFD if we plan to use F_GETFD. */ +#define HAVE_F_GETFD F_GETFD +#endif + #ifdef HAVE_SYS_RESOURCE_H #include #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. */