mirror of https://github.com/Icinga/icinga2.git
Fix crashes when restarting Icinga.
This commit is contained in:
parent
c570593b73
commit
fa845775a2
|
@ -565,10 +565,6 @@ void ClusterListener::NewClientHandler(const Socket::Ptr& client, TlsRole role)
|
|||
{
|
||||
ObjectLock olock(endpoint);
|
||||
|
||||
Stream::Ptr oldClient = endpoint->GetClient();
|
||||
if (oldClient)
|
||||
oldClient->Close();
|
||||
|
||||
endpoint->SetSyncing(true);
|
||||
endpoint->SetSeen(Utility::GetTime());
|
||||
endpoint->SetClient(tlsStream);
|
||||
|
|
|
@ -38,6 +38,11 @@ Endpoint::Endpoint(void)
|
|||
: m_Syncing(false)
|
||||
{ }
|
||||
|
||||
Endpoint::~Endpoint(void)
|
||||
{
|
||||
SetClient(Stream::Ptr());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this endpoint is connected.
|
||||
*
|
||||
|
@ -55,11 +60,17 @@ Stream::Ptr Endpoint::GetClient(void) const
|
|||
|
||||
void Endpoint::SetClient(const Stream::Ptr& client)
|
||||
{
|
||||
if (m_Client)
|
||||
m_Client->Close();
|
||||
|
||||
Log(LogInformation, "cluster", "Joining endpoint message thread.");
|
||||
|
||||
m_Thread.join();
|
||||
|
||||
m_Client = client;
|
||||
|
||||
if (client) {
|
||||
boost::thread thread(boost::bind(&Endpoint::MessageThreadProc, this, client));
|
||||
thread.detach();
|
||||
m_Thread = boost::thread(boost::bind(&Endpoint::MessageThreadProc, this, client));
|
||||
|
||||
OnConnected(GetSelf());
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
DECLARE_TYPENAME(Endpoint);
|
||||
|
||||
Endpoint(void);
|
||||
~Endpoint(void);
|
||||
|
||||
static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
|
||||
static boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> OnMessageReceived;
|
||||
|
@ -93,6 +94,8 @@ private:
|
|||
Dictionary::Ptr m_Features;
|
||||
bool m_Syncing;
|
||||
|
||||
boost::thread m_Thread;
|
||||
|
||||
void MessageThreadProc(const Stream::Ptr& stream);
|
||||
};
|
||||
|
||||
|
|
|
@ -376,5 +376,11 @@ int main(int argc, char **argv)
|
|||
sigaction(SIGHUP, &sa, NULL);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
return Application::GetInstance()->Run();
|
||||
int rc = Application::GetInstance()->Run();
|
||||
|
||||
#ifdef _DEBUG
|
||||
exit(rc);
|
||||
#else /* _DEBUG */
|
||||
_exit(rc); // Yay, our static destructors are pretty much beyond repair at this point.
|
||||
#endif /* _DEBUG */
|
||||
}
|
||||
|
|
|
@ -132,18 +132,6 @@ void Application::SetArgV(char **argv)
|
|||
m_ArgV = argv;
|
||||
}
|
||||
|
||||
void Application::ShutdownTimerHandler(void)
|
||||
{
|
||||
if (m_ShuttingDown || m_Restarting) {
|
||||
Log(LogInformation, "base", "Shutting down Icinga...");
|
||||
Application::GetInstance()->OnShutdown();
|
||||
|
||||
DynamicObject::StopObjects();
|
||||
GetTP().Stop();
|
||||
m_ShuttingDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes events for registered sockets and timers and calls whatever
|
||||
* handlers have been set up for these events.
|
||||
|
@ -154,17 +142,23 @@ void Application::RunEventLoop(void) const
|
|||
boost::thread t(&Application::TimeWatchThreadProc);
|
||||
t.detach();
|
||||
|
||||
/* Set up a timer that watches the m_Shutdown flag. */
|
||||
Timer::Ptr shutdownTimer = boost::make_shared<Timer>();
|
||||
shutdownTimer->OnTimerExpired.connect(boost::bind(&Application::ShutdownTimerHandler));
|
||||
shutdownTimer->SetInterval(0.5);
|
||||
shutdownTimer->Start();
|
||||
|
||||
Timer::Initialize();
|
||||
|
||||
while (!m_ShuttingDown && !m_Restarting)
|
||||
Utility::Sleep(0.5);
|
||||
|
||||
Log(LogInformation, "base", "Shutting down Icinga...");
|
||||
Application::GetInstance()->OnShutdown();
|
||||
|
||||
#ifdef _DEBUG
|
||||
DynamicObject::StopObjects();
|
||||
GetTP().Stop();
|
||||
m_ShuttingDown = false;
|
||||
|
||||
GetTP().Join();
|
||||
|
||||
Timer::Uninitialize();
|
||||
#endif /* _DEBUG */
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -127,7 +127,6 @@ private:
|
|||
|
||||
static void TimeWatchThreadProc(void);
|
||||
static void NewTxTimerHandler(void);
|
||||
static void ShutdownTimerHandler(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue