delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/01/27/14:48:46

X-Spam-Check-By: sourceware.org
Message-ID: <20060127194834.13739.qmail@web30609.mail.mud.yahoo.com>
Date: Fri, 27 Jan 2006 14:48:34 -0500 (EST)
From: Martin <linkscrazy AT yahoo DOT com>
Subject: Re: 1.5.19-3 parent socket binding remains after closing when spawning child process
To: cygwin AT cygwin DOT com
In-Reply-To: <20060123151810.GB8552@calimero.vinschen.de>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

I tried snapshot cygwin-inst-20060127.tar.bz2.  This testcase still
fails for me.  I could be doing something wrong.  Please, give this
another try.  Your efforts are appreciated.

Thanks,
Martin
--- Corinna Vinschen <corinna-cygwin AT cygwin DOT com> wrote:

> On Jan 20 11:53, Martin wrote:
> > Well, this is a strange one.
> > I open a socket in a parent process, bind it and
> > listen.
> > I set the socket to close-on-exec with the FD_CLOEXEC
> > flag.
> > A child process is spawned, which doesn't inherit the
> > socket.
> > I then close the server socket in the parent process.
> > For a laugh, I attempt to connect to the port
> > associated with the server socket.  I would expect
> > this connection request to fail, since I just closed
> > the socket.  It doesn't.
> > 
> > The attached test case illustrates this.
> > Please let me know if I'm doing something wrong.
> 
> Thanks very much for the testcase.  I found that when duplicating
> sockets between processes using the WSADuplicateSocket/WSASocket
> method,
> the duplicated socket is inheritable by child processes again, even
> when
> the original socket has the inheritance flag removed.  So, what
> basically happend behind the scenes was this:
> 
>   sock = socket()
>   SetHandleInformation(sock, DONT_INHERIT);
> 
>   fork()
>     WSADuplicateSocket(sock)    in parent
>     sock = WSASocket            in child, BUT sock is inheritable
> again.
> 
>     exec()
>       close_on_exec is set?  Yes, don't duplicate socket.
>       ... but sock was inheritable, so the exec'ed process got a
>       valid handle to a valid, listening socket.  Bummer.
> 
> I've checked in a patch to CVS which resets the inheritance for the
> duplicated socket in the child process, so there's no valid, open
> handle
> to the listening socket anymore, after the parent called close() and
> the
> forked child exec'ed.  Consequentially the 2nd connect call fails
> now.
> 
> 
> Thanks again for the testcase, it was highly appreciated,
> Corinna
> 
> -- 
> Corinna Vinschen                  Please, send mails regarding Cygwin
> to
> Cygwin Project Co-Leader          cygwin AT cygwin DOT com
> Red Hat
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 
> 



	

	
		
__________________________________________________________ 
Find your next car at http://autos.yahoo.ca

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.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