From 8033586f66ce7d898e03f3a23ca38fc09be149d5 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 10 Jul 2013 14:19:01 +0200 Subject: [PATCH] livestatus: close socket on component Stop() refs #4376 --- components/livestatus/component.cpp | 16 ++++++++++++++-- components/livestatus/component.h | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/livestatus/component.cpp b/components/livestatus/component.cpp index bc10ca534..a43d2d2f1 100644 --- a/components/livestatus/component.cpp +++ b/components/livestatus/component.cpp @@ -51,8 +51,20 @@ void LivestatusComponent::Start(void) m_Listener = socket; - boost::thread thread(boost::bind(&LivestatusComponent::ServerThreadProc, this, socket)); - thread.detach(); + m_Thread = boost::thread(boost::bind(&LivestatusComponent::ServerThreadProc, this, socket)); + m_Thread.detach(); +} + +/** + * Stops the component. + */ +void LivestatusComponent::Stop(void) +{ + m_Listener->Close(); + + Log(LogInformation, "livestatus", "Socket closed."); + + m_Thread.join(); } String LivestatusComponent::GetSocketPath(void) const diff --git a/components/livestatus/component.h b/components/livestatus/component.h index e197f656a..e118aad15 100644 --- a/components/livestatus/component.h +++ b/components/livestatus/component.h @@ -23,6 +23,7 @@ #include "livestatus/query.h" #include "base/dynamicobject.h" #include "base/socket.h" +#include using namespace icinga; @@ -38,10 +39,13 @@ public: LivestatusComponent(const Dictionary::Ptr& serializedUpdate); virtual void Start(void); + virtual void Stop(void); String GetSocketPath(void) const; private: + boost::thread m_Thread; + Attribute m_SocketPath; Socket::Ptr m_Listener; -- 2.40.0