Closed clee closed 5 years ago
Using /proc/self/fd
or at least getrlimit(RLIMIT_NOFILE, &rl)
may be better than this guesswork. What possible problems do I miss except increasing code complexity?
I often see similar constructions with brutal loop of close(i)
calls and it keeps me wondering whether there is some better way.
Code complexity is not something you want in init
, as a crash brings down your system.
There is no downside to close()
ing nonexistent FDs, so there's no reason to inspect /proc/self/fd
to try to get a list of open FDs. The RLIMIT_NOFILE
option might be a good idea to set the upper limit to a known max, but I'm not sure if it introduces any other corner cases. The code is intentionally supposed to be as simple as possible.
OK, thank you for this reply.
Sigh, systemd :P