typedef std::map<std::string, SQLConnection*> ConnMap;
bool giveup = false;
+bool threadfinished = false;
static Module* SQLModule = NULL;
static Notifier* MessagePipe = NULL;
int QueueFD = -1;
{
/* 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);
}
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'");
}
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);
usleep(1000);
}
- return NULL;
+ pthread_exit((void *) 0);
}
MODULE_INIT(ModuleSQL)