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;
}