From 86f87784985faf4ec73b8dd9b0de61aca44461b3 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 21 Dec 2006 20:34:16 +0000 Subject: Fix for bug #180, logging is not threadsafe, mutex it (ew, luckily we dont log much) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6056 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_mysql.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/modules/extra') diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 86f87496e..fe23eee8c 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -195,6 +195,8 @@ pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t results_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t logging_mutex = PTHREAD_MUTEX_INITIALIZER; + /** Represents a mysql result set */ class MySQLresult : public SQLresult @@ -581,24 +583,20 @@ void ConnectDatabases(InspIRCd* ServerInstance) for (ConnMap::iterator i = Connections.begin(); i != Connections.end(); i++) { i->second->SetEnable(true); - if (i->second->Connect()) - { - ServerInstance->Log(DEFAULT,"SQL: Successfully connected database "+i->second->GetHost()); - } - else + if (!i->second->Connect()) { + /* XXX: MUTEX */ + pthread_mutex_lock(&logging_mutex); ServerInstance->Log(DEFAULT,"SQL: Failed to connect database "+i->second->GetHost()+": Error: "+i->second->GetError()); i->second->SetEnable(false); + pthread_mutex_unlock(&logging_mutex); } } } - void LoadDatabases(ConfigReader* ThisConf, InspIRCd* ServerInstance) { - ServerInstance->Log(DEFAULT,"SQL: Loading database settings"); Connections.clear(); - ServerInstance->Log(DEBUG,"Cleared connections"); for (int j =0; j < ThisConf->Enumerate("database"); j++) { std::string db = ThisConf->ReadValue("database","name",j); @@ -606,13 +604,10 @@ void LoadDatabases(ConfigReader* ThisConf, InspIRCd* ServerInstance) std::string pass = ThisConf->ReadValue("database","password",j); std::string host = ThisConf->ReadValue("database","hostname",j); std::string id = ThisConf->ReadValue("database","id",j); - ServerInstance->Log(DEBUG,"Read database settings"); if ((db != "") && (host != "") && (user != "") && (id != "") && (pass != "")) { SQLConnection* ThisSQL = new SQLConnection(host,user,pass,db,id); - ServerInstance->Log(DEFAULT,"Loaded database: "+ThisSQL->GetHost()); Connections[id] = ThisSQL; - ServerInstance->Log(DEBUG,"Pushed back connection"); } } ConnectDatabases(ServerInstance); -- cgit v1.2.3