From ef25cb39a9cb9e36a8872dcd252686023eaec959 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 18 Mar 2021 11:36:55 +0100 Subject: passt: Set soft limit for number of open files to hard limit Default value for /proc/sys/fs/nr_open is 2^20, which is more than enough: set this hard limit as current (soft) limit on start, and drop the 'ulimit -n' from the demo script. Signed-off-by: Stefano Brivio --- passt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'passt.c') diff --git a/passt.c b/passt.c index 9786221..6b160c0 100644 --- a/passt.c +++ b/passt.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -513,6 +514,7 @@ int main(int argc, char **argv) struct timespec last_time; struct ctx c = { 0 }; int nfds, i, fd_unix; + struct rlimit limit; if (argc != 1) usage(argv[0]); @@ -528,6 +530,16 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } + if (getrlimit(RLIMIT_NOFILE, &limit)) { + perror("getrlimit"); + exit(EXIT_FAILURE); + } + limit.rlim_cur = limit.rlim_max; + if (setrlimit(RLIMIT_NOFILE, &limit)) { + perror("setrlimit"); + exit(EXIT_FAILURE); + } + if (icmp_sock_init(&c) || tcp_sock_init(&c) || udp_sock_init(&c)) exit(EXIT_FAILURE); -- cgit v1.2.3