From ef71ca445b7c99f28ca80fe75fbe6b843ecc6fcb Mon Sep 17 00:00:00 2001 From: Kozlov Dmitry Date: Wed, 18 May 2011 11:36:44 +0400 Subject: use /proc/sys/fs/nr_open in conjuction with /proc/sys/fs/file-max to determine limit of maximum number of opened files --- accel-pppd/main.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/accel-pppd/main.c b/accel-pppd/main.c index 2e48c45..c408736 100644 --- a/accel-pppd/main.c +++ b/accel-pppd/main.c @@ -89,19 +89,28 @@ static void change_limits(void) { FILE *f; struct rlimit lim; - unsigned int file_max; + unsigned int file_max = 1024*1024; + unsigned int nr_open = 1024*1024; + + f = fopen("/proc/sys/fs/nr_open", "r"); + if (f) { + fscanf(f, "%d", &nr_open); + fclose(f); + } f = fopen("/proc/sys/fs/file-max", "r"); if (f) { fscanf(f, "%d", &file_max); fclose(f); + } + + if (file_max > nr_open) + file_max = nr_open; - lim.rlim_cur = file_max; - lim.rlim_max = file_max; - if (setrlimit(RLIMIT_NOFILE, &lim)) - log_emerg("main: setrlimit: %s\n", strerror(errno)); - } else - log_emerg("main: failed to open '/proc/sys/fs/file-max': %s\n", strerror(errno)); + lim.rlim_cur = file_max; + lim.rlim_max = file_max; + if (setrlimit(RLIMIT_NOFILE, &lim)) + log_emerg("main: setrlimit: %s\n", strerror(errno)); } static void config_reload_notify(int r) -- cgit v1.2.3