summaryrefslogtreecommitdiff
path: root/source3/param
diff options
context:
space:
mode:
authortodd stecher <todd.stecher@gmail.com>2009-02-19 09:33:30 -0800
committerSteven Danneman <steven.danneman@isilon.com>2009-02-20 16:35:48 -0800
commitd9a842b26f306a6328e0fb4f226ed8292a8c221a (patch)
tree38dccdf56470b5ee4e0a97dcf20fc477a522fd4a /source3/param
parent193be432a224918bf0fbecfb6705146476c15c07 (diff)
downloadsamba-d9a842b26f306a6328e0fb4f226ed8292a8c221a.tar.gz
samba-d9a842b26f306a6328e0fb4f226ed8292a8c221a.tar.bz2
samba-d9a842b26f306a6328e0fb4f226ed8292a8c221a.zip
S3: Detect max_open_files from system
- Attempt to use syscalls to determine max-open-files value. - Add in periodic logging when max file limit reached
Diffstat (limited to 'source3/param')
-rw-r--r--source3/param/loadparm.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 37af7038c1..cb568256c7 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -4657,6 +4657,42 @@ static void init_printer_values(struct service *pService)
}
}
+/**
+ * Function to return the default value for the maximum number of open
+ * file descriptors permitted. This function tries to consult the
+ * kernel-level (sysctl) and ulimit (getrlimit()) values and goes
+ * the smaller of those.
+ */
+static int max_open_files(void)
+{
+ int sysctl_max;
+ struct rlimit rl;
+ bool sysctl_worked = false, rlimit_worked = false;
+
+#ifdef HAVE_SYSCTLBYNAME
+ size_t size = sizeof(sysctl_max);
+ if (sysctlbyname("kern.maxfilesperproc", &sysctl_max, &size, NULL,0)==0)
+ sysctl_worked = true;
+#endif
+
+ if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
+ rlimit_worked = true;
+
+ if (sysctl_worked) {
+ if ((!rlimit_worked) ||
+ (rl.rlim_cur == RLIM_INFINITY) ||
+ (rl.rlim_cur > sysctl_max))
+ return sysctl_max;
+ else
+ return rl.rlim_cur;
+ } else {
+ if ((!rlimit_worked) ||
+ (rl.rlim_cur == RLIM_INFINITY))
+ return MAX_OPEN_FILES;
+ else
+ return rl.rlim_cur;
+ }
+}
/**
* Common part of freeing allocated data for one parameter.
@@ -4880,7 +4916,7 @@ static void init_globals(bool first_time_only)
Globals.getwd_cache = true;
Globals.bLargeReadwrite = True;
Globals.max_log_size = 5000;
- Globals.max_open_files = MAX_OPEN_FILES;
+ Globals.max_open_files = max_open_files();
Globals.open_files_db_hash_size = SMB_OPEN_DATABASE_TDB_HASH_SIZE;
Globals.maxprotocol = PROTOCOL_NT1;
Globals.minprotocol = PROTOCOL_CORE;