From 1eba088054eca1555b455ee4a2adfafecb888af9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 24 Sep 2016 08:48:47 -0700 Subject: [PATCH 1/3] Fix compilation on OSX Sierra (10.12) --- configure.ac | 1 + src/common/compat_pthreads.c | 2 +- src/common/crypto.c | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3c80e71c5..a799a5563 100644 --- a/configure.ac +++ b/configure.ac @@ -986,6 +986,7 @@ AC_CHECK_HEADERS( sys/mman.h \ sys/param.h \ sys/prctl.h \ + sys/random.h \ sys/resource.h \ sys/select.h \ sys/socket.h \ diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c index 1b24cc3c2..7640ebae3 100644 --- a/src/common/compat_pthreads.c +++ b/src/common/compat_pthreads.c @@ -247,7 +247,7 @@ tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex, const struct timeval *tv) return -1; } tvnow.tv_sec = ts.tv_sec; - tvnow.tv_usec = ts.tv_nsec / 1000; + tvnow.tv_usec = (int)(ts.tv_nsec / 1000); timeradd(tv, &tvnow, &tvsum); #else if (gettimeofday(&tvnow, NULL) < 0) diff --git a/src/common/crypto.c b/src/common/crypto.c index 2b96324d3..f147dbd71 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -77,6 +77,9 @@ #ifdef HAVE_SYS_SYSCALL_H #include #endif +#ifdef HAVE_SYS_RANDOM_H +#include +#endif #include "torlog.h" #include "aes.h" From 951638a06d20263d33e501bdfa317c34b850f2b8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 24 Sep 2016 09:12:00 -0700 Subject: [PATCH 2/3] Fix pthread_cond_timedwait() on OSX Sierra Sierra provides clock_gettime(), but not pthread_condattr_setclock. So we had better lot try to use CLOCK_MONOTONIC as our source for time when waiting, since we ccan never actually tell the condition that we mean CLOCK_MONOTONIC. This isn't a tor bug yet, since we never actually pass a timeout to tor_cond_wait() outside of the unit tests. --- src/common/compat_pthreads.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c index 7640ebae3..4c0567665 100644 --- a/src/common/compat_pthreads.c +++ b/src/common/compat_pthreads.c @@ -192,14 +192,21 @@ tor_cond_init(tor_cond_t *cond) return -1; } -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) \ - && defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) +#if defined(HAVE_CLOCK_GETTIME) +#if defined(CLOCK_MONOTONIC) && defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) /* Use monotonic time so when we timedwait() on it, any clock adjustment * won't affect the timeout value. */ if (pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)) { return -1; } -#endif +#define USE_COND_CLOCK CLOCK_MONOTONIC +#else /* !defined HAVE_PTHREAD_CONDATTR_SETCLOCK */ + /* On OSX Sierra, there is no pthread_condattr_setclock, so we are stuck + * with the realtime clock. + */ +#define USE_COND_CLOCK CLOCK_REALTIME +#endif /* which clock to use */ +#endif /* HAVE_CLOCK_GETTIME */ if (pthread_cond_init(&cond->cond, &condattr)) { return -1; } @@ -242,8 +249,8 @@ tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex, const struct timeval *tv) struct timeval tvnow, tvsum; struct timespec ts; while (1) { -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) - if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) { +#if defined(HAVE_CLOCK_GETTIME) && defined(USE_COND_CLOCK) + if (clock_gettime(USE_COND_CLOCK, &ts) < 0) { return -1; } tvnow.tv_sec = ts.tv_sec; From 39f51dfae312d67f4a97366db4b476d520ed0c0f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 24 Sep 2016 13:29:20 -0700 Subject: [PATCH 3/3] changes file for osx sierra fixes --- changes/ticket20241 | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changes/ticket20241 diff --git a/changes/ticket20241 b/changes/ticket20241 new file mode 100644 index 000000000..7c592f736 --- /dev/null +++ b/changes/ticket20241 @@ -0,0 +1,3 @@ + o Minor features (compilation, portability): + - Tor now compiles correctly on MacOS 10.12 (aka "Sierra"). Closes + ticket 20241.