]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Tomek's changes + init + deinit fixes
authorFrancis Dupont <fdupont@isc.org>
Tue, 27 Mar 2018 17:22:45 +0000 (19:22 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 27 Mar 2018 17:22:45 +0000 (19:22 +0200)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/dhcpsrv/host_data_source_factory.cc
src/lib/dhcpsrv/host_data_source_factory.h
src/lib/dhcpsrv/hosts_messages.mes

index 6e46f87b1f4a03301f70c2fa98e3fd57f6766f8f..43c0758ddf1c9b9ea5a5714fb47c15d85a0f43be 100644 (file)
@@ -24,6 +24,7 @@
 #include <dhcpsrv/parsers/option_data_parser.h>
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <dhcpsrv/parsers/shared_networks_list_parser.h>
+#include <dhcpsrv/host_data_source_factory.h>
 #include <dhcpsrv/timer_mgr.h>
 #include <hooks/hooks_parser.h>
 #include <config/command_mgr.h>
@@ -297,6 +298,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
     // for option definitions. This is equivalent to committing empty container.
     LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
 
+    // Print the list of known backends.
+    HostDataSourceFactory::printRegistered();
+
     // Answer will hold the result.
     ConstElementPtr answer;
     // Rollback informs whether error occurred and original data
index 2bc5e4902226a2077876cb0e3c17c49b839afb24..531a6588a20198297333c156eafc369eccb33aa4 100644 (file)
@@ -32,6 +32,7 @@
 #include <dhcpsrv/parsers/option_data_parser.h>
 #include <dhcpsrv/parsers/simple_parser6.h>
 #include <dhcpsrv/parsers/shared_networks_list_parser.h>
+#include <dhcpsrv/host_data_source_factory.h>
 #include <hooks/hooks_parser.h>
 #include <log/logger_support.h>
 #include <util/encode/hex.h>
@@ -395,6 +396,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
     // for option definitions. This is equivalent to committing empty container.
     LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
 
+    // Print the list of known backends.
+    HostDataSourceFactory::printRegistered();
+
     // This is a way to convert ConstElementPtr to ElementPtr.
     // We need a config that can be edited, because we will insert
     // default values and will insert derived values as well.
index 9e023c76782ecc526b11045744cf7c6798e11fb1..ec5cac31fdedb357591b1ec7c09d6a874c64194a 100644 (file)
@@ -9,6 +9,7 @@
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/host_data_source_factory.h>
 #include <dhcpsrv/hosts_log.h>
+#include <log/logger_support.h>
 
 #ifdef HAVE_MYSQL
 #include <dhcpsrv/mysql_host_data_source.h>
@@ -81,7 +82,7 @@ HostDataSourceFactory::del(HostDataSourceList& sources,
         if ((*it)->getType() != db_type) {
             continue;
         }
-        LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
+        LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
             .arg(db_type);
         sources.erase(it);
         return (true);
@@ -91,33 +92,51 @@ HostDataSourceFactory::del(HostDataSourceList& sources,
 
 bool
 HostDataSourceFactory::registerFactory(const string& db_type,
-                                       const Factory& factory) {
+                                       const Factory& factory,
+                                       bool no_log) {
     if (map_.count(db_type)) {
         return (false);
     }
     map_.insert(pair<string, Factory>(db_type, factory));
-    // As registerFactory can be called before logging is established
-    // remove temporary this until a better solution is found.
-#if 0
-    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
-        .arg(db_type);
-#endif
+
+    // We are dealing here with static logger initialization fiasco.
+    // registerFactory may be called from constructors of static global
+    // objects for built in backends. The logging is not initialized yet,
+    // so the LOG_DEBUG would throw.
+    if (!no_log) {
+        LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
+            .arg(db_type);
+    }
     return (true);
 }
 
 bool
-HostDataSourceFactory::deregisterFactory(const string& db_type) {
+HostDataSourceFactory::deregisterFactory(const string& db_type, bool no_log) {
     auto index = map_.find(db_type);
     if (index != map_.end()) {
         map_.erase(index);
-        LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_DEREGISTER)
-            .arg(db_type);
+        if (!no_log) {
+            LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE,
+                      HOSTS_BACKEND_DEREGISTER)
+                .arg(db_type);
+        }
         return (true);
     } else {
         return (false);
     }
 }
 
+void
+HostDataSourceFactory::printRegistered() {
+    std::stringstream txt;
+
+    for (auto x : map_) {
+        txt << x.first << " ";
+    }
+
+    LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED).arg(txt.str());
+}
+
 }  // namespace dhcp
 }  // namespace isc
 
@@ -133,18 +152,18 @@ namespace {
 struct MySqlHostDataSourceInit {
     // Constructor registers
     MySqlHostDataSourceInit() {
-        HostDataSourceFactory::registerFactory("mysql", factory);
+        HostDataSourceFactory::registerFactory("mysql", factory, true);
     }
 
     // Destructor deregisters
     ~MySqlHostDataSourceInit() {
-        HostDataSourceFactory::deregisterFactory("mysql");
+        HostDataSourceFactory::deregisterFactory("mysql", true);
     }
 
     // Factory class method
     static HostDataSourcePtr
     factory(const DatabaseConnection::ParameterMap& parameters) {
-        LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_HOST_DB)
+        LOG_INFO(hosts_logger, DHCPSRV_MYSQL_HOST_DB)
             .arg(DatabaseConnection::redactedAccessString(parameters));
         return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
     }
@@ -158,18 +177,18 @@ MySqlHostDataSourceInit mysql_init_;
 struct PgSqlHostDataSourceInit {
     // Constructor registers
     PgSqlHostDataSourceInit() {
-        HostDataSourceFactory::registerFactory("postgresql", factory);
+        HostDataSourceFactory::registerFactory("postgresql", factory, true);
     }
 
     // Destructor deregisters
     ~PgSqlHostDataSourceInit() {
-        HostDataSourceFactory::deregisterFactory("postgresql");
+        HostDataSourceFactory::deregisterFactory("postgresql", true);
     }
 
     // Factory class method
     static HostDataSourcePtr
     factory(const DatabaseConnection::ParameterMap& parameters) {
-        LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_HOST_DB)
+        LOG_INFO(hosts_logger, DHCPSRV_PGSQL_HOST_DB)
             .arg(DatabaseConnection::redactedAccessString(parameters));
         return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
     }
@@ -183,12 +202,12 @@ PgSqlHostDataSourceInit pgsql_init_;
 struct CqlHostDataSourceInit {
     // Constructor registers
     CqlHostDataSourceInit() {
-        HostDataSourceFactory::registerFactory("cql", factory);
+        HostDataSourceFactory::registerFactory("cql", factory, true);
     }
 
     // Destructor deregisters
     ~CqlHostDataSourceInit() {
-        HostDataSourceFactory::deregisterFactory("cql");
+        HostDataSourceFactory::deregisterFactory("cql", true);
     }
 
     // Factory class method
@@ -205,4 +224,3 @@ CqlHostDataSourceInit cql_init_;
 #endif
 
 } // end of anonymous namespace
-
index 11c40dde023adfb3927326b6719cbc21ca3dc7e2..b28f291d0b794158ddb11ca6d1222a4ea85724bf 100644 (file)
@@ -14,6 +14,7 @@
 #include <boost/function.hpp>
 
 #include <string>
+#include <vector>
 #include <map>
 
 namespace isc {
@@ -83,22 +84,35 @@ public:
     /// @brief Register a host data source factory
     ///
     /// Associate the factory to a database type in the map.
+    /// The no_log is to avoid logging before the logger is initialized
+    /// as when called at global object initialization.
     ///
     /// @param db_type database type
     /// @param factory host data source factory
+    /// @param no_log do not log (default false)
     /// @return true if the factory was successfully added to the map, false
     /// if it already exists.
     static bool registerFactory(const std::string& db_type,
-                                const Factory& factory);
+                                const Factory& factory, bool no_log = false);
 
     /// @brief Deregister a host data source factory
     ///
     /// Disassociate the factory to a database type in the map.
+    /// The no_log is to avoid logging during global object deinitialization.
     ///
     /// @param db_type database type
+    /// @param no_log do not log (default false)
     /// @return true if the factory was successfully removed from the map,
     /// false if it was not found.
-    static bool deregisterFactory(const std::string& db_type);
+    static bool deregisterFactory(const std::string& db_type,
+                                  bool no_log = false);
+
+    /// @brief Prints out all registered backends.
+    ///
+    /// We need a dedicated method for this, because we sometimes can't log
+    /// the backend type when doing early initialization for backends
+    /// initialized statically.
+    static void printRegistered();
 
 private:
     /// @brief Factory map
index 54975efee1d1752bd542f00d3aee9823cfbad569..cf370ed31ab2bb808790ff6f8a438740c287acc2 100644 (file)
@@ -6,14 +6,18 @@
 
 $NAMESPACE isc::dhcp
 
-% HOSTS_BACKEND_DEREGISTER deregistered backend type: %1
+% HOSTS_BACKEND_DEREGISTER deregistered host backend type: %1
 This debug message is issued when a backend factory was deregistered.
 It is no longer possible to use host backend of this type.
 
-% HOSTS_BACKEND_REGISTER registered backend type: %1
+% HOSTS_BACKEND_REGISTER registered host backend type: %1
 This debug message is issued when a backend factory was successfully
 registered. It is now possible to use host backend of this type.
 
+% HOSTS_BACKENDS_REGISTERED the following host backend types are available: %1
+This informational message lists all possible host backends that could
+be used in hosts-database[s].
+
 % HOSTS_CFG_ADD_HOST add the host for reservations: %1
 This debug message is issued when new host (with reservations) is added to
 the server's configuration. The argument describes the host and its