[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] hack: set MaxConn to the hard ulimit -n rather than letting...



Update of /home2/or/cvsroot/tor/src/common
In directory moria.mit.edu:/home2/arma/work/onion/0091/tor/src/common

Modified Files:
      Tag: tor-0_0_9-patches
	compat.c compat.h 
Log Message:
hack: set MaxConn to the hard ulimit -n rather than letting the
user pick one.


Index: compat.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.22.2.4
retrieving revision 1.22.2.5
diff -u -d -r1.22.2.4 -r1.22.2.5
--- compat.c	3 Feb 2005 19:55:42 -0000	1.22.2.4
+++ compat.c	4 Feb 2005 00:44:02 -0000	1.22.2.5
@@ -354,8 +354,8 @@
 
 /** Get the maximum allowed number of file descriptors. (Some systems
  * have a low soft limit.) Make sure we set it to at least
- * <b>required_min</b>. Return 0 if we can, or -1 if we fail. */
-int set_max_file_descriptors(unsigned int required_min) {
+ * 1024. Return 0 if we can, or -1 if we fail. */
+int set_max_file_descriptors(unsigned int *maxconn) {
 #ifndef HAVE_GETRLIMIT
   log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding.");
   return 0; /* hope we'll be ok */
@@ -367,11 +367,11 @@
            strerror(errno));
     return -1;
   }
-  if (required_min > rlim.rlim_max) {
-    log_fn(LOG_WARN,"We need %u file descriptors available, and we're limited to %lu. Please change your ulimit.", required_min, (unsigned long int)rlim.rlim_max);
+  if (rlim.rlim_max < 1024) {
+    log_fn(LOG_WARN,"We need %u file descriptors available, and we're limited to %lu. Please change your ulimit.", 1024, (unsigned long int)rlim.rlim_max);
     return -1;
   }
-  if (required_min > rlim.rlim_cur) {
+  if (rlim.rlim_max > rlim.rlim_cur) {
     log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.",
            (unsigned long int)rlim.rlim_cur, (unsigned long int)rlim.rlim_max);
   }
@@ -381,6 +381,7 @@
            strerror(errno));
     return -1;
   }
+  *maxconn = (rlim.rlim_max - 32); /* leave some overhead for logs, etc */
   return 0;
 #endif
 }

Index: compat.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.13.2.4
retrieving revision 1.13.2.5
diff -u -d -r1.13.2.4 -r1.13.2.5
--- compat.h	3 Feb 2005 19:55:42 -0000	1.13.2.4
+++ compat.h	4 Feb 2005 00:44:02 -0000	1.13.2.5
@@ -177,7 +177,7 @@
 void set_uint32(char *cp, uint32_t v);
 #endif
 
-int set_max_file_descriptors(unsigned int required_min);
+int set_max_file_descriptors(unsigned int *maxconn);
 int switch_id(char *user, char *group);
 #ifdef HAVE_PWD_H
 char *get_user_homedir(const char *username);