X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Date: Tue, 21 Jul 2009 16:40:03 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: close on exec atomics
Message-ID: <20090721144003.GB27613@calimero.vinschen.de>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <4A65BCC9.1020002@byu.net> <20090721135848.GA2600@calimero.vinschen.de> <20090721140502.GA11240@calimero.vinschen.de> <20090721141704.GA26490@ednor.casa.cgf.cx>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20090721141704.GA26490@ednor.casa.cgf.cx>
User-Agent: Mutt/1.5.19 (2009-02-20)
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Jul 21 10:17, Christopher Faylor wrote:
> On Tue, Jul 21, 2009 at 04:05:02PM +0200, Corinna Vinschen wrote:
> >On Jul 21 15:58, Corinna Vinschen wrote:
> >> On Jul 21 07:04, Eric Blake wrote:
> >> > -----BEGIN PGP SIGNED MESSAGE-----
> >> > Hash: SHA1
> >> > 
> >> > It seems like it would be pretty easy to add several new close-on-exec
> >> > features required by POSIX 2008:
> >> > 
> >> > open(name, O_RDONLY | O_CLOEXEC);
> >> > // skips the need to use fcntl
> >> > 
> >> > fcntl(fd, F_DUPFD_CLOEXEC);
> >> > // like F_DUPFD, but closes window without having to use
> >> > // fcntl(fd, F_SETFD, fcntl(fd, F_GETFD))
> >> > 
> >> > and those provided by glibc as extensions:
> >> > 
> >> > fopen(name, "re");
> >> > // like fopen "r", but with cloexec set
> >> > 
> >> > The argument is that in multi-threaded apps, if one thread opens a file
> >> > but has not yet turned on the close-on-exec bit while another thread does
> >> > a fork-and-exec, then you leaked the fd into the child; and these new
> >> > flags close the window.
> >> > 
> >> > Should I go ahead and prepare a patch for the newlib side?
> >> 
> >> It's not that easy to implement, especially not the fcntl which requires
> >> to redefine the dup2 methods throughout to allow atomic operation on the
> >> target OS handles.  open (O_CLOEXEC) is much easier.  Anyway, can we
> >> wait until after Cygwin 1.7.1?
> >
> >...which is to say, I added it to my TODO list.
> 
> I agree about waiting, but I think this is one for my TODO list.  The
> close_on_exec code is all mine, AFAIK.  I reworked it all back in 1998
> or so, so it is pretty fresh in my mind.

I don't think there's a lot to do in close_on_exec code itself related
to this.  There is no need to call set_close_on_exec at all, rather the
fhandler should create the handle not inheritable in the first place.
That goes for open as well as fcntl.  Time to add Linux' dup3 call, I
guess :)


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

