[PATCH] ev: fix epoll_init fd leak

Marc Lehmann schmorp at schmorp.de
Thu Nov 3 11:19:03 CET 2011

On Wed, Nov 02, 2011 at 12:58:43PM +0100, Christian Parpart <trapni at gentoo.org> wrote:
> 1.) first reads config file,
> 2.) populates internal data structures out of it,
> 3.) cleans up its environment (including closing inherited fds, including
> 0,1,2)

This is the bug.

> This is not a bad behaviour.

It is. Were you sleeping when I explained it?

> closing all inherited fds right before starting to allocate its intended
> ones is even a really sane approach to prevent stale fds from the parent
> process. (again, we talk about a server app).

We heard that before in the form of "demons do that", but can you name one
such app? Even if, I can name you ten for each such example which are not
as braindead.

All "sane" (or at least all such programs widely in use) do the
traditional, sane thing if they dislike fds 0..2, namely attaching them to
/dev/null or some other "safe" file.

Code that closes all fds like you describe can only come, sorry to say,
from a clueless programmer: It is not how you do it, it asks for security
bugs and/or data corruption and so on.

Code that puts listening sockets or internal log targets to stdio file
descriptors is just broken, sorry.

> While you should never come even close to your software limits in a peak
> load, it would be a huge waste to live in spirit of yours (just keeping

Since this is how the world works, I doubt they all chose to live in a
huge waste.

> fds around for nothing, knowing, that libev is the only void dependency
> that needs them to properly initialize, wtf).

libev is not the only one - your libc is another library that uses those
fds on its own.

> p.s.: you wanted a software-example, well, I once worked at a company
> where resources (like fds) and high performance where treated very
> precise, keeping fds around for nothing would have been a joke, though,
> sure, you might work around libev's behaviour.

That argument isn't even wrong - name some software that does it that
way, or don't claim it exists. Mythical proprietary (and such most likely
broken and low-quality) software doesn't count.

And saying that this is for performance is bullshit - these three fds cost
you exactly no extra performance.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list