[or-cvs] r13060: Backport r12341: If setting our rlimit to rlim_max or cap fa (in tor/branches/tor-0_1_2-patches: . doc src/common)

nickm at seul.org nickm at seul.org
Mon Jan 7 20:03:27 UTC 2008


Author: nickm
Date: 2008-01-07 15:03:27 -0500 (Mon, 07 Jan 2008)
New Revision: 13060

Modified:
   tor/branches/tor-0_1_2-patches/
   tor/branches/tor-0_1_2-patches/configure.in
   tor/branches/tor-0_1_2-patches/doc/TODO.012
   tor/branches/tor-0_1_2-patches/src/common/compat.c
Log:
 r17507 at catbus:  nickm | 2008-01-07 15:03:24 -0500
 Backport r12341: If setting our rlimit to rlim_max or cap fails, fall back to OPEN_FILES if defiled.  This makes Tor run on OSX 10.5, while allowing OSX to mend its ways in the future.



Property changes on: tor/branches/tor-0_1_2-patches
___________________________________________________________________
 svk:merge ticket from /tor/012 [r17507] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/branches/tor-0_1_2-patches/configure.in
===================================================================
--- tor/branches/tor-0_1_2-patches/configure.in	2008-01-07 19:51:42 UTC (rev 13059)
+++ tor/branches/tor-0_1_2-patches/configure.in	2008-01-07 20:03:27 UTC (rev 13060)
@@ -490,7 +490,7 @@
 
 dnl These headers are not essential
 
-AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netintet/in.h netinet/in6.h)
+AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netintet/in.h netinet/in6.h sys/syslimits.h)
 
 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
 [#ifdef HAVE_SYS_TYPES_H

Modified: tor/branches/tor-0_1_2-patches/doc/TODO.012
===================================================================
--- tor/branches/tor-0_1_2-patches/doc/TODO.012	2008-01-07 19:51:42 UTC (rev 13059)
+++ tor/branches/tor-0_1_2-patches/doc/TODO.012	2008-01-07 20:03:27 UTC (rev 13060)
@@ -10,7 +10,7 @@
   X no need to backport the windows privoxy.config changes because they're
     not in SVN??
   o r12339: rlim_t may be wider than unsigned long.
-  - r12341: Work if the real open-file limit is OPEN_FILES.
+  o r12341: Work if the real open-file limit is OPEN_FILES.
   o r12459: Exit policies reject public IP address too
 
 Backport for 0.1.2.x once better tested:

Modified: tor/branches/tor-0_1_2-patches/src/common/compat.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/common/compat.c	2008-01-07 19:51:42 UTC (rev 13059)
+++ tor/branches/tor-0_1_2-patches/src/common/compat.c	2008-01-07 20:03:27 UTC (rev 13060)
@@ -94,6 +94,9 @@
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
+#ifdef HAVE_SYS_SYSLIMITS_H
+#include <sys/syslimits.h>
+#endif
 
 #ifdef USE_BSOCKETS
 #include <bsocket.h>
@@ -653,9 +656,33 @@
   }
   rlim.rlim_cur = most;
   if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
-    log_warn(LD_CONFIG, "Could not set maximum number of file descriptors: %s",
-             strerror(errno));
-    return -1;
+    int bad = 1;
+#ifdef OPEN_MAX
+    if (errno == EINVAL && OPEN_MAX < rlim.rlim_cur) {
+      /* On some platforms, OPEN_MAX is the real limit, and getrlimit() is
+       * full of nasty lies.  I'm looking at you, OSX 10.5.... */
+      rlim.rlim_cur = OPEN_MAX;
+      if (setrlimit(RLIMIT_NOFILE, &rlim) == 0) {
+        if (rlim.rlim_cur < limit) {
+          log_warn(LD_CONFIG, "We are limited to %lu file descriptors by "
+                 "OPEN_MAX, and ConnLimit is %lu.  Changing ConnLimit; sorry.",
+                   (unsigned long)OPEN_MAX, limit);
+        } else {
+          log_info(LD_CONFIG, "Dropped connection limit to OPEN_MAX (%lu); "
+                   "Apparently, %lu was too high and rlimit lied to us.",
+                  (unsigned long)OPEN_MAX, (unsigned long)most);
+        }
+        most = rlim.rlim_cur;
+        bad = 0;
+      }
+    }
+#endif
+    if (bad) {
+      log_warn(LD_CONFIG,
+               "Couldn't set maximum number of file descriptors: %s",
+               strerror(errno));
+      return -1;
+    }
   }
   /* leave some overhead for logs, etc, */
   limit = most;



More information about the tor-commits mailing list