From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jamie Lokier Subject: Re: bash: Correct usage of F_SETFD Date: Wed, 24 Nov 2010 01:17:16 +0000 Message-ID: <20101124011716.GX22787@shareable.org> References: <20101122201620.GA16687@us.ibm.com> <101122221640.AA32947.SM@caleb.INS.CWRU.Edu> <4CEAEE3A.4090004@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: chet.ramey@case.edu, sukadev@linux.vnet.ibm.com, linux-fsdevel@vger.kernel.org, bug-bash@gnu.org, chet@po.cwru.edu To: Eric Blake Return-path: Received: from mail2.shareable.org ([80.68.89.115]:58513 "EHLO mail2.shareable.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932150Ab0KXBRt (ORCPT ); Tue, 23 Nov 2010 20:17:49 -0500 Content-Disposition: inline In-Reply-To: <4CEAEE3A.4090004@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Eric Blake wrote: > On 11/22/2010 03:16 PM, Chet Ramey wrote: > >> include/filecntl.h in bash-4.1 has following: > >> > >> #define SET_CLOSE_ON_EXEC(fd) (fcntl ((fd), F_SETFD, FD_CLOEXEC)) > >> > >> Is that really the correct/intended usage of F_SETFD ? > > > > F_SETFD Set the close-on-exec flag associated with fildes to > > the low order bit of arg (0 or 1 as above). > > > >> If kernel ever adds a new flag to the fd, this would end up clearing the > >> other new flag right ? > >> > >> Shouldn't bash use F_GETFD to get the current flags and set/clear just > >> the FD_CLOEXEC bit ? > > > > I suppose it would matter if there are systems that have more than one > > flag value. > > In practice, there aren't any such systems; but POSIX warns that current > practice is no indicator of future systems, and that read-modify-write > is the only way to use F_SETFD. There are so many programs using F_SETFD the way Bash does, that it would be quite brave (or stupid) to add another flag. -- Jamie