This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Socket Handles duplicated twice after fork


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@MIT.EDU] 
> Sent: Thursday, May 09, 2002 1:43 AM
> To: cygwin@cygwin.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]