summaryrefslogtreecommitdiffstats
path: root/sbin/hastd/hooks.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-10-20 21:10:01 +0000
committerpjd <pjd@FreeBSD.org>2010-10-20 21:10:01 +0000
commitff47d7260c161e26931b5956c9db0c9c70464ca0 (patch)
tree2eaf62f555bde2375f4fed555c6eeb1295036bb2 /sbin/hastd/hooks.c
parentd5e7511690c1ec3e58e7d07bc500b130a8f7c138 (diff)
downloadFreeBSD-src-ff47d7260c161e26931b5956c9db0c9c70464ca0.zip
FreeBSD-src-ff47d7260c161e26931b5956c9db0c9c70464ca0.tar.gz
Use closefrom(2) instead of close(2) in a loop.
MFC after: 1 week
Diffstat (limited to 'sbin/hastd/hooks.c')
-rw-r--r--sbin/hastd/hooks.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/sbin/hastd/hooks.c b/sbin/hastd/hooks.c
index 2e43357..bd13242 100644
--- a/sbin/hastd/hooks.c
+++ b/sbin/hastd/hooks.c
@@ -88,32 +88,19 @@ static void hook_free(struct hookproc *hp);
static void
descriptors(void)
{
- long maxfd;
int fd;
/*
- * Close all descriptors.
+ * Close all (or almost all) descriptors.
*/
- maxfd = sysconf(_SC_OPEN_MAX);
- if (maxfd < 0) {
- pjdlog_errno(LOG_WARNING, "sysconf(_SC_OPEN_MAX) failed");
- maxfd = 1024;
- }
- 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)
+ if (pjdlog_mode_get() == PJDLOG_MODE_STD) {
+ closefrom(MAX(MAX(STDIN_FILENO, STDOUT_FILENO),
+ STDERR_FILENO) + 1);
return;
+ }
+
+ closefrom(0);
+
/*
* Redirect stdin, stdout and stderr to /dev/null.
*/
OpenPOWER on IntegriCloud