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:
Pawel Jakub Dawidek 2010-08-27 14:35:39 +00:00
parent 3f828c18e5
commit e64887c4d6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211884

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.
*/