]> git.ipfire.org Git - fireperf.git/commitdiff
rlimit: Automatically set to maximum
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Aug 2021 15:16:54 +0000 (15:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Aug 2021 15:16:54 +0000 (15:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/main.c

index 4c836d68eb871688bee87f26083c8bd4510e0866..3af95bcabc4db68d3df4b40f3d62686c1825b27b 100644 (file)
@@ -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;
 }