diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 15 | ||||
-rw-r--r-- | src/common/compat.h | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index c3c3ca2a0a..66e55f9bea 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -362,7 +362,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2]) /** Get the maximum allowed number of file descriptors. (Some systems * have a low soft limit.) Make sure we set it to at least * <b>*limit</b>. Return a new limit if we can, or -1 if we fail. */ -int set_max_file_descriptors(int limit, int cap) { +int +set_max_file_descriptors(unsigned long limit, unsigned long cap) { #ifndef HAVE_GETRLIMIT log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding."); if (limit > cap) { @@ -371,7 +372,9 @@ int set_max_file_descriptors(int limit, int cap) { } #else struct rlimit rlim; - int most; + unsigned long most; + tor_assert(limit > 0); + tor_assert(cap > 0); if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) { log_fn(LOG_WARN, "Could not get maximum number of file descriptors: %s", @@ -379,13 +382,13 @@ int set_max_file_descriptors(int limit, int cap) { return -1; } if (rlim.rlim_max < limit) { - log_fn(LOG_WARN,"We need %d file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long int)rlim.rlim_max); + log_fn(LOG_WARN,"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 = ((rlim.rlim_max > cap) ? cap : rlim.rlim_max); + most = (rlim.rlim_max > cap) ? cap : (unsigned) 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); + log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.", + (unsigned long)rlim.rlim_cur, most); } rlim.rlim_cur = most; if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) { diff --git a/src/common/compat.h b/src/common/compat.h index fbb44d0fa4..04ca605df0 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -197,7 +197,7 @@ void set_uint16(char *cp, uint16_t v); void set_uint32(char *cp, uint32_t v); #endif -int set_max_file_descriptors(int limit, int cap); +int set_max_file_descriptors(unsigned long limit, unsigned long cap); int switch_id(char *user, char *group); #ifdef HAVE_PWD_H char *get_user_homedir(const char *username); |