Browse Source

[5134] Proposed patch to prevent static initialization fiasco.

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.
Marcin Siodelski 8 years ago
parent
commit
97ac3e79bf

+ 3 - 2
src/lib/hooks/library_manager.cc

@@ -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
 // 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
 // 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,
 LibraryManager::LibraryManager(const std::string& name, int index,
                                const boost::shared_ptr<CalloutManager>& manager)
                                const boost::shared_ptr<CalloutManager>& manager)
         : dl_handle_(NULL), index_(index), manager_(manager),
         : dl_handle_(NULL), index_(index), manager_(manager),
-          library_name_(name)
+          library_name_(name),
+          server_hooks_(ServerHooks::getServerHooksPtr())
 {
 {
     if (!manager) {
     if (!manager) {
         isc_throw(NoCalloutManager, "must specify a CalloutManager when "
         isc_throw(NoCalloutManager, "must specify a CalloutManager when "

+ 4 - 2
src/lib/hooks/library_manager.h

@@ -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
 // 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
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,7 +8,7 @@
 #define LIBRARY_MANAGER_H
 #define LIBRARY_MANAGER_H
 
 
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
-
+#include <hooks/server_hooks.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 
 
 #include <string>
 #include <string>
@@ -219,6 +219,8 @@ private:
                                 ///< Callout manager for registration
                                 ///< Callout manager for registration
     std::string library_name_;  ///< Name of the library
     std::string library_name_;  ///< Name of the library
 
 
+    ServerHooksPtr server_hooks_; ///< Stores a pointer to ServerHooks.
+
 };
 };
 
 
 } // namespace hooks
 } // namespace hooks

+ 7 - 2
src/lib/hooks/server_hooks.cc

@@ -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
 // 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
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -142,7 +142,12 @@ ServerHooks::getHookNames() const {
 
 
 ServerHooks&
 ServerHooks&
 ServerHooks::getServerHooks() {
 ServerHooks::getServerHooks() {
-    static ServerHooks hooks;
+    return (*getServerHooksPtr());
+}
+
+ServerHooksPtr
+ServerHooks::getServerHooksPtr() {
+    static ServerHooksPtr hooks(new ServerHooks());
     return (hooks);
     return (hooks);
 }
 }
 
 

+ 9 - 1
src/lib/hooks/server_hooks.h

@@ -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
 // 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
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -10,6 +10,7 @@
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
 
 
 #include <boost/noncopyable.hpp>
 #include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
 
 
 #include <map>
 #include <map>
 #include <string>
 #include <string>
@@ -37,6 +38,8 @@ public:
         isc::Exception(file, line, what) {}
         isc::Exception(file, line, what) {}
 };
 };
 
 
+class ServerHooks;
+typedef boost::shared_ptr<ServerHooks> ServerHooksPtr;
 
 
 /// @brief Server hook collection
 /// @brief Server hook collection
 ///
 ///
@@ -133,6 +136,11 @@ public:
     /// @return Reference to the global ServerHooks object.
     /// @return Reference to the global ServerHooks object.
     static ServerHooks& getServerHooks();
     static ServerHooks& getServerHooks();
 
 
+    /// @brief Returns pointer to ServerHooks object.
+    ///
+    /// @return Pointer to the global ServerHooks object.
+    static ServerHooksPtr getServerHooksPtr();
+
 private:
 private:
     /// @brief Constructor
     /// @brief Constructor
     ///
     ///