Browse Source

[1986] Cleanups; use scoped_ptr, and more log msgs

- use scoped_ptr instead of raw pointer and 'manual' cleanup
- log errors in b10-ddns if there is an error response from b10-auth
- minor other cleanups
Jelte Jansen 13 years ago
parent
commit
96f4382db5

+ 2 - 2
src/bin/auth/auth.spec.pre.in

@@ -134,12 +134,12 @@
       },
       },
       {
       {
         "command_name": "start_ddns_forwarder",
         "command_name": "start_ddns_forwarder",
-        "command_description": "(Re)start internal forwarding of DDNS Update packets.",
+        "command_description": "(Re)start internal forwarding of DDNS Update packets. This is automatically called if b10-ddns is started.",
         "command_args": []
         "command_args": []
       },
       },
       {
       {
         "command_name": "stop_ddns_forwarder",
         "command_name": "stop_ddns_forwarder",
-        "command_description": "Stop internal forwarding of DDNS Update packets",
+        "command_description": "Stop internal forwarding of DDNS Update packets. This is automatically called if b10-ddns is stopped.",
         "command_args": []
         "command_args": []
       }
       }
     ],
     ],

+ 3 - 3
src/bin/auth/auth_messages.mes

@@ -110,9 +110,6 @@ look into the cause and address the issue.  The log message includes
 the client's address (and port), and the error message sent from the
 the client's address (and port), and the error message sent from the
 lower layer that detects the failure.
 lower layer that detects the failure.
 
 
-% AUTH_RECEIVED_NOTIFY received incoming NOTIFY for zone name %1, zone class %2
-This is a debug message reporting that an incoming NOTIFY was received.
-
 % AUTH_NOTIFY_QUESTIONS invalid number of questions (%1) in incoming NOTIFY
 % AUTH_NOTIFY_QUESTIONS invalid number of questions (%1) in incoming NOTIFY
 This debug message is logged by the authoritative server when it receives
 This debug message is logged by the authoritative server when it receives
 a NOTIFY packet that contains zero or more than one question. (A valid
 a NOTIFY packet that contains zero or more than one question. (A valid
@@ -169,6 +166,9 @@ bug ticket for this issue.
 This is a debug message issued when the authoritative server has received
 This is a debug message issued when the authoritative server has received
 a command on the command channel.
 a command on the command channel.
 
 
+% AUTH_RECEIVED_NOTIFY received incoming NOTIFY for zone name %1, zone class %2
+This is a debug message reporting that an incoming NOTIFY was received.
+
 % AUTH_RECEIVED_SENDSTATS command 'sendstats' received
 % AUTH_RECEIVED_SENDSTATS command 'sendstats' received
 This is a debug message issued when the authoritative server has received
 This is a debug message issued when the authoritative server has received
 a command from the statistics module to send it data. The 'sendstats'
 a command from the statistics module to send it data. The 'sendstats'

+ 7 - 14
src/bin/auth/auth_srv.cc

@@ -58,6 +58,7 @@
 
 
 #include <boost/bind.hpp>
 #include <boost/bind.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/scoped_ptr.hpp>
 
 
 #include <algorithm>
 #include <algorithm>
 #include <cassert>
 #include <cassert>
@@ -303,7 +304,7 @@ private:
 
 
     // Socket session forwarder for dynamic update requests
     // Socket session forwarder for dynamic update requests
     BaseSocketSessionForwarder& ddns_base_forwarder_;
     BaseSocketSessionForwarder& ddns_base_forwarder_;
-    SocketSessionForwarderHolder* ddns_forwarder_;
+    boost::scoped_ptr<SocketSessionForwarderHolder> ddns_forwarder_;
 
 
     /// Increment query counter
     /// Increment query counter
     void incCounter(const int protocol);
     void incCounter(const int protocol);
@@ -337,9 +338,6 @@ AuthSrvImpl::AuthSrvImpl(const bool use_cache,
 
 
     // enable or disable the cache
     // enable or disable the cache
     cache_.setEnabled(use_cache);
     cache_.setEnabled(use_cache);
-
-    // TODO: REMOVE and create 'on demand'
-    //createDDNSForwarder();
 }
 }
 
 
 AuthSrvImpl::~AuthSrvImpl() {
 AuthSrvImpl::~AuthSrvImpl() {
@@ -347,7 +345,6 @@ AuthSrvImpl::~AuthSrvImpl() {
         xfrout_client_.disconnect();
         xfrout_client_.disconnect();
         xfrout_connected_ = false;
         xfrout_connected_ = false;
     }
     }
-    destroyDDNSForwarder();
 }
 }
 
 
 // This is a derived class of \c DNSLookup, to serve as a
 // This is a derived class of \c DNSLookup, to serve as a
@@ -892,25 +889,21 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
 
 
 bool
 bool
 AuthSrvImpl::hasDDNSForwarder() {
 AuthSrvImpl::hasDDNSForwarder() {
-    return (ddns_forwarder_ != NULL);
+    return (ddns_forwarder_);
 }
 }
 
 
 void
 void
 AuthSrvImpl::createDDNSForwarder() {
 AuthSrvImpl::createDDNSForwarder() {
-    if (hasDDNSForwarder()) {
-        destroyDDNSForwarder();
-    }
     LOG_DEBUG(auth_logger, DBG_AUTH_OPS, AUTH_START_DDNS_FORWARDER);
     LOG_DEBUG(auth_logger, DBG_AUTH_OPS, AUTH_START_DDNS_FORWARDER);
-    ddns_forwarder_ = new SocketSessionForwarderHolder("update",
+    ddns_forwarder_.reset(
-                                                       ddns_base_forwarder_);
+        new SocketSessionForwarderHolder("update", ddns_base_forwarder_));
 }
 }
 
 
 void
 void
 AuthSrvImpl::destroyDDNSForwarder() {
 AuthSrvImpl::destroyDDNSForwarder() {
-    if (ddns_forwarder_ != NULL) {
+    if (ddns_forwarder_) {
         LOG_DEBUG(auth_logger, DBG_AUTH_OPS, AUTH_STOP_DDNS_FORWARDER);
         LOG_DEBUG(auth_logger, DBG_AUTH_OPS, AUTH_STOP_DDNS_FORWARDER);
-        delete ddns_forwarder_;
+        ddns_forwarder_.reset();
-        ddns_forwarder_ = NULL;
     }
     }
 }
 }
 
 

+ 2 - 2
src/bin/ddns/ddns.py.in

@@ -548,7 +548,7 @@ class DDNSServer:
         answer, _ = self._cc._session.group_recvmsg(False, seq)
         answer, _ = self._cc._session.group_recvmsg(False, seq)
         rcode, error_msg = parse_answer(answer)
         rcode, error_msg = parse_answer(answer)
         if (rcode != 0):
         if (rcode != 0):
-            raise Exception(error_msg)
+            logger.error(DDNS_START_FORWARDER_ERROR, error_msg)
 
 
     def __notify_stop_forwarder(self):
     def __notify_stop_forwarder(self):
         '''Notify auth that DDNS Update packets can now be forwarded'''
         '''Notify auth that DDNS Update packets can now be forwarded'''
@@ -557,7 +557,7 @@ class DDNSServer:
         answer, _ = self._cc._session.group_recvmsg(False, seq)
         answer, _ = self._cc._session.group_recvmsg(False, seq)
         rcode, error_msg = parse_answer(answer)
         rcode, error_msg = parse_answer(answer)
         if (rcode != 0):
         if (rcode != 0):
-            raise Exception(error_msg)
+            logger.error(DDNS_STOP_FORWARDER_ERROR, error_msg)
 
 
     def __notify_auth(self, zname, zclass):
     def __notify_auth(self, zname, zclass):
         '''Notify auth of the update, if necessary.'''
         '''Notify auth of the update, if necessary.'''

+ 12 - 0
src/bin/ddns/ddns_messages.mes

@@ -192,6 +192,12 @@ be completed, after which the process will exit.
 The ddns process has successfully started and is now ready to receive commands
 The ddns process has successfully started and is now ready to receive commands
 and updates.
 and updates.
 
 
+% DDNS_START_FOWARDER_ERROR Error from b10-auth when requesting DDNS UPDATE forwarding: %1
+There was an error response from b10-auth to the command to start
+forwarding DDNS UPDATE messages to b10-ddns.
+The error message is printed, and additional information may be found in
+the b10-auth log output.
+
 % DDNS_STOPPED ddns server has stopped
 % DDNS_STOPPED ddns server has stopped
 The ddns process has successfully stopped and is no longer listening for or
 The ddns process has successfully stopped and is no longer listening for or
 handling commands or updates, and will now exit.
 handling commands or updates, and will now exit.
@@ -200,6 +206,12 @@ handling commands or updates, and will now exit.
 There was a keyboard interrupt signal to stop the ddns process. The
 There was a keyboard interrupt signal to stop the ddns process. The
 process will now shut down.
 process will now shut down.
 
 
+% DDNS_STOP_FOWARDER_ERROR Error from b10-auth when requesting to stop DDNS UPDATE forwarding: %1
+There was an error response from b10-auth to the command to stop
+forwarding DDNS UPDATE messages to b10-ddns.
+The error message is printed, and additional information may be found in
+the b10-auth log output.
+
 % DDNS_UNCAUGHT_EXCEPTION uncaught exception of type %1: %2
 % DDNS_UNCAUGHT_EXCEPTION uncaught exception of type %1: %2
 The b10-ddns process encountered an uncaught exception and will now shut
 The b10-ddns process encountered an uncaught exception and will now shut
 down. This is indicative of a programming error and should not happen under
 down. This is indicative of a programming error and should not happen under