]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mysql.cpp
Allow freeform queries. Allow $nick, $host, $ip, $pass, $md5pass and $sha256pass...
[user/henk/code/inspircd.git] / src / modules / extra / m_mysql.cpp
index 0e9a3a6315f573c5d509fd79834314868bcd19e9..bd8b6a57f33e03cbc43a7d372619dc062d6e436a 100644 (file)
@@ -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;
@@ -542,7 +543,7 @@ void ConnectDatabases(InspIRCd* ServerInstance)
                {
                        /* XXX: MUTEX */
                        pthread_mutex_lock(&logging_mutex);
-                       ServerInstance->Log(DEFAULT,"SQL: Failed to connect database "+i->second->GetHost()+": Error: "+i->second->GetError());
+                       ServerInstance->Logs->Log("m_mysql",DEFAULT,"SQL: Failed to connect database "+i->second->GetHost()+": Error: "+i->second->GetError());
                        i->second->SetEnable(false);
                        pthread_mutex_unlock(&logging_mutex);
                }
@@ -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->Logs->Log("m_mysql",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->Logs->Log("m_mysql",DEFAULT,"SQL: Error code from pthread_join() is " + rc);
+               }
                ClearAllConnections();
                delete Conf;
                ServerInstance->Modules->UnpublishInterface("SQL", this);
@@ -802,7 +818,7 @@ class ModuleSQL : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,1,0,0,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
+               return Version(1,2,0,0,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
        }
        
 };
@@ -881,7 +897,7 @@ void* DispatcherThread(void* arg)
                usleep(1000);
        }
 
-       return NULL;
+       pthread_exit((void *) 0);
 }
 
 MODULE_INIT(ModuleSQL)