aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-01-16 14:13:39 -0500
committerNick Mathewson <nickm@torproject.org>2018-01-16 14:13:39 -0500
commit454d85436385a7ee0b60f18834d707d72b08b915 (patch)
treef5bb20faeb465f1046393b636f164c3810335c5f /src
parentf470756cf4660bd7d5e9d4c8d66a56adfd3b7ff7 (diff)
parent68ca6d2e1971372617f920e71a4a51e16900095e (diff)
downloadtor-454d85436385a7ee0b60f18834d707d72b08b915.tar.gz
tor-454d85436385a7ee0b60f18834d707d72b08b915.zip
Merge branch 'bug21074_029'
Diffstat (limited to 'src')
-rw-r--r--src/common/compat.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index b4bd6eba06..7c9b2f808e 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1675,7 +1675,7 @@ get_max_sockets(void)
* fail by returning -1 and <b>max_out</b> is untouched.
*
* If we are unable to set the limit value because of setrlimit() failing,
- * return -1 and <b>max_out</b> is set to the current maximum value returned
+ * return 0 and <b>max_out</b> is set to the current maximum value returned
* by getrlimit().
*
* Otherwise, return 0 and store the maximum we found inside <b>max_out</b>
@@ -1740,13 +1740,14 @@ set_max_file_descriptors(rlim_t limit, int *max_out)
rlim.rlim_cur = rlim.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
- int bad = 1;
+ int couldnt_set = 1;
+ const int setrlimit_errno = errno;
#ifdef OPEN_MAX
uint64_t try_limit = OPEN_MAX - ULIMIT_BUFFER;
if (errno == EINVAL && try_limit < (uint64_t) 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 = try_limit;
+ rlim.rlim_cur = MIN(try_limit, rlim.rlim_cur);
if (setrlimit(RLIMIT_NOFILE, &rlim) == 0) {
if (rlim.rlim_cur < (rlim_t)limit) {
log_warn(LD_CONFIG, "We are limited to %lu file descriptors by "
@@ -1761,14 +1762,13 @@ set_max_file_descriptors(rlim_t limit, int *max_out)
(unsigned long)try_limit, (unsigned long)OPEN_MAX,
(unsigned long)rlim.rlim_max);
}
- bad = 0;
+ couldnt_set = 0;
}
}
#endif /* defined(OPEN_MAX) */
- if (bad) {
+ if (couldnt_set) {
log_warn(LD_CONFIG,"Couldn't set maximum number of file descriptors: %s",
- strerror(errno));
- return -1;
+ strerror(setrlimit_errno));
}
}
/* leave some overhead for logs, etc, */