delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/09/09:18:19

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
Subject: RE: Socket Handles duplicated twice after fork
MIME-Version: 1.0
Date: Thu, 9 May 2002 23:17:53 +1000
X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3
content-class: urn:content-classes:message
Message-ID: <FC169E059D1A0442A04C40F86D9BA7600C6014@itdomain003.itdomain.net.au>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
To: "David E Euresti" <davie AT MIT DOT EDU>, <cygwin AT cygwin DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id g49DIIl13503

We're all kinda flat out... I've been following it but not had time to
review..

I suggest that you grab the cygwin source and create a patch to fix
this, as you are obviously quite aware of what happens, and what should
happen.

http://www.cygwin.com/cvs.html and http://cygwin.com/contrib.html are
good reference points.

Rob

> -----Original Message-----
> From: David E Euresti [mailto:davie AT MIT DOT EDU] 
> Sent: Thursday, May 09, 2002 1:43 AM
> To: cygwin AT cygwin DOT com
> Subject: Socket Handles duplicated twice after fork
> 
> 
> 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/
> 
> 

--
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