From 3ca314bffcd18c2cc965594b46ca058e57aaa7e9 Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 18 Feb 2008 15:25:54 +0000 Subject: 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 --- src/modules/extra/m_mysql.cpp | 20 ++++++++++++++++++-- 1 file 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 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) -- cgit v1.2.3