Skip to content
Snippets Groups Projects
Commit 405f5c4e authored by Giuseppe Lo Presti's avatar Giuseppe Lo Presti
Browse files

Fixed bug #99123: Unsafe usage of locks in CastorConfiguration.

Patch provided by David Abdurachmanov (CMSSW).
parent a7192b4f
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,7 @@ castor::common::CastorConfiguration::getConfig(std::string fileName)
// do we have this configuration already in cache ?
if (s_castorConfigs.end() == s_castorConfigs.find(fileName)) {
// no such configuration. Create it
s_castorConfigs[fileName] = CastorConfiguration(fileName);
s_castorConfigs.insert(std::make_pair(fileName, CastorConfiguration(fileName)));
}
// we can now release the lock. Concurrent read only access is ok.
pthread_mutex_unlock(&s_globalConfigLock);
......@@ -79,6 +79,20 @@ castor::common::CastorConfiguration::CastorConfiguration(std::string fileName)
}
}
//------------------------------------------------------------------------------
// copy constructor
//------------------------------------------------------------------------------
castor::common::CastorConfiguration::CastorConfiguration(const CastorConfiguration & other)
throw (castor::exception::Exception): m_fileName(other.m_fileName),
m_lastUpdateTime(other.m_lastUpdateTime), m_config(other.m_config) {
// create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
throw e;
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......@@ -87,6 +101,23 @@ castor::common::CastorConfiguration::~CastorConfiguration() {
pthread_rwlock_destroy(&m_lock);
}
//------------------------------------------------------------------------------
// assignment operator
//------------------------------------------------------------------------------
castor::common::CastorConfiguration & castor::common::CastorConfiguration::operator=(const castor::common::CastorConfiguration & other)
throw (castor::exception::Exception) {
m_fileName = other.m_fileName;
m_lastUpdateTime = other.m_lastUpdateTime;
m_config = other.m_config;
// create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
throw e;
}
return *this;
}
//------------------------------------------------------------------------------
// getConfEnt
//------------------------------------------------------------------------------
......
......@@ -66,11 +66,25 @@ namespace castor {
CastorConfiguration(std::string fileName = "/etc/castor/castor.conf")
throw (castor::exception::Exception);
/**
* copy constructor
* @param other instance of CastorConfiguration class
*/
CastorConfiguration(const CastorConfiguration & other)
throw (castor::exception::Exception);
/**
* destrcutor
*/
virtual ~CastorConfiguration();
/**
* assignment operator
* @param other instance of CastorConfiguration class
*/
CastorConfiguration & operator=(const CastorConfiguration & other)
throw (castor::exception::Exception);
/**
* retrieves a configuration entry
* @param category the category of the entry
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment