Re: epoll design problems with common fork/exec patterns

Davide Libenzi
2007-10-27T16:59:22Z

On Sat, 27 Oct 2007, Marc Lehmann wrote:

> > Please provide some code to illustrate one exact problem you have.
>
> // assume there is an open epoll set that listens for events on fd 5
> if (fork () = 0)
> {
> close (5);
> // fd 5 is now removed from the epoll set of the parent.
> _exit (0);
> }

Hmmm ... what? I assume you know that:

1) A file descriptor is a userspace view/handle of a kernel object

2) The kernel object has a use-count for as many file descriptors that
have been handed out to userspace

3) A close() decreases the internal counter by one

4) The kernel object gets effectively closed when the internal counter
goes to zero

5) A fork() acts as a dup() on the file descriptors by hence bumping up
its internal counter

6) Epoll removes the file from the set, when the *kernel* object gets
closed (internal use-count goes to zero)

With that in mind, how can the code snippet above trigger a removal from
the epoll set?

- Davide