Browse Source

[1522] added some logging messages for the socket requestor.

JINMEI Tatuya 13 years ago
parent
commit
199ebdc9c9

+ 25 - 0
src/lib/server_common/server_common_messages.mes

@@ -71,3 +71,28 @@ specification is outside the valid range of 0 to 65535.
 % SRVCOMM_SET_LISTEN setting addresses to listen to
 Debug message, noting that the server is about to start listening on a
 different set of IP addresses and ports than before.
+
+% SOCKETREQUESTOR_CREATED Socket requestor created
+Debug message.  A socket requesor (client of the socket creator) is created
+for the corresponding application.  Normally this should happen at most
+one time throughout the lifetime of the application.
+
+% SOCKETREQUESTOR_DESTROYED Socket requestor destoryed
+Debug message.  The socket requestor created at SOCKETREQUESTOR_CREATED
+has been destroyed.  This event is generally unexpected other than in
+test cases.
+
+% SOCKETREQUESTOR_GETSOCKET Received a %1 socket for [%2]:%3, FD=%4, token=%5, path=%6
+Debug message. The socket requestor for the corresponding application
+has requested a socket for a set of address, port and protocol (shown
+in the log message) and successfully got it from the creator.  The
+corresponding file descriptor and the associated "token" (an internal
+ID used between the creator and requestor) are shown in the log
+message.
+
+% SOCKETREQUESTOR_RELEASESOCKET Released a socket of token %1
+Debug message.  The socket requestor has released a socket passed by
+the creator.  The associated token of the socket is shown in the
+log message.  If the corresponding SOCKETREQUESTOR_GETSOCKET was logged
+more detailed information of the socket can be identified by matching
+the token.

+ 22 - 0
src/lib/server_common/socket_request.cc

@@ -14,6 +14,7 @@
 #include <config.h>
 
 #include "socket_request.h"
+#include <server_common/logger.h>
 
 #include <config/ccsession.h>
 #include <cc/data.h>
@@ -230,6 +231,20 @@ getSocketFd(const std::string& token, int sock_pass_fd) {
     return (passed_sock_fd);
 }
 
+namespace {
+inline const char*
+protocolString(SocketRequestor::Protocol protocol) {
+    switch (protocol) {
+    case SocketRequestor::TCP:
+        return ("TCP");
+    case SocketRequestor::UDP:
+        return ("UDP");
+    default:
+        return ("unknown protocol");
+    }
+}
+}
+
 // This implementation class for SocketRequestor uses
 // a ModuleCCSession for communication with the boss process,
 // and fd_share to read out the socket(s).
@@ -251,10 +266,12 @@ public:
             isc_throw(Unexpected, "Failed to filter SIGPIPE: " <<
                       strerror(errno));
         }
+        LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED);
     }
 
     ~SocketRequestorCCSession() {
         closeFdShareSockets();
+        LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_DESTROYED);
     }
 
     virtual SocketID requestSocket(Protocol protocol,
@@ -286,6 +303,9 @@ public:
 
         // and finally get the socket itself
         const int passed_sock_fd = getSocketFd(token, sock_pass_fd);
+        LOG_DEBUG(logger, DBGLVL_TRACE_DETAIL, SOCKETREQUESTOR_GETSOCKET).
+            arg(protocolString(protocol)).arg(address).arg(port).
+            arg(passed_sock_fd).arg(token).arg(path);
         return (SocketID(passed_sock_fd, token));
     }
 
@@ -295,6 +315,8 @@ public:
 
         // Send it to boss
         const int seq = session_.groupSendMsg(release_msg, "Boss");
+        LOG_DEBUG(logger, DBGLVL_TRACE_DETAIL, SOCKETREQUESTOR_RELEASESOCKET).
+            arg(token);
 
         // Get the answer from the boss.
         // Just do a blocking read, we can't really do much anyway