From 8bba5b8b7380c84e38d08fccae13ae48bc4d4a59 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 29 Jul 2016 17:50:52 +0200 Subject: [PATCH] bug #4662: Removes double unlocks from MarketPlace. Adds SSL callbacks for multithread calls --- include/NebulaUtil.h | 27 +++++++++++++ src/common/NebulaUtil.cc | 67 ++++++++++++++++++++++++++++++++ src/market/MarketPlaceAppPool.cc | 5 +++ src/nebula/Nebula.cc | 4 ++ 4 files changed, 103 insertions(+) diff --git a/include/NebulaUtil.h b/include/NebulaUtil.h index 9127339ab0..029faab109 100644 --- a/include/NebulaUtil.h +++ b/include/NebulaUtil.h @@ -23,6 +23,8 @@ #include #include +#include + namespace one_util { std::string& toupper(std::string& st); @@ -256,6 +258,31 @@ namespace one_util * of error */ std::string * zlib_decompress(const std::string& in, bool base64); + + extern "C" void sslmutex_lock_callback(int mode, int type, char *file, + int line); + + extern "C" unsigned long sslmutex_id_callback(); + + class SSLMutex + { + public: + static void initialize(); + + static void finalize(); + + private: + friend void sslmutex_lock_callback(int mode, int type, char *file, + int line); + + SSLMutex(); + + ~SSLMutex(); + + static SSLMutex * ssl_mutex; + + static std::vector vmutex; + }; }; #endif /* _NEBULA_UTIL_H_ */ diff --git a/src/common/NebulaUtil.cc b/src/common/NebulaUtil.cc index 3b7f9a434d..8679c75cfa 100644 --- a/src/common/NebulaUtil.cc +++ b/src/common/NebulaUtil.cc @@ -493,4 +493,71 @@ std::string * one_util::zlib_decompress(const std::string& in, bool base64) return new std::string(oss.str()); } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +extern "C" void one_util::sslmutex_lock_callback(int mode, int type, char *file, + int line) +{ + pthread_mutex_t * pm = SSLMutex::ssl_mutex->vmutex[type]; + + if (mode & CRYPTO_LOCK) + { + pthread_mutex_lock(pm); + } + else + { + pthread_mutex_unlock(pm); + } +} + +extern "C" unsigned long one_util::sslmutex_id_callback() +{ + return (unsigned long) pthread_self(); +} + +one_util::SSLMutex * one_util::SSLMutex::ssl_mutex; + +std::vector one_util::SSLMutex::vmutex; + +void one_util::SSLMutex::initialize() +{ + if ( ssl_mutex == 0 ) + { + ssl_mutex = new SSLMutex(); + } +}; + +void one_util::SSLMutex::finalize() +{ + delete ssl_mutex; +} + +one_util::SSLMutex::SSLMutex() +{ + pthread_mutex_t * pm; + for (int i=0; ifrom_template64(t64, error_str) != 0 ) { + app->lock(); delete app; + return -1; } @@ -235,7 +237,9 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id, mp_aux->unlock(); + app->lock(); delete app; + return -2; } @@ -246,6 +250,7 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id, { int oid = master_allocate(app, error_str); + app->lock(); delete app; return oid; diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 7e9ae0a5f5..5082eb0cbb 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -407,6 +407,8 @@ void Nebula::start(bool bootstrap_only) pthread_sigmask(SIG_BLOCK, &mask, NULL); + one_util::SSLMutex::initialize(); + // ----------------------------------------------------------- //Managers // ----------------------------------------------------------- @@ -994,6 +996,8 @@ void Nebula::start(bool bootstrap_only) //XML Library xmlCleanupParser(); + one_util::SSLMutex::finalize(); + NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n"); return;