From: Michael Tremer Date: Thu, 28 Jan 2021 18:10:35 +0000 (+0000) Subject: client+server: Configure ulimits before opening any connections X-Git-Tag: 0.1.0~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d48117cb3daa188ce68794e150731b99cf0a8cce;p=fireperf.git client+server: Configure ulimits before opening any connections Signed-off-by: Michael Tremer --- diff --git a/src/main.c b/src/main.c index db9fe54..6ea628d 100644 --- a/src/main.c +++ b/src/main.c @@ -19,10 +19,14 @@ #############################################################################*/ #include +#include #include #include #include #include +#include +#include +#include #include "client.h" #include "main.h" @@ -54,6 +58,22 @@ static int parse_address(const char* string, struct in6_addr* address6) { return 1; } +static int set_limits(struct fireperf_config* conf) { + struct rlimit limit; + + // Increase limit of open files + limit.rlim_cur = limit.rlim_max = conf->parallel + 128; + + 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)); + return 1; + } + + return 0; +} + static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { static struct option long_options[] = { {"client", required_argument, 0, 'c'}, @@ -175,6 +195,11 @@ int main(int argc, char* argv[]) { DEBUG(&conf, "Configuration:\n"); DEBUG(&conf, " Port = %d\n", conf.port); + // Set limits + r = set_limits(&conf); + if (r) + return r; + switch (conf.mode) { case FIREPERF_MODE_CLIENT: return fireperf_client(&conf);