Add Nicira extension for remote command execution.
[sliver-openvswitch.git] / lib / socket-util.c
index 781bcb8..d8ae179 100644 (file)
@@ -41,6 +41,7 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/resource.h>
 #include <sys/un.h>
 #include <unistd.h>
 #include "fatal-signal.h"
@@ -68,6 +69,26 @@ set_nonblocking(int fd)
     }
 }
 
+/* Returns the maximum valid FD value, plus 1. */
+int
+get_max_fds(void)
+{
+    static int max_fds = -1;
+    if (max_fds < 0) {
+        struct rlimit r;
+        if (!getrlimit(RLIMIT_NOFILE, &r)
+            && r.rlim_cur != RLIM_INFINITY
+            && r.rlim_cur != RLIM_SAVED_MAX
+            && r.rlim_cur != RLIM_SAVED_CUR) {
+            max_fds = r.rlim_cur;
+        } else {
+            VLOG_WARN("failed to obtain fd limit, defaulting to 1024");
+            max_fds = 1024;
+        }
+    }
+    return max_fds;
+}
+
 /* Translates 'host_name', which may be a DNS name or an IP address, into a
  * numeric IP address in '*addr'.  Returns 0 if successful, otherwise a
  * positive errno value. */