]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3543] Fixed crashes at exit
authorFrancis Dupont <fdupont@isc.org>
Thu, 28 Jun 2018 01:24:48 +0000 (03:24 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 27 Dec 2018 20:00:17 +0000 (21:00 +0100)
src/bin/d2/d2_controller.cc
src/bin/d2/d2_controller.h
src/bin/d2/main.cc

index b04693d4df0580bed2070fa0a779564b73c27e66..8a771f54d8c4a288241af67d5656a15c313348b1 100644 (file)
@@ -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();
 
index f53cf6eb5117d4490dc46d52dfac903f71678f5a..c9138315e738d46872e5aa869f9f3afa9ef608bb 100644 (file)
@@ -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();
 
index 7eb704467b4d0e72c7f5bb2a8726aaa3eb33429f..c9beb40f7b6581cad45c4dd75846fd31323b0506 100644 (file)
@@ -10,7 +10,7 @@
 #include <exceptions/exceptions.h>
 #include <log/logger_support.h>
 #include <log/logger_manager.h>
-
+#include <boost/pointer_cast.hpp>
 #include <iostream>
 
 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<D2Controller>(controller)->d2ShutdownHandler();
+
     return (ret);
 }