public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: cygwin <cygwin@cygwin.com>
Subject: odd socketpair() failure
Date: Wed, 03 Aug 2011 23:09:00 -0000	[thread overview]
Message-ID: <4E39D525.5070804@redhat.com> (raw)

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 <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
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

             reply	other threads:[~2011-08-03 23:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 23:09 Eric Blake [this message]
2011-08-04  6:00 ` Marco atzeri
2011-08-04  8:26 ` Corinna Vinschen

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=4E39D525.5070804@redhat.com \
    --to=eblake@redhat.com \
    --cc=cygwin@cygwin.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).