too many close calls for non-opened fds

Carson Gaspar carson at taltos.org
Thu Aug 17 07:44:43 EST 2006


--On Wednesday, August 16, 2006 2:33 PM -0700 William Ahern 
<william at 25thandClement.com> wrote:

> On Wed, Aug 16, 2006 at 02:25:05PM -0700, Carson Gaspar wrote:
>> Does any UNIX variant have a "close all my open fds except for these"
>> syscall? Or an easy way to get back a list of in-use fds? I really wish
>> such a beast would be added, as calling close() on all possible fd
>> numbers  is _such_ a hack...
>
> OpenBSD has closefrom(2) and AIX has an fcntl capability using F_CLOSEM.
> On Linux you can read the entries in /proc/$$/fd--see
> openbsd-compat/closefrom.c in the OpenSSH source--however that wouldn't
> work in a chroot environment.

You learn something new every day... Solaris 10 also has closefrom() and 
fdwalk() (which performs an arbitrary function on all open fds, allowing 
you to check the return code from each close, unlike closefrom()).

Now if we can just get the Linux folks to add it...

-- 
Carson



More information about the openssh-unix-dev mailing list