Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-developers-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin-developers AT sources DOT redhat DOT com Date: Wed, 25 Jul 2001 21:32:44 -0400 From: Christopher Faylor To: cygwin-developers AT cygwin DOT com Subject: Re: close-on-exec handles are left open by exec parent Message-ID: <20010725213244.B14002@redhat.com> Reply-To: cygwin-developers AT cygwin DOT com Mail-Followup-To: cygwin-developers AT cygwin DOT com References: <9715860566 DOT 20010724154632 AT logos-m DOT ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.11i In-Reply-To: <9715860566.20010724154632@logos-m.ru>; from deo@logos-m.ru on Tue, Jul 24, 2001 at 03:46:32PM +0400 On Tue, Jul 24, 2001 at 03:46:32PM +0400, egor duda wrote: >test.exe create pipe and forks. when write end of the pipe is marked >as close-on-exec, we DuplicateHandle () appropriately. but forked >instance left running after execlp () is performed, and it doesn't >close it's own copy of pipe handle. so read () blocks forever. > >i can see 2 ways to fix it. We can either always perform >dtable::fixup_before_exec() and close handles marked as close-on-exec >there, or always close all handles when exec child is started and exec >parent cycles waiting for its child to exit. Nice analysis. I think the second is the way to deal with this. The first assumes that the exec will be successful, which is not necessarily true. fixup_before_exec is a compromise for sockets. I'd rather not have to do this for other fds, too. So, the correct fix is to close the handles after a successful CreateProcess. I can't believe that this bug has been around for so long. Of course, there was a time (in B20.1, I think ) where close-on-exec didn't work at all for non-cygwin processes... cgf