]> git.ipfire.org Git - fireperf.git/commitdiff
client+server: Configure ulimits before opening any connections
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 28 Jan 2021 18:10:35 +0000 (18:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 28 Jan 2021 18:10:35 +0000 (18:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/main.c

index db9fe54269d97a1a72207e74010740707b152c21..6ea628d1ecbf3f9d8239802fd1f93bf15a45bee4 100644 (file)
 #############################################################################*/
 
 #include <arpa/inet.h>
+#include <errno.h>
 #include <getopt.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 
 #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);