X-Recipient: archive-cygwin AT delorie DOT com 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 Message-ID: <4E39D525.5070804@redhat.com> Date: Wed, 03 Aug 2011 17:09:25 -0600 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 AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 AT redhat DOT 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