Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Mar 2006 19:16:19 +1100
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        Maxime Henrion <mux@freebsd.org>
Cc:        deischen@freebsd.org, freebsd-current@freebsd.org
Subject:   Re: _cleanup() vs Linux fcloseall()
Message-ID:  <20060330081619.GB736@turion.vk2pj.dyndns.org>
In-Reply-To: <20060329224100.GB2293@elvis.mu.org>
References:  <Pine.GSO.4.43.0603291445520.25824-100000@sea.ntplx.net> <200603291605.36884.jhb@freebsd.org> <20060329224100.GB2293@elvis.mu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060330081619.GB736>