[or-cvs] r12339: Use rlim_t instead of unsigned long to manipulate rlimit val (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Fri Nov 2 14:50:37 UTC 2007


Author: nickm
Date: 2007-11-02 10:50:37 -0400 (Fri, 02 Nov 2007)
New Revision: 12339

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/configure.in
   tor/trunk/src/common/compat.c
Log:
 r14647 at tombo:  nickm | 2007-11-02 10:48:37 -0400
 Use rlim_t instead of unsigned long to manipulate rlimit values.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14647] on d9e39d38-0f13-419c-a857-e10a0ce2aa0c

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-11-02 08:47:30 UTC (rev 12338)
+++ tor/trunk/ChangeLog	2007-11-02 14:50:37 UTC (rev 12339)
@@ -76,7 +76,10 @@
     - Stop leaking v2_download_status_map on shutdown.  Bugfix on
       0.2.0.9-alpha.
 
+  - Minor bugfixes (portability):
+    - Run correctly on platforms where rlim_t is larger than unsigned long.
 
+
 Changes in version 0.2.0.9-alpha - 2007-10-24
   This ninth development snapshot switches clients to the new v3 directory
   system; allows servers to be listed in the network status even when they

Modified: tor/trunk/configure.in
===================================================================
--- tor/trunk/configure.in	2007-11-02 08:47:30 UTC (rev 12338)
+++ tor/trunk/configure.in	2007-11-02 14:50:37 UTC (rev 12339)
@@ -362,6 +362,12 @@
 #endif
 ])
 
+AC_CHECK_TYPES([rlim_t], , ,
+[#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+])
+
 if test -z "$CROSS_COMPILE"; then
 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
 AC_RUN_IFELSE(AC_LANG_SOURCE([

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2007-11-02 08:47:30 UTC (rev 12338)
+++ tor/trunk/src/common/compat.c	2007-11-02 14:50:37 UTC (rev 12339)
@@ -663,6 +663,10 @@
 
 #define ULIMIT_BUFFER 32 /* keep 32 extra fd's beyond _ConnLimit */
 
+#if defined(HAVE_GETRLIMIT) && !defined(HAVE_RLIM_T)
+typedef unsigned long rlim_t;
+#endif
+
 /** Learn the maximum allowed number of file descriptors. (Some systems
  * have a low soft limit.
  *
@@ -684,7 +688,7 @@
   }
 #else
   struct rlimit rlim;
-  unsigned long most;
+  rlim_t most;
   tor_assert(limit > 0);
   tor_assert(cap > 0);
 
@@ -693,16 +697,17 @@
              strerror(errno));
     return -1;
   }
+  //log_notice(LD_CONFIG, "%llu %llu", rlim.rlim_cur, rlim.rlim_max);
   if ((unsigned long)rlim.rlim_max < limit) {
     log_warn(LD_CONFIG,"We need %lu file descriptors available, and we're "
              "limited to %lu. Please change your ulimit -n.",
              limit, (unsigned long)rlim.rlim_max);
     return -1;
   }
-  most = ((unsigned long)rlim.rlim_max > cap) ? cap : (unsigned) rlim.rlim_max;
+  most = rlim.rlim_max > (rlim_t)cap ? (rlim_t)cap : rlim.rlim_max;
   if (most > (unsigned long)rlim.rlim_cur) {
     log_info(LD_NET,"Raising max file descriptors from %lu to %lu.",
-             (unsigned long)rlim.rlim_cur, most);
+             (unsigned long)rlim.rlim_cur, (unsigned long)most);
   }
   rlim.rlim_cur = most;
   if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {



More information about the tor-commits mailing list