From owner-freebsd-current@FreeBSD.ORG Thu Mar 30 08:16:22 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 4A5E316A41F; Thu, 30 Mar 2006 08:16:22 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from mail19.syd.optusnet.com.au (mail19.syd.optusnet.com.au [211.29.132.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9D6D243D45; Thu, 30 Mar 2006 08:16:21 +0000 (GMT) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (c220-239-19-236.belrs4.nsw.optusnet.com.au [220.239.19.236]) by mail19.syd.optusnet.com.au (8.12.11/8.12.11) with ESMTP id k2U8GJbp010454 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Thu, 30 Mar 2006 19:16:19 +1100 Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by turion.vk2pj.dyndns.org (8.13.4/8.13.4) with ESMTP id k2U8GJBE001310; Thu, 30 Mar 2006 19:16:19 +1100 (EST) (envelope-from peter@turion.vk2pj.dyndns.org) Received: (from peter@localhost) by turion.vk2pj.dyndns.org (8.13.4/8.13.4/Submit) id k2U8GJcv001309; Thu, 30 Mar 2006 19:16:19 +1100 (EST) (envelope-from peter) Date: Thu, 30 Mar 2006 19:16:19 +1100 From: Peter Jeremy To: Maxime Henrion Message-ID: <20060330081619.GB736@turion.vk2pj.dyndns.org> References: <200603291605.36884.jhb@freebsd.org> <20060329224100.GB2293@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060329224100.GB2293@elvis.mu.org> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.11 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:16:22 -0000 On Thu, 2006-Mar-30 00:41:00 +0200, Maxime Henrion wrote: >John Baldwin wrote: >> I would vote for fcloseall() personally. > >Seconded. 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. >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. Something that just closed all stdio FILE streams would be far less useful (close to totally useless IMHO) than something that closed file descriptors. >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...). If it close any fd's numerically greater than the passed fd, that would make a lot of sense. -- Peter Jeremy