]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5134] Proposed patch to prevent static initialization fiasco.
authorMarcin Siodelski <marcin@isc.org>
Fri, 24 Feb 2017 15:42:11 +0000 (16:42 +0100)
committerMarcin Siodelski <marcin@isc.org>
Fri, 24 Feb 2017 15:42:11 +0000 (16:42 +0100)
On FreeBSD11 system the Control Agent unit tests fail because the
destructor of the LibraryManager is referencing ServerHooks. Both
are static and in this particular case the LibraryManager outlives
the other one.

src/lib/hooks/library_manager.cc
src/lib/hooks/library_manager.h
src/lib/hooks/server_hooks.cc
src/lib/hooks/server_hooks.h

index dfc25fa9af5149c2a296beee95e422b34d3fdde0..ab10837da962cb77cea3f1dbce4c664e8c67cbe6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -33,7 +33,8 @@ namespace hooks {
 LibraryManager::LibraryManager(const std::string& name, int index,
                                const boost::shared_ptr<CalloutManager>& manager)
         : dl_handle_(NULL), index_(index), manager_(manager),
-          library_name_(name)
+          library_name_(name),
+          server_hooks_(ServerHooks::getServerHooksPtr())
 {
     if (!manager) {
         isc_throw(NoCalloutManager, "must specify a CalloutManager when "
index 03f3ddfd7a9e11b37b651937bd66573c1aea0c98..5f6bc4cac727fcee324ebef5005a2e50bc476dd6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,7 +8,7 @@
 #define LIBRARY_MANAGER_H
 
 #include <exceptions/exceptions.h>
-
+#include <hooks/server_hooks.h>
 #include <boost/shared_ptr.hpp>
 
 #include <string>
@@ -219,6 +219,8 @@ private:
                                 ///< Callout manager for registration
     std::string library_name_;  ///< Name of the library
 
+    ServerHooksPtr server_hooks_; ///< Stores a pointer to ServerHooks.
+
 };
 
 } // namespace hooks
index ebd416998b3ad28aaaa5eae4a4e6b15a264e3b79..504446cb40860162c4daa434fe98f700b6552572 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -142,7 +142,12 @@ ServerHooks::getHookNames() const {
 
 ServerHooks&
 ServerHooks::getServerHooks() {
-    static ServerHooks hooks;
+    return (*getServerHooksPtr());
+}
+
+ServerHooksPtr
+ServerHooks::getServerHooksPtr() {
+    static ServerHooksPtr hooks(new ServerHooks());
     return (hooks);
 }
 
index 246cb83e61c4b5a154ae8343d2877d6501f1038c..3c052ad8f63a0ed9fde3b3efc981443b70bdca46 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -10,6 +10,7 @@
 #include <exceptions/exceptions.h>
 
 #include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include <map>
 #include <string>
@@ -37,6 +38,8 @@ public:
         isc::Exception(file, line, what) {}
 };
 
+class ServerHooks;
+typedef boost::shared_ptr<ServerHooks> ServerHooksPtr;
 
 /// @brief Server hook collection
 ///
@@ -133,6 +136,11 @@ public:
     /// @return Reference to the global ServerHooks object.
     static ServerHooks& getServerHooks();
 
+    /// @brief Returns pointer to ServerHooks object.
+    ///
+    /// @return Pointer to the global ServerHooks object.
+    static ServerHooksPtr getServerHooksPtr();
+
 private:
     /// @brief Constructor
     ///