Repository: kudu
Updated Branches:
  refs/heads/master ba36a0b7d -> 65cb2edf5


sasl: provide a mutex implementation to cyrus-sasl

In looking around the SASL code I found some notes that it is not
inherently thread-safe, unless we provide it a mutex implementation
using sasl_set_mutex(). This does just that.

Change-Id: I357de7f5df86d1663440b53cef715d92bee2cbe2
Reviewed-on: http://gerrit.cloudera.org:8080/4762
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Dan Burkert <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/cd40d1c5
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/cd40d1c5
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/cd40d1c5

Branch: refs/heads/master
Commit: cd40d1c5126d0fd541d95370cdb2998b60f2f82c
Parents: ba36a0b
Author: Todd Lipcon <[email protected]>
Authored: Wed Oct 19 13:49:13 2016 -0700
Committer: Todd Lipcon <[email protected]>
Committed: Thu Oct 20 21:01:19 2016 +0000

----------------------------------------------------------------------
 src/kudu/rpc/sasl_common.cc | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/cd40d1c5/src/kudu/rpc/sasl_common.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/sasl_common.cc b/src/kudu/rpc/sasl_common.cc
index b2c7849..a15536f 100644
--- a/src/kudu/rpc/sasl_common.cc
+++ b/src/kudu/rpc/sasl_common.cc
@@ -28,6 +28,7 @@
 #include "kudu/gutil/once.h"
 #include "kudu/gutil/stringprintf.h"
 #include "kudu/util/flag_tags.h"
+#include "kudu/util/mutex.h"
 #include "kudu/util/net/sockaddr.h"
 
 using std::set;
@@ -120,6 +121,25 @@ static sasl_callback_t callbacks[] = {
   { SASL_CB_LIST_END, nullptr, nullptr }
 };
 
+
+// SASL requires mutexes for thread safety, but doesn't implement
+// them itself. So, we have to hook them up to our mutex implementation.
+static void* SaslMutexAlloc() {
+  return static_cast<void*>(new Mutex());
+}
+static void SaslMutexFree(void* m) {
+  delete static_cast<Mutex*>(m);
+}
+static int SaslMutexLock(void* m) {
+  static_cast<Mutex*>(m)->lock();
+  return 0; // indicates success.
+}
+static int SaslMutexUnlock(void* m) {
+  static_cast<Mutex*>(m)->unlock();
+  return 0; // indicates success.
+}
+
+
 // Determine whether initialization was ever called
 struct InitializationData {
   Status status;
@@ -135,6 +155,9 @@ static void DoSaslInit(void* app_name_char_array) {
   const char* const app_name = reinterpret_cast<const char* 
const>(app_name_char_array);
   VLOG(3) << "Initializing SASL library";
 
+  // Make SASL thread-safe.
+  sasl_set_mutex(&SaslMutexAlloc, &SaslMutexLock, &SaslMutexUnlock, 
&SaslMutexFree);
+
   sasl_init_data = new InitializationData();
   sasl_init_data->app_name = app_name;
 

Reply via email to