diff options
author | Marcel Telka <marcel.telka@nexenta.com> | 2013-10-16 08:24:11 +0200 |
---|---|---|
committer | Dan McDonald <danmcd@nexenta.com> | 2013-11-13 16:30:59 -0500 |
commit | 97adda444bedd8afa322c1d2233957d40bc8e35c (patch) | |
tree | b3d342d05af704823a41fb936e5e94b2136b90f6 | |
parent | 7140fde549ff65142379ea6e25e6276552e22f3f (diff) | |
download | illumos-joyent-97adda444bedd8afa322c1d2233957d40bc8e35c.tar.gz |
4226 mountd(1m) could run out of file descriptors
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Jan Kryl <jan.kryl@nexenta.com>
Approved by: Eric Schrock <eric.schrock@delphix.com>
-rw-r--r-- | usr/src/cmd/fs.d/nfs/lib/nfs_sec.c | 18 | ||||
-rw-r--r-- | usr/src/cmd/fs.d/nfs/mountd/mountd.c | 15 |
2 files changed, 25 insertions, 8 deletions
diff --git a/usr/src/cmd/fs.d/nfs/lib/nfs_sec.c b/usr/src/cmd/fs.d/nfs/lib/nfs_sec.c index c4bd67232c..db163a9d93 100644 --- a/usr/src/cmd/fs.d/nfs/lib/nfs_sec.c +++ b/usr/src/cmd/fs.d/nfs/lib/nfs_sec.c @@ -24,6 +24,9 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright 2013 Nexenta Systems, Inc. All rights reserved. + */ /* * nfs security related library routines. @@ -68,6 +71,7 @@ static struct sc_data sc_service[] = { NULL, SC_FAILURE }; +static mutex_t matching_lock = DEFAULTMUTEX; static char *gettoken(char *, int); extern int atoi(const char *str); @@ -354,15 +358,15 @@ nfs_get_qop_name(seconfig_t *entryp) { char *tok; /* holds a token from the line */ char *secname, *gss_qop = NULL; /* pointer to a secmode name */ - static mutex_t matching_lock = DEFAULTMUTEX; char line[BUFSIZ]; /* holds each line of NFSSEC_CONF */ FILE *fp; /* file stream for NFSSEC_CONF */ + (void) mutex_lock(&matching_lock); if ((fp = fopen(NFSSEC_CONF, "r")) == NULL) { + (void) mutex_unlock(&matching_lock); return (NULL); } - (void) mutex_lock(&matching_lock); while (fgets(line, BUFSIZ, fp)) { if (!(blank(line) || comment(line))) { if ((secname = gettoken(line, FALSE)) == NULL) { @@ -389,8 +393,8 @@ nfs_get_qop_name(seconfig_t *entryp) } } err: - (void) mutex_unlock(&matching_lock); (void) fclose(fp); + (void) mutex_unlock(&matching_lock); return (gss_qop); } @@ -698,18 +702,18 @@ static int get_seconfig(int whichway, char *name, int num, rpc_gss_service_t service, seconfig_t *entryp) { - static mutex_t matching_lock = DEFAULTMUTEX; char line[BUFSIZ]; /* holds each line of NFSSEC_CONF */ FILE *fp; /* file stream for NFSSEC_CONF */ if ((whichway == GETBYNAME) && (name == NULL)) return (SC_NOTFOUND); + (void) mutex_lock(&matching_lock); if ((fp = fopen(NFSSEC_CONF, "r")) == NULL) { + (void) mutex_unlock(&matching_lock); return (SC_OPENFAIL); } - (void) mutex_lock(&matching_lock); while (fgets(line, BUFSIZ, fp)) { if (!(blank(line) || comment(line))) { switch (whichway) { @@ -730,13 +734,13 @@ get_seconfig(int whichway, char *name, int num, } } } - (void) mutex_unlock(&matching_lock); (void) fclose(fp); + (void) mutex_unlock(&matching_lock); return (SC_NOTFOUND); found: - (void) mutex_unlock(&matching_lock); (void) fclose(fp); + (void) mutex_unlock(&matching_lock); (void) get_rpcnum(entryp); return (SC_NOERROR); } diff --git a/usr/src/cmd/fs.d/nfs/mountd/mountd.c b/usr/src/cmd/fs.d/nfs/mountd/mountd.c index a5358f7e91..3d17d3b044 100644 --- a/usr/src/cmd/fs.d/nfs/mountd/mountd.c +++ b/usr/src/cmd/fs.d/nfs/mountd/mountd.c @@ -19,7 +19,7 @@ * CDDL HEADER END * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright 2013 Nexenta Systems, Inc. All rights reserved. */ /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ @@ -31,6 +31,7 @@ */ #include <stdio.h> +#include <stdio_ext.h> #include <stdlib.h> #include <ctype.h> #include <sys/types.h> @@ -49,6 +50,7 @@ #include <sys/systeminfo.h> #include <sys/utsname.h> #include <sys/wait.h> +#include <sys/resource.h> #include <signal.h> #include <locale.h> #include <unistd.h> @@ -364,6 +366,7 @@ main(int argc, char *argv[]) long thr_flags = (THR_NEW_LWP|THR_DAEMON); char defval[4]; int defvers, ret, bufsz; + struct rlimit rl; int pipe_fd = -1; @@ -390,6 +393,16 @@ main(int argc, char *argv[]) exit(1); } + if (getrlimit(RLIMIT_NOFILE, &rl) != 0) { + syslog(LOG_ERR, "getrlimit failed"); + } else { + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_NOFILE, &rl) != 0) + syslog(LOG_ERR, "setrlimit failed"); + } + + (void) enable_extended_FILE_stdio(-1, -1); + maxthreads = 0; while ((c = getopt(argc, argv, "vrm:")) != EOF) { |