From: Marcin Siodelski Date: Fri, 24 Feb 2017 15:42:11 +0000 (+0100) Subject: [5134] Proposed patch to prevent static initialization fiasco. X-Git-Tag: trac5137_base~3^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=97ac3e79bfc47592321bca93ec15cd96c63b3ccf;p=thirdparty%2Fkea.git [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. --- diff --git a/src/lib/hooks/library_manager.cc b/src/lib/hooks/library_manager.cc index dfc25fa9af..ab10837da9 100644 --- a/src/lib/hooks/library_manager.cc +++ b/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 // 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& 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 " diff --git a/src/lib/hooks/library_manager.h b/src/lib/hooks/library_manager.h index 03f3ddfd7a..5f6bc4cac7 100644 --- a/src/lib/hooks/library_manager.h +++ b/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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -8,7 +8,7 @@ #define LIBRARY_MANAGER_H #include - +#include #include #include @@ -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 diff --git a/src/lib/hooks/server_hooks.cc b/src/lib/hooks/server_hooks.cc index ebd416998b..504446cb40 100644 --- a/src/lib/hooks/server_hooks.cc +++ b/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 // 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); } diff --git a/src/lib/hooks/server_hooks.h b/src/lib/hooks/server_hooks.h index 246cb83e61..3c052ad8f6 100644 --- a/src/lib/hooks/server_hooks.h +++ b/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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -37,6 +38,8 @@ public: isc::Exception(file, line, what) {} }; +class ServerHooks; +typedef boost::shared_ptr 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 ///