From: Francis Dupont Date: Thu, 28 Jun 2018 01:24:48 +0000 (+0200) Subject: [3543] Fixed crashes at exit X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=636c8155ff9ea1a017cce232e9f3f87787ac2bbe;p=thirdparty%2Fkea.git [3543] Fixed crashes at exit --- diff --git a/src/bin/d2/d2_controller.cc b/src/bin/d2/d2_controller.cc index b04693d4df..8a771f54d8 100644 --- a/src/bin/d2/d2_controller.cc +++ b/src/bin/d2/d2_controller.cc @@ -64,9 +64,19 @@ D2Controller::parseFile(const std::string& file_name) { } D2Controller::~D2Controller() { + cerr << "dtor\n"; deregisterCommands(); } +void +D2Controller::d2ShutdownHandler() { + cerr << "shutting down\n"; + deregisterCommands(); + + isc::data::ConstElementPtr args; + DControllerBase::shutdownHandler("shutdown", args); +} + std::string D2Controller::getVersionAddendum() { std::stringstream stream; @@ -116,6 +126,8 @@ D2Controller::deregisterCommands() { } has_command_channel_ = false; + // Assume that command manager was not destroyed first... + // Close the command socket (if it exists). CommandMgr::instance().closeCommandSocket(); diff --git a/src/bin/d2/d2_controller.h b/src/bin/d2/d2_controller.h index f53cf6eb51..c9138315e7 100644 --- a/src/bin/d2/d2_controller.h +++ b/src/bin/d2/d2_controller.h @@ -46,6 +46,12 @@ public: /// by convention this should match the executable name. static const char* d2_bin_name_; + /// @brief handler for 'shutdown' command. + /// + /// This method handles shutdown command. It initiates the smooth shutdown + /// procedure using CPL methods. + void d2ShutdownHandler(); + /// @brief Register commands. void registerCommands(); diff --git a/src/bin/d2/main.cc b/src/bin/d2/main.cc index 7eb704467b..c9beb40f7b 100644 --- a/src/bin/d2/main.cc +++ b/src/bin/d2/main.cc @@ -10,7 +10,7 @@ #include #include #include - +#include #include using namespace isc::d2; @@ -25,12 +25,12 @@ using namespace std; int main(int argc, char* argv[]) { int ret = EXIT_SUCCESS; + // Instantiate/fetch the DHCP-DDNS application controller singleton. + DControllerBasePtr& controller = D2Controller::instance(); + // Launch the controller passing in command line arguments. // Exit program with the controller's return code. try { - // Instantiate/fetch the DHCP-DDNS application controller singleton. - DControllerBasePtr& controller = D2Controller::instance(); - // 'false' value disables test mode. controller->launch(argc, argv, false); } catch (const VersionMessage& ex) { @@ -49,5 +49,7 @@ int main(int argc, char* argv[]) { ret = EXIT_FAILURE; } + boost::dynamic_pointer_cast(controller)->d2ShutdownHandler(); + return (ret); }