Proposal: a revoke() system call

Sergey Babkin babkin at verizon.net
Tue Jul 8 12:28:06 UTC 2008


Robert Watson wrote:
> 
> On Mon, 7 Jul 2008, Sergey Babkin wrote:
> 
> > This leaves a small race window between fd is checked and read() is
> > executed. If in the meantime another thread does close() (and sets
> > mystructure.fd to -1), and the third thread does open() then the result of
> > this open would use the same fd number as our old fd (since now it's likely
> > to be the lowest available number), then read() would happen on a completely
> > wrong file. And yes, it does happen in real world. The best workaround I've
> > come up with is a small pause between setting mystructure.fd = -1 and
> > calling close().
> >
> > The point of proposal is to do a close() without freeing the file
> > descriptor.
> 
> Which can be accomplished by calling dup2(2) to replace the file descriptor
> with another file descriptor, perhaps one to /dev/null.  It would be worth

Yes, dup2() is certainly a better idea than a separate call.
I've just assumed that David is following the discussion so far :-)

-SB


More information about the freebsd-arch mailing list