From owner-freebsd-current@FreeBSD.ORG Thu Mar 30 08:39:15 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2A76216A422; Thu, 30 Mar 2006 08:39:15 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from fw.zoral.com.ua (ll-227.216.82.212.sovam.net.ua [212.82.216.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5553043D45; Thu, 30 Mar 2006 08:39:14 +0000 (GMT) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by fw.zoral.com.ua (8.13.4/8.13.3) with ESMTP id k2U8d7Yj022561 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 30 Mar 2006 11:39:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6) with ESMTP id k2U8d7sZ015339; Thu, 30 Mar 2006 11:39:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6/Submit) id k2U8d7UV015338; Thu, 30 Mar 2006 11:39:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 30 Mar 2006 11:39:07 +0300 From: Kostik Belousov To: Peter Jeremy Message-ID: <20060330083907.GE1375@deviant.kiev.zoral.com.ua> References: <200603291605.36884.jhb@freebsd.org> <20060329224100.GB2293@elvis.mu.org> <20060330081619.GB736@turion.vk2pj.dyndns.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xJK8B5Wah2CMJs8h" Content-Disposition: inline In-Reply-To: <20060330081619.GB736@turion.vk2pj.dyndns.org> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: ClamAV version 0.88, clamav-milter version 0.87 on fw.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on fw.zoral.com.ua Cc: deischen@freebsd.org, freebsd-current@freebsd.org Subject: Re: _cleanup() vs Linux fcloseall() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2006 08:39:15 -0000 --xJK8B5Wah2CMJs8h Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Mar 30, 2006 at 07:16:19PM +1100, Peter Jeremy wrote: > On Thu, 2006-Mar-30 00:41:00 +0200, Maxime Henrion wrote: > >John Baldwin wrote: > >> I would vote for fcloseall() personally. > > > >Seconded. >=20 > I'd prefer to see a function that closed all file descriptors greater > than a specified limit (which makes it easy for a process to preserve > stdin/out/err but close everything else). Two obvious places for this > would be: > - At the beginning of a setuid program (making sure that the user hasn't > passed in any unexpected open FDs). > - Before an exec() to prevent fd's leaking into a child. >=20 > >Does fcloseall() really closes all the open file descriptors? The name > >suggests that it will close all the FILE * streams instead, which is not > >quite the same. The manpage I found on the net seems to confirm this > >indirectly by saying that fflush() is used prior to closing the streams. >=20 > Something that just closed all stdio FILE streams would be far less > useful (close to totally useless IMHO) than something that closed file > descriptors. >=20 > >FWIW, NetBSD has something that close all the file descriptors, and it's > >done with fcntl(fd, F_CLOSEM) (using fcntl() on one file descriptor to > >close all of them looks a bit weird to me, but well...). >=20 > If it close any fd's numerically greater than the passed fd, that would > make a lot of sense. According to fcntl(2) manpage from the netbsd, this is exactly the functionality of F_CLOSEM. FreeBSD already has a way to close all file descriptors: rfork(RFCFDG). --xJK8B5Wah2CMJs8h Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (FreeBSD) iD8DBQFEK5kqC3+MBN1Mb4gRAhCXAKDkUU+7n0iqWKNF6MmDeFwEIL4rKgCdEyXf t3Q+DXFjwaVQtetiKMCn0Vc= =fbjc -----END PGP SIGNATURE----- --xJK8B5Wah2CMJs8h--