Browse Source

[1595] Application name for the socket requestor

It is used when the share name is not explicitly set.
Michal 'vorner' Vaner 13 years ago
parent
commit
9bbda62a5e

+ 1 - 1
src/bin/auth/main.cc

@@ -154,7 +154,7 @@ main(int argc, char* argv[]) {
         cc_session = new Session(io_service.get_io_service());
         LOG_DEBUG(auth_logger, DBG_AUTH_START, AUTH_CONFIG_CHANNEL_CREATED);
         // Initialize the Socket Requestor
-        isc::server_common::initSocketRequestor(*cc_session);
+        isc::server_common::initSocketRequestor(*cc_session, "auth");
 
         // We delay starting listening to new commands/config just before we
         // go into the main loop to avoid confusion due to mixture of

+ 1 - 1
src/bin/resolver/main.cc

@@ -202,7 +202,7 @@ main(int argc, char* argv[]) {
         LOG_DEBUG(resolver_logger, RESOLVER_DBG_INIT, RESOLVER_SERVICE_CREATED);
 
         cc_session = new Session(io_service.get_io_service());
-        isc::server_common::initSocketRequestor(*cc_session);
+        isc::server_common::initSocketRequestor(*cc_session, "resolver");
 
         // We delay starting listening to new commands/config just before we
         // go into the main loop.   See auth/main.cc for the rationale.

+ 1 - 1
src/lib/server_common/server_common_messages.mes

@@ -16,7 +16,7 @@ $NAMESPACE isc::server_common
 
 # \brief Messages for the server_common library
 
-% SOCKETREQUESTOR_CREATED Socket requestor created
+% SOCKETREQUESTOR_CREATED Socket requestor created for application %1
 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.

+ 14 - 6
src/lib/server_common/socket_request.cc

@@ -264,8 +264,10 @@ getSocketFd(const std::string& token, int sock_pass_fd) {
 // be closed during the lifetime of this class
 class SocketRequestorCCSession : public SocketRequestor {
 public:
-    explicit SocketRequestorCCSession(cc::AbstractSession& session) :
-        session_(session)
+    explicit SocketRequestorCCSession(cc::AbstractSession& session,
+                                      const std::string& app_name) :
+        session_(session),
+        app_name_(app_name)
     {
         // We need to filter SIGPIPE to prevent it from happening in
         // getSocketFd() while writing to the UNIX domain socket after the
@@ -278,7 +280,8 @@ public:
             isc_throw(Unexpected, "Failed to filter SIGPIPE: " <<
                       strerror(errno));
         }
-        LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED);
+        LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED).
+            arg(app_name);
     }
 
     ~SocketRequestorCCSession() {
@@ -293,7 +296,9 @@ public:
     {
         const isc::data::ConstElementPtr request_msg =
             createRequestSocketMessage(protocol, address, port,
-                                       share_mode, share_name);
+                                       share_mode,
+                                       share_name.empty() ? app_name_ :
+                                       share_name);
 
         // Send it to boss
         const int seq = session_.group_sendmsg(request_msg, "Boss");
@@ -377,6 +382,7 @@ private:
     }
 
     cc::AbstractSession& session_;
+    const std::string app_name_;
     std::map<std::string, int> fd_share_sockets_;
 };
 
@@ -392,12 +398,14 @@ socketRequestor() {
 }
 
 void
-initSocketRequestor(cc::AbstractSession& session) {
+initSocketRequestor(cc::AbstractSession& session,
+                    const std::string& app_name)
+{
     if (requestor != NULL) {
         isc_throw(InvalidOperation,
                   "The socket requestor was already initialized");
     } else {
-        requestor = new SocketRequestorCCSession(session);
+        requestor = new SocketRequestorCCSession(session, app_name);
     }
 }
 

+ 7 - 3
src/lib/server_common/socket_request.h

@@ -163,7 +163,8 @@ public:
     /// \param share_mode how the socket can be shared with other requests.
     /// This must be one of the defined values of ShareMode.
     /// \param share_name the name of sharing group, relevant for SHARE_SAME
-    ///     (specified by us or someone else).
+    ///     (specified by us or someone else). If left empty (the default),
+    ///     the app_name parameter of initSocketRequestor is used.
     /// \return the socket, as a file descriptor and token representing it on
     ///     the socket creator side.
     ///
@@ -180,7 +181,7 @@ public:
     virtual SocketID requestSocket(Protocol protocol,
                                    const std::string& address,
                                    uint16_t port, ShareMode share_mode,
-                                   const std::string& share_name) = 0;
+                                   const std::string& share_name = "") = 0;
 
     /// \brief Tell the socket creator we no longer need the socket
     ///
@@ -215,8 +216,11 @@ SocketRequestor& socketRequestor();
 ///
 /// \param session the CC session that'll be used to talk to the
 ///                socket creator.
+/// \param app_name default share name if one is not provided with
+///                 requestSocket
 /// \throw InvalidOperation when it is called more than once
-void initSocketRequestor(cc::AbstractSession& session);
+void initSocketRequestor(cc::AbstractSession& session,
+                         const std::string& app_name);
 
 /// \brief Initialization for tests
 ///

+ 12 - 1
src/lib/server_common/tests/socket_requestor_test.cc

@@ -83,7 +83,7 @@ public:
                                     ElementPtr(new ListElement),
                                     ElementPtr(new ListElement))
     {
-        initSocketRequestor(session);
+        initSocketRequestor(session, "tests");
     }
 
     ~SocketRequestorTest() {
@@ -187,6 +187,17 @@ TEST_F(SocketRequestorTest, testSocketRequestMessages) {
                  CCSessionError);
     ASSERT_EQ(1, session.getMsgQueue()->size());
     ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
+
+    // A default share name equal to the app name passed on construction
+    clearMsgQueue();
+    expected_request = createExpectedRequest("::1", 2, "UDP",
+                                             "SAMEAPP", "tests");
+    ASSERT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP,
+                                   "::1", 2,
+                                   SocketRequestor::SHARE_SAME),
+                 CCSessionError);
+    ASSERT_EQ(1, session.getMsgQueue()->size());
+    ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
 }
 
 TEST_F(SocketRequestorTest, invalidParameterForSocketRequest) {