aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-03-19 14:26:45 -0400
committerNick Mathewson <nickm@torproject.org>2013-03-19 14:26:45 -0400
commit8d29866bec821e188a411f78b8112d2097ed106c (patch)
tree905cd7e57ecae14b3873054247ad0e8db6c72128 /src
parentde7e99f8bbc17bfaea260c6d8e2217678b5152af (diff)
parent22804c0391f0549356959e1b474c43bfcba1b8cb (diff)
downloadtor-8d29866bec821e188a411f78b8112d2097ed106c.tar
tor-8d29866bec821e188a411f78b8112d2097ed106c.tar.gz
Merge remote-tracking branch 'public/bug8002' into maint-0.2.4
Diffstat (limited to 'src')
-rw-r--r--src/common/compat.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 4fa9fee42..c97a4545c 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -2313,8 +2313,33 @@ compute_num_cpus_impl(void)
return (int)info.dwNumberOfProcessors;
else
return -1;
-#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
- long cpus = sysconf(_SC_NPROCESSORS_CONF);
+#elif defined(HAVE_SYSCONF)
+#ifdef _SC_NPROCESSORS_CONF
+ long cpus_conf = sysconf(_SC_NPROCESSORS_CONF);
+#else
+ long cpus_conf = -1;
+#endif
+#ifdef _SC_NPROCESSORS_ONLN
+ long cpus_onln = sysconf(_SC_NPROCESSORS_ONLN);
+#else
+ long cpus_onln = -1;
+#endif
+ long cpus = -1;
+
+ if (cpus_conf > 0 && cpus_onln < 0) {
+ cpus = cpus_conf;
+ } else if (cpus_onln > 0 && cpus_conf < 0) {
+ cpus = cpus_onln;
+ } else if (cpus_onln > 0 && cpus_conf > 0) {
+ if (cpus_onln < cpus_conf) {
+ log_notice(LD_GENERAL, "I think we have %ld CPUS, but only %ld of them "
+ "are available. Telling Tor to only use %ld. You can over"
+ "ride this with the NumCPUs option",
+ cpus_conf, cpus_onln, cpus_onln);
+ }
+ cpus = cpus_onln;
+ }
+
if (cpus >= 1 && cpus < INT_MAX)
return (int)cpus;
else