summaryrefslogtreecommitdiff
path: root/lib/process.c
diff options
context:
space:
mode:
authorGurucharan Shetty <gshetty@nicira.com>2014-02-21 08:46:31 -0800
committerGurucharan Shetty <gshetty@nicira.com>2014-02-21 14:44:31 -0800
commit4f57ad100f4556c45a7ad4c4fe904545a99976e5 (patch)
tree39d61fc68ae31ecd373b933554c1d29483a404b3 /lib/process.c
parent7ff04d92445beaaea4123cbc3083d950278b1d55 (diff)
downloadopenvswitch-4f57ad100f4556c45a7ad4c4fe904545a99976e5.tar.gz
socket-util: Move get_max_fds() to process.c.
get_max_fds() is used only from process.c. Move it there along with rlim_is_finite(). Since process_start() can only be called before any additional threads are created, we no longer need the thread safety checks in get_max_fds(). Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/process.c')
-rw-r--r--lib/process.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/process.c b/lib/process.c
index d0e18821b..b479d005d 100644
--- a/lib/process.c
+++ b/lib/process.c
@@ -165,6 +165,49 @@ process_register(const char *name, pid_t pid)
return p;
}
+#ifndef _WIN32
+static bool
+rlim_is_finite(rlim_t limit)
+{
+ if (limit == RLIM_INFINITY) {
+ return false;
+ }
+
+#ifdef RLIM_SAVED_CUR /* FreeBSD 8.0 lacks RLIM_SAVED_CUR. */
+ if (limit == RLIM_SAVED_CUR) {
+ return false;
+ }
+#endif
+
+#ifdef RLIM_SAVED_MAX /* FreeBSD 8.0 lacks RLIM_SAVED_MAX. */
+ if (limit == RLIM_SAVED_MAX) {
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+/* Returns the maximum valid FD value, plus 1. */
+static int
+get_max_fds(void)
+{
+ static int max_fds;
+
+ if (!max_fds) {
+ struct rlimit r;
+ if (!getrlimit(RLIMIT_NOFILE, &r) && rlim_is_finite(r.rlim_cur)) {
+ max_fds = r.rlim_cur;
+ } else {
+ VLOG_WARN("failed to obtain fd limit, defaulting to 1024");
+ max_fds = 1024;
+ }
+ }
+
+ return max_fds;
+}
+#endif /* _WIN32 */
+
/* Starts a subprocess with the arguments in the null-terminated argv[] array.
* argv[0] is used as the name of the process. Searches the PATH environment
* variable to find the program to execute.