BIND 10 trac3186, updated. a27c2a6a18ec14e5c79eae56beb238044ecb87d2 [3186] Adding logging to user_chk hook libraryU

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Oct 16 14:56:35 UTC 2013


The branch, trac3186 has been updated
       via  a27c2a6a18ec14e5c79eae56beb238044ecb87d2 (commit)
      from  bd647c2a9820ecd3fc62852c42797265eca26ab1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a27c2a6a18ec14e5c79eae56beb238044ecb87d2
Author: Thomas Markwalder <tmark at isc.org>
Date:   Wed Oct 16 10:54:54 2013 -0400

    [3186] Adding logging to user_chk hook libraryU
    
    Replaced couts with isc::log mechanisms in user_chk DHCP hook library.

-----------------------------------------------------------------------

Summary of changes:
 src/hooks/dhcp/user_chk/Makefile.am                |   18 ++++-----
 src/hooks/dhcp/user_chk/load_unload.cc             |   27 ++++++++-----
 src/hooks/dhcp/user_chk/subnet_select_co.cc        |   13 +++---
 src/hooks/dhcp/user_chk/tests/Makefile.am          |    3 ++
 .../dhcp/user_chk/user_chk_log.cc}                 |    4 +-
 .../dhcp/user_chk/user_chk_log.h}                  |   25 +++++-------
 src/hooks/dhcp/user_chk/user_chk_messages.mes      |   42 ++++++++++++++++++++
 src/hooks/dhcp/user_chk/user_file.cc               |    5 ++-
 8 files changed, 95 insertions(+), 42 deletions(-)
 copy src/{bin/resolver/resolver_log.cc => hooks/dhcp/user_chk/user_chk_log.cc} (91%)
 copy src/{bin/d2/d2_log.h => hooks/dhcp/user_chk/user_chk_log.h} (68%)
 create mode 100644 src/hooks/dhcp/user_chk/user_chk_messages.mes

-----------------------------------------------------------------------
diff --git a/src/hooks/dhcp/user_chk/Makefile.am b/src/hooks/dhcp/user_chk/Makefile.am
index 2dbcff9..623008b 100644
--- a/src/hooks/dhcp/user_chk/Makefile.am
+++ b/src/hooks/dhcp/user_chk/Makefile.am
@@ -11,36 +11,34 @@ AM_CXXFLAGS  = $(B10_CXXFLAGS)
 AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
 
 # Define rule to build logging source files from message file
-# hooks_messages.h hooks_messages.cc: s-messages
+user_chk_messages.h user_chk_messages.cc: s-messages
 
-# s-messages: hooks_messages.mes
-# 	$(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/lib/hooks/hooks_messages.mes
-# 	touch $@
+s-messages: user_chk_messages.mes
+	$(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/hooks/dhcp/user_chk/user_chk_messages.mes
+	touch $@
 
 # Tell automake that the message files are built as part of the build process
 # (so that they are built before the main library is built).
-# BUILT_SOURCES = hooks_messages.h hooks_messages.cc
-BUILT_SOURCES =
+BUILT_SOURCES = user_chk_messages.h user_chk_messages.cc
 
 # Ensure that the message file is included in the distribution
 EXTRA_DIST =
 
 # Get rid of generated message files on a clean
-# CLEANFILES = *.gcno *.gcda hooks_messages.h hooks_messages.cc s-messages
-CLEANFILES = *.gcno *.gcda
+CLEANFILES = *.gcno *.gcda user_chk_messages.h user_chk_messages.cc s-messages
 
 lib_LTLIBRARIES = libdhcp_user_chk.la
 libdhcp_user_chk_la_SOURCES  =
 libdhcp_user_chk_la_SOURCES += load_unload.cc
 libdhcp_user_chk_la_SOURCES += subnet_select_co.cc
 libdhcp_user_chk_la_SOURCES += user.cc user.h
+libdhcp_user_chk_la_SOURCES += user_chk_log.cc user_chk_log.h
 libdhcp_user_chk_la_SOURCES += user_data_source.cc user_data_source.h
 libdhcp_user_chk_la_SOURCES += user_file.cc user_file.h
 libdhcp_user_chk_la_SOURCES += user_registry.cc user_registry.h
 libdhcp_user_chk_la_SOURCES += version.cc
 
-#nodist_libdhcp_user_chk_la_SOURCES = hooks_messages.cc hooks_messages.h
-nodist_libdhcp_user_chk_la_SOURCES =
+nodist_libdhcp_user_chk_la_SOURCES = user_chk_messages.cc user_chk_messages.h
 
 libdhcp_user_chk_la_CXXFLAGS = $(AM_CXXFLAGS)
 libdhcp_user_chk_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
diff --git a/src/hooks/dhcp/user_chk/load_unload.cc b/src/hooks/dhcp/user_chk/load_unload.cc
index a480554..14ee1ee 100644
--- a/src/hooks/dhcp/user_chk/load_unload.cc
+++ b/src/hooks/dhcp/user_chk/load_unload.cc
@@ -14,11 +14,13 @@
 // load_unload.cc
 
 #include <hooks/hooks.h>
+#include <user_chk_log.h>
 #include <user_registry.h>
 #include <user_file.h>
 
 #include <iostream>
 #include <fstream>
+#include <errno.h>
 
 using namespace isc::hooks;
 
@@ -31,6 +33,8 @@ extern "C" {
 
 int load(LibraryHandle&) {
 
+    isc::log::MessageInitializer::loadDictionary();
+
     // non-zero indicates an error.
     int ret_val = 0;
     try {
@@ -49,16 +53,15 @@ int load(LibraryHandle&) {
         // Open up the output file for user_chk results.
         user_chk_output.open(user_chk_output_fname,
                      std::fstream::out | std::fstream::app);
-
+        int sav_errno = errno;
         if (!user_chk_output) {
-            std::cout << "UserCheckHook: cannot open user check output file: "
-                      << user_chk_output_fname << std::endl;
-            ret_val = 1;
+            isc_throw(isc::Unexpected, "Cannot open output file: "
+                                       << user_chk_output_fname
+                                       << " reason: " << strerror(sav_errno));
         }
     }
     catch (const std::exception& ex) {
-        std::cout << "UserCheckHook: loading user_chk hook lib failed:"
-                  << ex.what() << std::endl;
+        LOG_ERROR(user_chk_logger, USER_CHK_HOOK_LOAD_ERROR).arg(ex.what());
         ret_val = 1;
     }
 
@@ -66,9 +69,15 @@ int load(LibraryHandle&) {
 }
 
 int unload() {
-    user_registry.reset();
-    if (user_chk_output.is_open()) {
-        user_chk_output.close();
+    try {
+        user_registry.reset();
+        if (user_chk_output.is_open()) {
+            user_chk_output.close();
+        }
+    } catch (const std::exception& ex) {
+        // On the off chance something goes awry, catch it and log it.
+        // @todo Not sure if we should return a non-zero result or not.
+        LOG_ERROR(user_chk_logger, USER_CHK_HOOK_UNLOAD_ERROR).arg(ex.what());
     }
 
     return (0);
diff --git a/src/hooks/dhcp/user_chk/subnet_select_co.cc b/src/hooks/dhcp/user_chk/subnet_select_co.cc
index 1daecd0..d0bdc69 100644
--- a/src/hooks/dhcp/user_chk/subnet_select_co.cc
+++ b/src/hooks/dhcp/user_chk/subnet_select_co.cc
@@ -4,6 +4,7 @@
 #include <dhcp/pkt6.h>
 #include <dhcpsrv/subnet.h>
 #include <user_registry.h>
+#include <user_chk_log.h>
 
 #include <fstream>
 #include <string>
@@ -38,7 +39,7 @@ void generate_output_record(const std::string& id_type_str,
 // This callout is called at the "subnet4_select" hook.
 int subnet4_select(CalloutHandle& handle) {
     if (!user_registry) {
-        std::cout << "UserCheckHook: UserRegistry is null!" << std::endl;
+        LOG_ERROR(user_chk_logger, USER_CHK_SUBNET4_SELECT_REGISTRY_NULL);
         return (1);
     }
 
@@ -72,9 +73,8 @@ int subnet4_select(CalloutHandle& handle) {
                                    false);
         }
     } catch (const std::exception& ex) {
-        std::cout << "UserCheckHook: Exception in subnet4_select callout:"
-                  << ex.what() << std::endl;
-
+        LOG_ERROR(user_chk_logger, USER_CHK_SUBNET4_SELECT_ERROR)
+                 .arg(ex.what());
         return (1);
     }
 
@@ -83,7 +83,7 @@ int subnet4_select(CalloutHandle& handle) {
 // This callout is called at the "subnet6_select" hook.
 int subnet6_select(CalloutHandle& handle) {
     if (!user_registry) {
-        std::cout << "UserCheckHook: UserRegistry is null!" << std::endl;
+        LOG_ERROR(user_chk_logger, USER_CHK_SUBNET4_SELECT_REGISTRY_NULL);
         return (1);
     }
 
@@ -125,7 +125,8 @@ int subnet6_select(CalloutHandle& handle) {
                                    false);
         }
     } catch (const std::exception& ex) {
-        std::cout << "UserCheckHook: Exception in subnet6_select callout:"                        << ex.what() << std::endl;
+        LOG_ERROR(user_chk_logger, USER_CHK_SUBNET6_SELECT_ERROR)
+                                   .arg(ex.what());
         return (1);
     }
 
diff --git a/src/hooks/dhcp/user_chk/tests/Makefile.am b/src/hooks/dhcp/user_chk/tests/Makefile.am
index 32d257d..97bac5d 100644
--- a/src/hooks/dhcp/user_chk/tests/Makefile.am
+++ b/src/hooks/dhcp/user_chk/tests/Makefile.am
@@ -34,6 +34,8 @@ libdhcp_user_chk_unittests_SOURCES += ../load_unload.cc
 libdhcp_user_chk_unittests_SOURCES += ../subnet_select_co.cc
 libdhcp_user_chk_unittests_SOURCES += ../version.cc
 libdhcp_user_chk_unittests_SOURCES += ../user.cc ../user.h
+libdhcp_user_chk_unittests_SOURCES += ../user_chk_log.cc ../user_chk_log.h
+libdhcp_user_chk_unittests_SOURCES += ../user_chk_messages.cc ../user_chk_messages.h
 libdhcp_user_chk_unittests_SOURCES += ../user_data_source.cc ../user_data_source.h
 libdhcp_user_chk_unittests_SOURCES += ../user_file.cc ../user_file.h
 libdhcp_user_chk_unittests_SOURCES += ../user_registry.cc ../user_registry.h
@@ -57,6 +59,7 @@ endif
 
 libdhcp_user_chk_unittests_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
 libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
+libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/hooks/libb10-hooks.la
 libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libb10-dhcp++.la
 libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
 libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/cc/libb10-cc.la
diff --git a/src/hooks/dhcp/user_chk/user_chk_log.cc b/src/hooks/dhcp/user_chk/user_chk_log.cc
new file mode 100644
index 0000000..3be5252
--- /dev/null
+++ b/src/hooks/dhcp/user_chk/user_chk_log.cc
@@ -0,0 +1,19 @@
+// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+/// Defines the logger used by the NSAS
+
+#include <user_chk_log.h>
+
+isc::log::Logger user_chk_logger("user_chk");
diff --git a/src/hooks/dhcp/user_chk/user_chk_log.h b/src/hooks/dhcp/user_chk/user_chk_log.h
new file mode 100644
index 0000000..43fb364
--- /dev/null
+++ b/src/hooks/dhcp/user_chk/user_chk_log.h
@@ -0,0 +1,29 @@
+// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef USER_CHK_LOG_H
+#define USER_CHK_LOG_H
+
+#include <log/message_initializer.h>
+#include <log/macros.h>
+#include <user_chk_messages.h>
+
+/// @brief User Check Logger
+///
+/// Define the logger used to log messages.  We could define it in multiple
+/// modules, but defining in a single module and linking to it saves time and
+/// space.
+extern isc::log::Logger user_chk_logger;
+
+#endif // USER_CHK_LOG_H
diff --git a/src/hooks/dhcp/user_chk/user_chk_messages.mes b/src/hooks/dhcp/user_chk/user_chk_messages.mes
new file mode 100644
index 0000000..6becd8c
--- /dev/null
+++ b/src/hooks/dhcp/user_chk/user_chk_messages.mes
@@ -0,0 +1,42 @@
+# Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+% USER_CHK_HOOK_LOAD_ERROR DHCP UserCheckHook could not be loaded: %1
+This is an error message issued when the DHCP UserCheckHook could not be loaded.
+The exact cause should be explained in the log message.  User subnet selection will revert to default processing.
+
+% USER_CHK_HOOK_UNLOAD_ERROR DHCP UserCheckHook an error occurred unloading the library: %1
+This is an error message issued when an error occurs while unloading the
+UserCheckHook library.  This is unlikely to occur and normal operations of the
+library will likely resume when it is next loaded.
+
+% USER_CHK_SUBNET4_SELECT_ERROR DHCP UserCheckHook an unexpected error occured in subnet4_select callout: %1
+This is an error message issued when the DHCP UserCheckHook subnet4_select hook
+encounters an unexpected error.  The message should contain a more detailed
+explanation.
+
+% USER_CHK_SUBNET4_SELECT_REGISTRY_NULL DHCP UserCheckHook UserRegistry has not been created.
+This is an error message issued when the DHCP UserCheckHook subnet4_select hook
+has been invoked but the UserRegistry has not been created.  This is a
+programmatic error and should not occur.
+
+% USER_CHK_SUBNET6_SELECT_ERROR DHCP UserCheckHook an unexpected error occured in subnet6_select callout: %1
+This is an error message issued when the DHCP UserCheckHook subnet6_select hook
+encounters an unexpected error.  The message should contain a more detailed
+explanation.
+
+% USER_CHK_SUBNET6_SELECT_REGISTRY_NULL DHCP UserCheckHook UserRegistry has not been created.
+This is an error message issued when the DHCP UserCheckHook subnet6_select hook
+has been invoked but the UserRegistry has not been created.  This is a
+programmatic error and should not occur.
diff --git a/src/hooks/dhcp/user_chk/user_file.cc b/src/hooks/dhcp/user_chk/user_file.cc
index 4bd5265..384cb52 100644
--- a/src/hooks/dhcp/user_chk/user_file.cc
+++ b/src/hooks/dhcp/user_chk/user_file.cc
@@ -17,6 +17,7 @@
 #include <user_file.h>
 
 #include <boost/foreach.hpp>
+#include <errno.h>
 
 UserFile::UserFile(const std::string& fname) : fname_(fname) {
     if (fname_.empty()) {
@@ -35,8 +36,10 @@ UserFile::open() {
     }
 
     ifs_.open(fname_.c_str(), std::ifstream::in);
+    int sav_error = errno;
     if (!ifs_.is_open()) {
-        isc_throw(UserFileError, "cannot open file:" << fname_);
+        isc_throw(UserFileError, "cannot open file:" << fname_
+                                 << " reason: " << strerror(sav_error));
     }
 
     setOpenFlag(true);



More information about the bind10-changes mailing list