When logging to stdout/stderr don't close those descriptors after fork().

MFC after:	2 weeks
Obtained from:	Wheel Systems Sp. z o.o. http://www.wheelsystems.com
This commit is contained in:
pjd 2010-08-27 14:35:39 +00:00
parent ac5c9c9216
commit dd3961e615

View File

@ -61,8 +61,21 @@ descriptors(void)
pjdlog_errno(LOG_WARNING, "sysconf(_SC_OPEN_MAX) failed");
maxfd = 1024;
}
for (fd = 0; fd <= maxfd; fd++)
close(fd);
for (fd = 0; fd <= maxfd; fd++) {
switch (fd) {
case STDIN_FILENO:
case STDOUT_FILENO:
case STDERR_FILENO:
if (pjdlog_mode_get() == PJDLOG_MODE_STD)
break;
/* FALLTHROUGH */
default:
close(fd);
break;
}
}
if (pjdlog_mode_get() == PJDLOG_MODE_STD)
return;
/*
* Redirect stdin, stdout and stderr to /dev/null.
*/