Module: sems Branch: sayer/1.4-spce2.5 Commit: b397d727dcaa3c9a12841acd488b18efb7d0c9ea URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=b397d727dcaa3c9a12841acd488b18efb7d0c9ea
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Wed Aug 8 11:02:39 2012 +0200 b/f: db_reg_agent: also shutdown cleanly on rapid shutdown (e.g. signal 15) otherwise the processing thread continues to run, and the process crashes on shutdown --- apps/db_reg_agent/DBRegAgent.cpp | 15 +++++++++++++++ apps/db_reg_agent/DBRegAgent.h | 4 ++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/apps/db_reg_agent/DBRegAgent.cpp b/apps/db_reg_agent/DBRegAgent.cpp index 7aada69..6e4b8ac 100644 --- a/apps/db_reg_agent/DBRegAgent.cpp +++ b/apps/db_reg_agent/DBRegAgent.cpp @@ -240,6 +240,19 @@ int DBRegAgent::onLoad() } void DBRegAgent::onUnload() { + if (running) { + running = false; + DBG("unclean shutdown. Waiting for processing thread to stop.\n"); + for (int i=0;i<20;i++) { + if (shutdown_finished) + break; + usleep(2000); // 2ms + } + if (!shutdown_finished) { + WARN("processing thread could not be stopped, process will probably crash\n"); + } + } + DBG("closing main DB connection\n"); MainDBConnection.disconnect(); DBG("closing auxiliary DB connection\n"); @@ -878,6 +891,7 @@ void DBRegAgent::run() { registration_processor.start(); } + shutdown_finished = false; DBG("running DBRegAgent thread...\n"); while (running) { processEvents(); @@ -899,6 +913,7 @@ void DBRegAgent::run() { mysqlpp::Connection::thread_end(); DBG("DBRegAgent thread stopped.\n"); + shutdown_finished = true; } void DBRegAgent::on_stop() { diff --git a/apps/db_reg_agent/DBRegAgent.h b/apps/db_reg_agent/DBRegAgent.h index 9ea3903..bbb0861 100644 --- a/apps/db_reg_agent/DBRegAgent.h +++ b/apps/db_reg_agent/DBRegAgent.h @@ -230,8 +230,12 @@ class DBRegAgent unsigned int expires; + /** processing thread running? */ bool running; + /** processing thread shutdown finished? */ + bool shutdown_finished; + AmDynInvoke* uac_auth_i; void DIcreateRegistration(int subscriber_id, const string& user, _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
