diff options
author | jilles <jilles@FreeBSD.org> | 2013-04-27 13:26:35 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-04-27 13:26:35 +0000 |
commit | 72dbb34e66701a0d22f36de94acbb3f84e7fcb79 (patch) | |
tree | 5aa9e483274d2af7f5508cdbb7053c4be365119f /usr.sbin/syslogd/syslogd.c | |
parent | ba8e6992c30d728a8b2f366027f189a6cafba364 (diff) | |
download | FreeBSD-src-72dbb34e66701a0d22f36de94acbb3f84e7fcb79.zip FreeBSD-src-72dbb34e66701a0d22f36de94acbb3f84e7fcb79.tar.gz |
syslogd: Use closefrom() instead of getdtablesize()/close() loop.
When syslogd forks a process for '|' destinations, it closes all file
descriptors greater than 2.
Use closefrom() for this instead of a getdtablesize()/close() loop because
it is both faster and avoids leaving file descriptors open because the limit
was lowered after they were opened.
MFC after: 1 week
Diffstat (limited to 'usr.sbin/syslogd/syslogd.c')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index bb56b6b..8fc2678 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -2476,7 +2476,7 @@ validate(struct sockaddr *sa, const char *hname) static int p_open(const char *prog, pid_t *rpid) { - int pfd[2], nulldesc, i; + int pfd[2], nulldesc; pid_t pid; sigset_t omask, mask; char *argv[4]; /* sh -c cmd NULL */ @@ -2526,8 +2526,7 @@ p_open(const char *prog, pid_t *rpid) dup2(pfd[0], STDIN_FILENO); dup2(nulldesc, STDOUT_FILENO); dup2(nulldesc, STDERR_FILENO); - for (i = getdtablesize(); i > 2; i--) - (void)close(i); + closefrom(3); (void)execvp(_PATH_BSHELL, argv); _exit(255); |