From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4651 invoked by alias); 3 Aug 2011 23:09:41 -0000 Received: (qmail 4641 invoked by uid 22791); 3 Aug 2011 23:09:40 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_FD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Aug 2011 23:09:26 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73N9PWH023967 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 3 Aug 2011 19:09:25 -0400 Received: from [10.3.113.47] (ovpn-113-47.phx2.redhat.com [10.3.113.47]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p73N9P4K024783 for ; Wed, 3 Aug 2011 19:09:25 -0400 Message-ID: <4E39D525.5070804@redhat.com> Date: Wed, 03 Aug 2011 23:09:00 -0000 From: Eric Blake User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11 MIME-Version: 1.0 To: cygwin Subject: odd socketpair() failure Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2011-08/txt/msg00105.txt.bz2 A while ago, I tested pipe() for EMFILE failures [1]. Well, I repeated those tests for socketpair() [2], and cygwin is once again the odd man out. [1] http://cygwin.com/ml/cygwin/2011-06/msg00328.html [2] http://austingroupbugs.net/view.php?id=483 $ cat foo.c #define _POSIX_C_SOURCE 200811L #define __EXTENSIONS__ 1 #include #include #include #include #include #include #include #include int main (int argc, char **argv) { int last; int fd[2] = {-2,-3}; int err; /* Get to an EMFILE condition. */ while (1) { int fd = open("/dev/null", O_RDONLY); if (fd < 0) { printf ("after fd %d, open failed with errno %d %s\n", last, errno, strerror(errno)); break; } last = fd; } /* Probe behavior */ err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); if (err) printf ("try 1, socketpair returned %d errno %d %s, fds %d %d\n", err, errno, strerror(errno), fd[0], fd[1]); else printf ("try 1, socketpair succeeded, fds %d %d\n", fd[0], fd[1]); if (close(last)) return 1; err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); if (err) printf ("try 2, socketpair returned %d errno %d %s, fds %d %d\n", err, errno, strerror(errno), fd[0], fd[1]); else printf ("try 2, socketpair succeeded, fds %d %d\n", fd[0], fd[1]); if (close(0)) return 1; err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); if (err) printf ("try 3, socketpair returned %d errno %d %s, fds %d %d\n", err, errno, strerror(errno), fd[0], fd[1]); else printf ("try 3, socketpair succeeded, fds %d %d\n", fd[0], fd[1]); return 0; } $ ./foo after fd 3199, open failed with errno 24 Too many open files try 1, socketpair returned -1 errno 24 Too many open files, fds -2 -3 try 2, socketpair returned -1 errno 24 Too many open files, fds -2 -3 try 3, socketpair returned -1 errno 24 Too many open files, fds -2 -3 But on Linux, try 3 succeeds. Something in cygwin is not quite right on try 3 - the program explicitly freed two fd slots (0 and 3199), so it should have plenty of room to create the socketpair without hitting EMFILE. Disclaimer: I tested on 1.7.9 rather than the latest snapshot; maybe the pipe() fix in the meantime also fixed socketpair()? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple