core: Restore get_max_fds optimization on Linux
authorColin Watson <cjwatson@debian.org>
Sat, 16 Sep 2017 03:16:45 +0000 (04:16 +0100)
committerWerner Koch <wk@gnupg.org>
Wed, 4 Oct 2017 15:26:39 +0000 (17:26 +0200)
commitb5b996b1a142abb90296f5feadf0b5b19c59f738
treebae96d5b1fea3c7f799bd36dd4d7a4c850a0abdd
parentbff944842887908dfcf66469251598065c0abcff
core: Restore get_max_fds optimization on Linux

* src/posix-io.c (get_max_fds): Restore Linux optimization, this time
using open/getdents/close rather than opendir/readdir/closedir.
--

opendir/readdir/closedir may allocate/free memory, and aren't required
to do so in an async-signal-safe way.  On the other hand, opening
/proc/self/fd directly and iterating over it using getdents is safe.

(getdents is not strictly speaking documented to be async-signal-safe
because it's not in POSIX.  However, the Linux implementation is
essentially just a souped-up read.  Python >= 3.2.3 makes the same
assumption.)

Signed-off-by: Colin Watson <cjwatson@debian.org>
src/posix-io.c