From dd3961e615cb3f103c9d0bd0c4c18e1cb3773869 Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 27 Aug 2010 14:35:39 +0000 Subject: [PATCH] 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 --- sbin/hastd/hooks.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sbin/hastd/hooks.c b/sbin/hastd/hooks.c index 1fdeb7500859..617e05143f28 100644 --- a/sbin/hastd/hooks.c +++ b/sbin/hastd/hooks.c @@ -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. */