marcan / takeover.sh

Wipe and reinstall a running Linux system via SSH, without rebooting. You know you want to.
Other
7.1k stars 353 forks source link

Close more FDs (64 not enough on debian/systemd) #8

Closed clee closed 5 years ago

marcan commented 5 years ago

Sigh, systemd :P

Nable80 commented 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.

marcan commented 5 years ago

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.

Nable80 commented 5 years ago

OK, thank you for this reply.