aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@ev0ke.net>2015-06-02 16:37:11 -0400
committerDavid Goulet <dgoulet@ev0ke.net>2015-08-05 13:17:33 -0400
commit79798a23637db7e5a4bb05c860b2932b3b1a3010 (patch)
tree26570576b67d283a1e6845877b893a02d8479f63
parent9338847bf427b59d6dd5634fc2f8998ce0e269c1 (diff)
downloadtor-79798a23637db7e5a4bb05c860b2932b3b1a3010.tar.gz
tor-79798a23637db7e5a4bb05c860b2932b3b1a3010.zip
Set the open file limit to the current value before changing it
If setrlimit() failed, max_out wasn't set in set_max_file_descriptors() ending in a state where we don't use ULIMIT_BUFFER for things like tor private key files. Also fix the set_max_file_descriptors() documentation. Fixes #16274 Signed-off-by: David Goulet <dgoulet@ev0ke.net>
-rw-r--r--changes/bug162745
-rw-r--r--src/common/compat.c24
2 files changed, 21 insertions, 8 deletions
diff --git a/changes/bug16274 b/changes/bug16274
new file mode 100644
index 0000000000..4eec571761
--- /dev/null
+++ b/changes/bug16274
@@ -0,0 +1,5 @@
+ o Minor bugfix (open file limit):
+ - Fix set_max_file_descriptors() to set by default the max open file
+ limit to the current limit in case setrlimit() fails so we at least
+ have a usable value; Fixes #16274; bugfix on tor-0.2.0.10-alpha~71;
+ Patch by dgoulet.
diff --git a/src/common/compat.c b/src/common/compat.c
index 306081754e..28b8344852 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1600,15 +1600,23 @@ get_max_sockets(void)
* tell Tor it's allowed to use. */
#define ULIMIT_BUFFER 32 /* keep 32 extra fd's beyond ConnLimit_ */
-/** Learn the maximum allowed number of file descriptors, and tell the system
- * we want to use up to that number. (Some systems have a low soft limit, and
- * let us set it higher.)
+/** Learn the maximum allowed number of file descriptors, and tell the
+ * system we want to use up to that number. (Some systems have a low soft
+ * limit, and let us set it higher.) We compute this by finding the largest
+ * number that we can use.
*
- * We compute this by finding the largest number that we can use.
- * If we can't find a number greater than or equal to <b>limit</b>,
- * then we fail: return -1.
+ * If the limit is below the reserved file descriptor value (ULIMIT_BUFFER),
+ * return -1 and <b>max_out</b> is untouched.
*
- * Otherwise, return 0 and store the maximum we found inside <b>max_out</b>.*/
+ * If we can't find a number greater than or equal to <b>limit</b>, then we
+ * 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
+ * by getrlimit().
+ *
+ * Otherwise, return 0 and store the maximum we found inside <b>max_out</b>
+ * and set <b>max_sockets</b> with that value as well.*/
int
set_max_file_descriptors(rlim_t limit, int *max_out)
{
@@ -1665,7 +1673,7 @@ set_max_file_descriptors(rlim_t limit, int *max_out)
}
/* Set the current limit value so if the attempt to set the limit to the
* max fails at least we'll have a valid value of maximum sockets. */
- max_sockets = (int)rlim.rlim_cur - ULIMIT_BUFFER;
+ *max_out = max_sockets = (int)rlim.rlim_cur - ULIMIT_BUFFER;
rlim.rlim_cur = rlim.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {