delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/08/11:43:22

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Wed, 8 May 2002 11:42:54 -0400 (EDT)
From: David E Euresti <davie AT MIT DOT EDU>
To: <cygwin AT cygwin DOT com>
Subject: Socket Handles duplicated twice after fork
Message-ID: <Pine.GSO.4.30L.0205081131450.10599-100000@department-of-alchemy.mit.edu>
MIME-Version: 1.0

Hello,
	I've been trying to get the developers attention to this problem
but have failed at it.  Perhaps the third time is the charm.

Below we have some code that creates a socketpair and forks.  Then each
process tells you what the handle of the sockets are.  The output looks
something like this:

Parent: Sockets are 0x10c 0x104
Child: Sockets are 0xc 0x10

Now if you run sysinternals's Process Explorer (www.sysinternals.com)
and click on the parent process you'll see that sure enough the handles
0x10c and 0x104 are there and point to a /Device/Afd/Endpoint.  Now if you
go to the child process you'll see that 0xc and 0x10 are there and
pointing to /Device/Afd/Endpoint.  However you'll also notice that 0x10c
and 0x104 are also there.  This is were the error is.  The bad part is
that you don't have access to those handles to close them so they will
always remain open even if you close 0xc and 0x10.  This was all tested in
Win2k.

Let me know what you guys think.  Is this an error in Cygwin, is it
fixable, is this an error in my code?  Thanks.

#include <unistd.h>
#include <io.h>
#include <sys/socket.h>
#include <stdio.h>

int main() {
  int fds[2];
  int pid;

  socketpair (AF_UNIX, SOCK_STREAM, 0, fds);

  pid = fork ();
  if (pid == 0) {
    printf("Child: Sockets are 0x%x 0x%x\n",
	   get_osfhandle(fds[0]), get_osfhandle(fds[1]));
    sleep(300);
  }
  else {
    printf("Parent: Sockets are 0x%x 0x%x\n",
	   get_osfhandle(fds[0]), get_osfhandle(fds[1]));
    sleep(300);
  }
}



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019