[PATCH] really close all extra fds in bb_daemonize_or_rexec
Rob Landley
rob at landley.net
Sat Jul 5 14:03:14 PDT 2008
On Tuesday 01 July 2008 03:26:31 Andreas Wetzel wrote:
> hi,
>
> the current implementation seems not to reliably close all open file
> descriptors if the flag DAEMON_CLOSE_EXTRA_FDS is set. it is assumed,
> that the fd returned by opening a file (bb_dev_null) is the top-most fd,
> but this is not true. open returns the first free fd. so, potentially,
> some fds remain open.
>
> the attached patch fixes this by calling close() on every possible file
> descriptor (diffed against the busybox_1_9_stable branch).
I wonder how that interacts with the non-sequential file descriptor stuff? (I
never did follow to see if it was merged, but http://lwn.net/Articles/237722/
is a starting point.)
Personally, I'd probably just iterate through /proc/$PID/fd and use the actual
list of the process's open file descriptors to know what to close. But I can
see the potential downsides of that probably being larger and depending
on /proc. (Not that getdtablesize is the most portable call out there
either, considering that even when it exists it can return INT_MAX...)
Rob
--
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson.
More information about the busybox
mailing list