From bf7d1a55afd4e082813e995fd967ad1dae8df26d Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 23 May 2012 15:09:41 -0400 Subject: Fixed some problems found by Robby --- modules/database/db_sql.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'modules/database/db_sql.cpp') diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index ef272c3f0..b4b81375c 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -58,6 +58,7 @@ class DBSQL : public Module, public Pipe SQLSQLInterface sqlinterface; Anope::string prefix; std::set > updated_items; + bool shutting_down; void RunBackground(const SQLQuery &q, SQLInterface *iface = NULL) { @@ -81,16 +82,16 @@ class DBSQL : public Module, public Pipe } public: - DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this) + DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this), shutting_down(false) { this->SetAuthor("Anope"); - Implementation i[] = { I_OnReload, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate }; + Implementation i[] = { I_OnReload, I_OnShutdown, I_OnRestart, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); this->OnReload(); } - + void OnNotify() anope_override { for (std::set >::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it) @@ -125,6 +126,17 @@ class DBSQL : public Module, public Pipe this->prefix = config.ReadValue("db_sql", "prefix", "anope_db_", 0); } + void OnShutdown() anope_override + { + this->shutting_down = true; + this->OnNotify(); + } + + void OnRestart() anope_override + { + this->OnShutdown(); + } + EventReturn OnLoadDatabase() anope_override { if (!this->sql) @@ -167,6 +179,8 @@ class DBSQL : public Module, public Pipe void OnSerializableConstruct(Serializable *obj) anope_override { + if (this->shutting_down) + return; this->updated_items.insert(obj); this->Notify(); } @@ -178,7 +192,7 @@ class DBSQL : public Module, public Pipe void OnSerializableUpdate(Serializable *obj) anope_override { - if (obj->IsTSCached()) + if (this->shutting_down || obj->IsTSCached()) return; obj->UpdateTS(); this->updated_items.insert(obj); -- cgit