[or-cvs] fix wmf"s bug. now we don"t try to squeeze UINT_MAX into IN...
Roger Dingledine
arma at seul.org
Thu Feb 17 04:58:33 UTC 2005
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
Log Message:
fix wmf's bug. now we don't try to squeeze UINT_MAX into INT_MAX.
nick, can you review this?
Index: compat.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.22.2.8
retrieving revision 1.22.2.9
diff -u -d -r1.22.2.8 -r1.22.2.9
--- compat.c 4 Feb 2005 07:16:10 -0000 1.22.2.8
+++ compat.c 17 Feb 2005 04:58:30 -0000 1.22.2.9
@@ -361,6 +361,7 @@
return 0; /* hope we'll be ok */
#else
struct rlimit rlim;
+ int most;
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
log_fn(LOG_WARN, "Could not get maximum number of file descriptors: %s",
@@ -371,17 +372,19 @@
log_fn(LOG_WARN,"We need %u file descriptors available, and we're limited to %lu. Please change your ulimit -n.", 1024, (unsigned long int)rlim.rlim_max);
return -1;
}
- 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);
+ most = ((rlim.rlim_max > INT_MAX) ? INT_MAX : rlim.rlim_max);
+ if (most > rlim.rlim_cur) {
+ log_fn(LOG_INFO,"Raising max file descriptors from %lu to %d.",
+ (unsigned long int)rlim.rlim_cur, most);
}
- rlim.rlim_cur = rlim.rlim_max;
+ rlim.rlim_cur = most;
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
log_fn(LOG_WARN, "Could not set maximum number of file descriptors: %s",
strerror(errno));
return -1;
}
- *maxconn = (rlim.rlim_max - 32); /* leave some overhead for logs, etc */
+ /* leave some overhead for logs, etc, and don't overflow INT_MAX */
+ *maxconn = most - 32;
return 0;
#endif
}
More information about the tor-commits
mailing list