diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-11 16:51:56 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-11 16:51:56 -0500 |
commit | eccef6ba60e59c6d7001d8f6623eb4d01ea8ca11 (patch) | |
tree | 63a1b020cef2c76e7f3a4bd72786b5f5844e515e | |
parent | 86583ad78e6c75ea0094553584428f795089c482 (diff) | |
parent | 5dc785ceef465125f180f020991ec2c363bb8abc (diff) | |
download | tor-eccef6ba60e59c6d7001d8f6623eb4d01ea8ca11.tar.gz tor-eccef6ba60e59c6d7001d8f6623eb4d01ea8ca11.zip |
Merge branch 'maint-0.2.9' into maint-0.3.1
-rw-r--r-- | changes/bug21074_downgrade | 4 | ||||
-rw-r--r-- | src/common/compat.c | 14 |
2 files changed, 11 insertions, 7 deletions
diff --git a/changes/bug21074_downgrade b/changes/bug21074_downgrade new file mode 100644 index 0000000000..c9f81bd137 --- /dev/null +++ b/changes/bug21074_downgrade @@ -0,0 +1,4 @@ + o Minor bugfixes: + - Don't exit the Tor process if setrlimit() fails to change the file + limit (which can happen sometimes on some versions of OSX). Fixes + bug 21074; bugfix on 0.0.9pre5. diff --git a/src/common/compat.c b/src/common/compat.c index 4d110aba35..4a1f0013c6 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1665,7 +1665,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> @@ -1730,13 +1730,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((rlim_t) 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 " @@ -1751,14 +1752,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 /* 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, */ |