mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
bug #4662: Removes double unlocks from MarketPlace. Adds SSL callbacks
for multithread calls
This commit is contained in:
parent
7676ab6c62
commit
8bba5b8b73
@ -23,6 +23,8 @@
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
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<pthread_mutex_t *> vmutex;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* _NEBULA_UTIL_H_ */
|
||||
|
@ -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<pthread_mutex_t *> 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; i<CRYPTO_num_locks(); i++)
|
||||
{
|
||||
pm = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
|
||||
pthread_mutex_init(pm, NULL);
|
||||
|
||||
vmutex.push_back(pm);
|
||||
}
|
||||
|
||||
CRYPTO_set_id_callback((unsigned long (*)()) sslmutex_id_callback);
|
||||
|
||||
CRYPTO_set_locking_callback(
|
||||
(void (*)(int, int, const char*, int))sslmutex_lock_callback);
|
||||
}
|
||||
|
||||
one_util::SSLMutex::~SSLMutex()
|
||||
{
|
||||
for (int i=0; i<CRYPTO_num_locks(); i++)
|
||||
{
|
||||
pthread_mutex_destroy(vmutex[i]);
|
||||
free(vmutex[i]);
|
||||
}
|
||||
|
||||
CRYPTO_set_locking_callback(NULL);
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,9 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
|
||||
|
||||
if ( app->from_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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user