Here is the patch to make it use /proc/self/fd, similar to what we do in apt,
and other software does. This uses dirfd to avoid closing the directory
fd under us while iterating over it; an alternative can be to just not
use close() but instead fcntl(fl, F_SETFD, FD_CLOEXEC) such that the
fds will all be closed by the time you exec - which is the concrete
approach taken in apt.
You'll have to see what works better for you in terms of standard
compliance; dirfd was a BSD 4.3 extension standardised only in
POSIX.1-2008.
/proc/self/fd itself is implemented on Linux, and I guess BSDs
also have a /proc compat layer, but it's been a while since I looked
into it.
Neither approach of closing fds is POSIX compliant, given that the
system may open and require arbitrary descriptors, but oh well, in
practice it works fine, and there is no approach that is compliant :D
--
debian developer -
deb.li/jak |
jak-linux.org - free software dev
ubuntu core developer i speak de, en