Subject: Re: implementing closeall via a syscall
To: mouss <usebsd@free.fr>
From: Matt Thomas <matt@3am-software.com>
List: tech-kern
Date: 01/05/2004 14:47:21
At 02:28 PM 1/5/2004, you wrote:
>- As of now, fcntl seems to be the right way, adding both a closem and a 
>maxfd commands. Thanks Matt for your comments. So I'm gonna go for that 
>and update the manpage accordingly. I'll probably also try to do this on 
>other *bsd (dragonfly, free, open) just to go for the "convergence project":-)

Note that the diffs have already been applied to NetBSD. :)

>- at user level, I suggest adding closefrom() and fdwalk() for solaris 
>compatibility, closeall() replacement, and an ifdef bit of code for 
>portability. a closem() call (with ebadf as an error) doesn't seem needed, 
>or is it? (we could return the "worst" error from the close's).

closefrom/fdwalk seem fine from a compatibility area.  closem
doesn't seem to be needed.

>- Andrew: I don't have a solaris at hands, so I can't confirm, but... 
>http://docs.sun.com/db/doc/816-0213/6m6ne37rj?a=view
>
>- Matt: After some analysis, I came back to my original code.
>Indeed, the fdrelease(p, fdp->fd_lastfile) suffers an infinite loop if 
>fdrelease fails. So it's better to call fdrelease on an already closed fd. 
>Otherwise, we'd need an <if (i> fd_lastfile) i=fd_last> test, which is 
>suboptimal in the "normal" case (when all the fd's ranging from k to N are 
>open), when it's better to fdrelease even if fd is not open. Or did I miss 
>something? (I realize that I should have kept a "natural" loop [from i=f 
>to max], but now that we are in, we gotta find the right way:).

fdrelease can't fail.  it will always close the descriptor.  So there is no
infinite loop.

-- 
Matt Thomas                     email: matt@3am-software.com
3am Software Foundry              www: http://3am-software.com/bio/matt/
Cupertino, CA              disclaimer: I avow all knowledge of this message.