bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS) does not close extra fds

Peter Korsgaard peter at
Thu Mar 14 16:15:59 UTC 2019

On Thu, Mar 14, 2019 at 4:35 PM Arnout Vandecappelle <arnout at> wrote:

>  The problem is that the assumption that open() returns an fd that is larger
> than all existing fds is simply wrong.
>  I think that there is no other way to close all open fds than to iterate over
> /proc/self/fd. But that is of course not very portable.

This particular issue could be fixed by rewriting the logic to something like:

int keep = 2;

   keep = -1;

fd = open(bb_dev_null, O_RDWR);
while (fd > keep) {

But yeah, the other problem persists. I don't know of any other
solutions besides using a hardcoded max-fd. I believe the classic
limit used by select is 1024.

Bye, Peter Korsgaard

More information about the busybox mailing list