Close all FD's instead of just 0,1,2 on startup

Changed the startup in the main function to loop through all file
descriptors from getrlimit(RLIMIT_NOFILE) down to 0, and close them all
to make sure none are left opened by the parent process.
This commit is contained in:
Petar Kapris 2020-12-10 14:36:21 +01:00
parent 27a087ac3d
commit 6fc342929c

View file

@ -351,9 +351,10 @@ char *argv[];
if (pid > 0)
exit(0);
close(0);
close(1);
close(2);
for (int i = getrlimit(RLIMIT_NOFILE); i >= 0; --i) {
close(i);
}
if (setsid() < 0) {
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
syslog(LOG_ERR, "Failed to set new session ID at startup.");