summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-21 20:34:16 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-21 20:34:16 +0000
commit86f87784985faf4ec73b8dd9b0de61aca44461b3 (patch)
treec3dbde309a9dd5f311716217b4e0034b6db2b9ae /src/modules
parentea1b0d4b16f0a68af426c04f5e9ab437da2d6302 (diff)
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
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_mysql.cpp17
1 files changed, 6 insertions, 11 deletions
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);