diff options
author | Kozlov Dmitry <dima@server> | 2011-05-18 11:36:44 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2011-05-18 11:36:44 +0400 |
commit | ef71ca445b7c99f28ca80fe75fbe6b843ecc6fcb (patch) | |
tree | 5a3addfae3966e73d648f52f608e1db06c04fde9 /accel-pppd/main.c | |
parent | 3cbee16f1ae968ae80d7e8fbe6a4359a901b3f40 (diff) | |
download | accel-ppp-ef71ca445b7c99f28ca80fe75fbe6b843ecc6fcb.tar.gz accel-ppp-ef71ca445b7c99f28ca80fe75fbe6b843ecc6fcb.zip |
use /proc/sys/fs/nr_open in conjuction with /proc/sys/fs/file-max to determine limit of maximum number of opened files
Diffstat (limited to 'accel-pppd/main.c')
-rw-r--r-- | accel-pppd/main.c | 23 |
1 files 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) |