Subject: Re: implementing closeall via a syscall
To: Matt Thomas <matt@3am-software.com>
From: mouss <usebsd@free.fr>
List: tech-kern
Date: 01/05/2004 23:28:40
- 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":-)

- 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).

- 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:).


cheers,
mouss
- The syscall way can at least serve a doc purpose: should I write a 
paper on adding new syscalls? (the current web page has two lines for 
syscalls)