crypto: fix non-reentrancy of ceph::crypto::init

This could be called multiple times from common_preinit.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
This commit is contained in:
Colin Patrick McCabe 2011-05-05 12:44:40 -07:00
parent 429bf1fe93
commit 921d4b3d8b
2 changed files with 26 additions and 4 deletions

View File

@ -1,5 +1,21 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2010-2011 Dreamhost
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "ceph_crypto.h"
#include <pthread.h>
#ifdef USE_CRYPTOPP
// nothing
ceph::crypto::HMACSHA1::~HMACSHA1()
@ -9,6 +25,16 @@ ceph::crypto::HMACSHA1::~HMACSHA1()
#elif USE_NSS
void ceph::crypto::init() {
static pthread_mutex_t lock;
static bool crypto_init = false;
pthread_mutex_lock(&lock);
if (crypto_init) {
pthread_mutex_unlock(&lock);
return;
}
crypto_init = true;
pthread_mutex_unlock(&lock);
SECStatus s;
s = NSS_NoDB_Init(NULL);
assert(s == SECSuccess);

View File

@ -116,10 +116,6 @@ md_config_t *common_preinit(const CephInitParameters &iparams,
break;
}
// TODO this is not idempotent! we are relying on
// libceph_initialized/rados_initialized to guard us from being
// called more than once in 3rd party apps, and on coding
// conventions in Ceph daemons/tools
ceph::crypto::init();
return conf;
}