+/*
+ * Increase limit for open files for current process
+ */
+static int
+increase_open_file_limit(void)
+{
+ struct rlimit limit;
+
+ /* read current limits */
+ if (getrlimit(RLIMIT_NOFILE, &limit) != 0) {
+ RTE_LOG(ERR, EAL, "Error reading resource limit: %s\n",
+ strerror(errno));
+ return -1;
+ }
+
+ /* check if current soft limit matches the hard limit */
+ if (limit.rlim_cur < limit.rlim_max) {
+ /* set soft limit to match hard limit */
+ limit.rlim_cur = limit.rlim_max;
+ }
+ else {
+ /* we can't increase the soft limit so now we try to increase
+ * soft and hard limit. this might fail when run as non-root.
+ */
+ limit.rlim_cur *= 2;
+ limit.rlim_max *= 2;
+ }
+
+ /* set current resource limit */
+ if (setrlimit(RLIMIT_NOFILE, &limit) != 0) {
+ RTE_LOG(ERR, EAL, "Error increasing open files limit: %s\n",
+ strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+