summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-18 15:25:54 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-18 15:25:54 +0000
commit3ca314bffcd18c2cc965594b46ca058e57aaa7e9 (patch)
treee8bc71bf927934914baa7dc5419c4dec7a932504 /src
parentbaa907dc7039da22a08530cd7415482dd218aafb (diff)
Merge in patch by Darom that fixes race condition when unloading m_mysql.so that may cause it to crash, fixes bug #438
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8963 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/extra/m_mysql.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index 0e9a3a631..03dd99342 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -68,6 +68,7 @@ class Notifier;
typedef std::map<std::string, SQLConnection*> ConnMap;
bool giveup = false;
+bool threadfinished = false;
static Module* SQLModule = NULL;
static Notifier* MessagePipe = NULL;
int QueueFD = -1;
@@ -725,16 +726,24 @@ class ModuleSQL : public Module
pthread_attr_t attribs;
pthread_attr_init(&attribs);
- pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED);
+ pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE);
if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0)
{
throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno)));
}
+ pthread_attr_destroy(&attribs);
if (!ServerInstance->Modules->PublishFeature("SQL", this))
{
/* Tell worker thread to exit NOW */
+ int rc;
+ void *status;
giveup = true;
+ rc = pthread_join(Dispatcher, &status);
+ if (rc)
+ {
+ ServerInstance->Log(DEFAULT,"SQL: Error code from pthread_join() is " + rc);
+ }
throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
}
@@ -745,7 +754,14 @@ class ModuleSQL : public Module
virtual ~ModuleSQL()
{
+ int rc;
+ void *status;
giveup = true;
+ rc = pthread_join(Dispatcher, &status);
+ if (rc)
+ {
+ ServerInstance->Log(DEFAULT,"SQL: Error code from pthread_join() is " + rc);
+ }
ClearAllConnections();
delete Conf;
ServerInstance->Modules->UnpublishInterface("SQL", this);
@@ -881,7 +897,7 @@ void* DispatcherThread(void* arg)
usleep(1000);
}
- return NULL;
+ pthread_exit((void *) 0);
}
MODULE_INIT(ModuleSQL)