Date: Thu, 30 Mar 2006 11:39:07 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Peter Jeremy <peterjeremy@optushome.com.au> Cc: deischen@freebsd.org, freebsd-current@freebsd.org Subject: Re: _cleanup() vs Linux fcloseall() Message-ID: <20060330083907.GE1375@deviant.kiev.zoral.com.ua> In-Reply-To: <20060330081619.GB736@turion.vk2pj.dyndns.org> References: <Pine.GSO.4.43.0603291445520.25824-100000@sea.ntplx.net> <200603291605.36884.jhb@freebsd.org> <20060329224100.GB2293@elvis.mu.org> <20060330081619.GB736@turion.vk2pj.dyndns.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060330083907.GE1375>