]> granicus.if.org Git - icinga2/commitdiff
Fix error messages in LivestatusListener::ServerThreadProc
authorGunnar Beutner <gunnar@beutner.name>
Fri, 9 Jan 2015 08:53:43 +0000 (09:53 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 9 Jan 2015 08:53:43 +0000 (09:53 +0100)
fixes #8176

lib/livestatus/livestatuslistener.cpp
lib/livestatus/livestatuslistener.hpp

index 3f43d63e99aa9327cda3ec97af42f1e816bca349..7d8252cd38031e81b1a43d8f44eccbb5b7993d46 100644 (file)
@@ -81,8 +81,8 @@ void LivestatusListener::Start(void)
 
                m_Listener = socket;
 
-               boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));
-               thread.detach();
+               m_Thread = boost::thread(boost::bind(&LivestatusListener::ServerThreadProc, this));
+
                Log(LogInformation, "LivestatusListener")
                    << "Created TCP socket listening on host '" << GetBindHost() << "' port '" << GetBindPort() << "'.";
        }
@@ -109,8 +109,8 @@ void LivestatusListener::Start(void)
 
                m_Listener = socket;
 
-               boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));
-               thread.detach();
+               m_Thread = boost::thread(boost::bind(&LivestatusListener::ServerThreadProc, this));
+
                Log(LogInformation, "LivestatusListener")
                    << "Created UNIX socket in '" << GetSocketPath() << "'.";
 #else
@@ -126,6 +126,9 @@ void LivestatusListener::Stop(void)
        DynamicObject::Stop();
 
        m_Listener->Close();
+
+       if (m_Thread.joinable())
+               m_Thread.join();
 }
 
 int LivestatusListener::GetClientsConnected(void)
@@ -142,19 +145,21 @@ int LivestatusListener::GetConnections(void)
        return l_Connections;
 }
 
-void LivestatusListener::ServerThreadProc(const Socket::Ptr& server)
+void LivestatusListener::ServerThreadProc(void)
 {
-       server->Listen();
+       m_Listener->Listen();
 
-       for (;;) {
-               try {
-                       Socket::Ptr client = server->Accept();
+       try {
+               for (;;) {
+                       Socket::Ptr client = m_Listener->Accept();
                        Log(LogNotice, "LivestatusListener", "Client connected");
                        Utility::QueueAsyncCallback(boost::bind(&LivestatusListener::ClientHandler, this, client), LowLatencyScheduler);
-               } catch (std::exception&) {
-                       Log(LogCritical, "ListenerListener", "Cannot accept new connection.");
                }
+       } catch (std::exception&) {
+               Log(LogCritical, "ListenerListener", "Cannot accept new connection.");
        }
+
+       m_Listener->Close();
 }
 
 void LivestatusListener::ClientHandler(const Socket::Ptr& client)
index 3585a8dd10fa868adca155f23413f176871a97a1..3b26a817b16a315369b074d7e9e11af6941a8ab3 100644 (file)
@@ -51,10 +51,11 @@ protected:
        virtual void Stop(void);
 
 private:
-       void ServerThreadProc(const Socket::Ptr& server);
+       void ServerThreadProc(void);
        void ClientHandler(const Socket::Ptr& client);
 
        Socket::Ptr m_Listener;
+       boost::thread m_Thread;
 };
 
 }