From: Michael Tremer Date: Tue, 17 Aug 2021 15:16:54 +0000 (+0000) Subject: rlimit: Automatically set to maximum X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=7c14f08117e47eefc385538bbd07188172e98c23;p=fireperf.git rlimit: Automatically set to maximum Signed-off-by: Michael Tremer --- diff --git a/src/main.c b/src/main.c index 4c836d6..3af95bc 100644 --- a/src/main.c +++ b/src/main.c @@ -110,16 +110,25 @@ static int parse_port(struct fireperf_config* conf, const char* optarg) { static int set_limits(struct fireperf_config* conf) { struct rlimit limit; - // Increase limit of open files - limit.rlim_cur = limit.rlim_max = conf->parallel + conf->listening_sockets + 128; + // Fetch current limit + if (getrlimit(RLIMIT_NOFILE, &limit) < 0) { + ERROR(conf, "Could not read RLIMIT_NOFILE: %m\n"); + return 1; + } + // Set current value to maximum + limit.rlim_cur = limit.rlim_max; + + // Apply the new limit int r = setrlimit(RLIMIT_NOFILE, &limit); if (r) { - ERROR(conf, "Could not set open file limit to %lu: %s\n", - (unsigned long)limit.rlim_max, strerror(errno)); + ERROR(conf, "Could not set open file limit to %lu: %m\n", + (unsigned long)limit.rlim_cur); return 1; } + DEBUG(conf, "RLIMIT_NOFILE set to %lu\n", (unsigned long)limit.rlim_cur); + return 0; }