Deactivate Livestatus listener before writing the state file

fixes #7660
This commit is contained in:
Gunnar Beutner 2015-01-08 14:03:43 +01:00
parent 79b0c13dfb
commit 493620a0ac
2 changed files with 16 additions and 0 deletions

View File

@ -70,6 +70,7 @@ void LivestatusListener::Start(void)
if (GetSocketType() == "tcp") { if (GetSocketType() == "tcp") {
TcpSocket::Ptr socket = new TcpSocket(); TcpSocket::Ptr socket = new TcpSocket();
try { try {
socket->Bind(GetBindHost(), GetBindPort(), AF_UNSPEC); socket->Bind(GetBindHost(), GetBindPort(), AF_UNSPEC);
} catch (std::exception&) { } catch (std::exception&) {
@ -78,6 +79,8 @@ void LivestatusListener::Start(void)
return; return;
} }
m_Listener = socket;
boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket)); boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));
thread.detach(); thread.detach();
Log(LogInformation, "LivestatusListener") Log(LogInformation, "LivestatusListener")
@ -86,6 +89,7 @@ void LivestatusListener::Start(void)
else if (GetSocketType() == "unix") { else if (GetSocketType() == "unix") {
#ifndef _WIN32 #ifndef _WIN32
UnixSocket::Ptr socket = new UnixSocket(); UnixSocket::Ptr socket = new UnixSocket();
try { try {
socket->Bind(GetSocketPath()); socket->Bind(GetSocketPath());
} catch (std::exception&) { } catch (std::exception&) {
@ -103,6 +107,8 @@ void LivestatusListener::Start(void)
return; return;
} }
m_Listener = socket;
boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket)); boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));
thread.detach(); thread.detach();
Log(LogInformation, "LivestatusListener") Log(LogInformation, "LivestatusListener")
@ -115,6 +121,13 @@ void LivestatusListener::Start(void)
} }
} }
void LivestatusListener::Stop(void)
{
DynamicObject::Stop();
m_Listener->Close();
}
int LivestatusListener::GetClientsConnected(void) int LivestatusListener::GetClientsConnected(void)
{ {
boost::mutex::scoped_lock lock(l_ComponentMutex); boost::mutex::scoped_lock lock(l_ComponentMutex);

View File

@ -48,10 +48,13 @@ public:
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void Stop(void);
private: private:
void ServerThreadProc(const Socket::Ptr& server); void ServerThreadProc(const Socket::Ptr& server);
void ClientHandler(const Socket::Ptr& client); void ClientHandler(const Socket::Ptr& client);
Socket::Ptr m_Listener;
}; };
} }