From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sukadev Bhattiprolu Subject: Re: bash: Correct usage of F_SETFD Date: Mon, 22 Nov 2010 16:04:46 -0800 Message-ID: <20101123000446.GA24667@us.ibm.com> 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, linux-fsdevel@vger.kernel.org, bug-bash@gnu.org, chet@po.cwru.edu To: Eric Blake Return-path: Received: from e3.ny.us.ibm.com ([32.97.182.143]:42109 "EHLO e3.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932386Ab0KVX5F (ORCPT ); Mon, 22 Nov 2010 18:57:05 -0500 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oAMNdRwk026990 for ; Mon, 22 Nov 2010 18:39:27 -0500 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oAMNv4sv2162746 for ; Mon, 22 Nov 2010 18:57:04 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oAMNv36B002437 for ; Mon, 22 Nov 2010 21:57:03 -0200 Content-Disposition: inline In-Reply-To: <4CEAEE3A.4090004@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Eric Blake [eblake@redhat.com] 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). Is that the POSIX definition ? Following man page does not limit F_SETFD to FD_CLOEXEC: http://www.kernel.org/doc/man-pages/online/pages/man2/fcntl.2.html F_SETFD (long) Set the file descriptor flags to the value specified by arg. | > | >> 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. Yes, that seems to make more sense. Sukadev