From 393b24fe894312605801141718b3e6f5195cf1bd Mon Sep 17 00:00:00 2001 From: Neil Cook Date: Wed, 26 Oct 2016 14:32:35 +0000 Subject: [PATCH 1/2] pthread-based locking for arc4random --- configure.ac | 2 +- src/compat/arc4_lock.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index b2c066a2..90a27d04 100644 --- a/configure.ac +++ b/configure.ac @@ -644,7 +644,7 @@ CHECK_CFLAGS="" PKG_CHECK_MODULES([CHECK],[check >= 0.9.6],[CHECK_GETDNS="check_getdns"],[ AC_SEARCH_LIBS([floor], [m]) AC_SEARCH_LIBS([timer_create], [rt]) -AC_SEARCH_LIBS([pthread_create], [pthread]) +AC_SEARCH_LIBS([pthread_create], [pthread], [AC_DEFINE([HAVE_PTHREADS], [1], [Define if pthreads exist.])]) AC_SEARCH_LIBS([srunner_create],[check check_pic],[ CHECK_GETDNS="check_getdns" CHECK_LIBS="$LIBS"],[ diff --git a/src/compat/arc4_lock.c b/src/compat/arc4_lock.c index 44662841..facf9575 100644 --- a/src/compat/arc4_lock.c +++ b/src/compat/arc4_lock.c @@ -34,6 +34,23 @@ #include "config.h" #define LOCKRET(func) func +#ifdef HAVE_PTHREADS +#include "pthread.h" + +static pthread_mutex_t arc_lock = PTHREAD_MUTEX_INITIALIZER; + +void _ARC4_LOCK(void) +{ + pthread_mutex_lock(&arc_lock); +} + +void _ARC4_UNLOCK(void) +{ + pthread_mutex_unlock(&arc_lock); +} + +#else +/* XXX - add windows-(or at least non pthread) specific lock routines here */ void _ARC4_LOCK(void) { } @@ -41,4 +58,4 @@ void _ARC4_LOCK(void) void _ARC4_UNLOCK(void) { } - +#endif From db6cee94fa537bff05f6a01a92b3cbb322adc4dc Mon Sep 17 00:00:00 2001 From: Neil Cook Date: Wed, 26 Oct 2016 15:47:44 +0000 Subject: [PATCH 2/2] Fix HAVE_PTHREADS define in configure.ac --- configure.ac | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 90a27d04..e8a1650b 100644 --- a/configure.ac +++ b/configure.ac @@ -644,7 +644,7 @@ CHECK_CFLAGS="" PKG_CHECK_MODULES([CHECK],[check >= 0.9.6],[CHECK_GETDNS="check_getdns"],[ AC_SEARCH_LIBS([floor], [m]) AC_SEARCH_LIBS([timer_create], [rt]) -AC_SEARCH_LIBS([pthread_create], [pthread], [AC_DEFINE([HAVE_PTHREADS], [1], [Define if pthreads exist.])]) +AC_SEARCH_LIBS([pthread_create], [pthread]) AC_SEARCH_LIBS([srunner_create],[check check_pic],[ CHECK_GETDNS="check_getdns" CHECK_LIBS="$LIBS"],[ @@ -924,6 +924,10 @@ if [ test -n "$DOXYGEN" ] fi +#---- check for pthreads library +AC_SEARCH_LIBS([pthread_mutex_init],[pthread],[AC_DEFINE([HAVE_PTHREADS], [1], [Have pthreads library])], [AC_MSG_WARN([pthreads not available])]) + + dnl ----- dnl ----- Start of "Things needed for gldns" section dnl -----