aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-05-26 10:07:22 -0700
committerBen Pfaff <blp@nicira.com>2010-05-26 15:27:01 -0700
commit0ec6cfb13b4d9ef14b90119cf662e47ed559a185 (patch)
tree2c6668a67cc83fa1933fefda5568cc00042054cc
parent3762274e6359f4afe04107851f4c71347fa0afa0 (diff)
socket-util: Tolerate missing RLIM_SAVED_CUR and RLIM_SAVED_MAX.
POSIX requires these macros, but FreeBSD 8.0 doesn't have them.
-rw-r--r--lib/socket-util.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 3af74a48..bf563eda 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -55,6 +55,28 @@ set_nonblocking(int fd)
}
}
+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. */
int
get_max_fds(void)
@@ -62,10 +84,7 @@ 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) {
+ 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");