From 74bae58f2152745897a6ace316ba8394777105a9 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 18 Jun 2012 00:14:34 +0200 Subject: [PATCH] Bugfixes. --- base/timer.cpp | 4 +++- components/checker/checkercomponent.cpp | 15 ++++++++++----- components/checker/checkercomponent.h | 14 +++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/base/timer.cpp b/base/timer.cpp index 9159abe90..58e9da42c 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -151,5 +151,7 @@ void Timer::Stop(void) void Timer::Reschedule(time_t next) { m_Next = next; - RescheduleTimers(); + + if (next < NextCall) + NextCall = next; } diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index cbd09176c..e76989be2 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -64,10 +64,10 @@ void CheckerComponent::CheckTimerHandler(void) time_t now; time(&now); - if (m_Services.size() == 0) - return; - for (;;) { + if (m_Services.size() == 0) + break; + Service service = m_Services.top(); if (service.GetNextCheck() > now || service.HasPendingCheck()) @@ -83,7 +83,6 @@ void CheckerComponent::CheckTimerHandler(void) m_PendingTasks.push_back(task); service.SetNextCheck(now + service.GetCheckInterval()); - m_Services.push(service); } AdjustCheckTimer(); @@ -101,10 +100,13 @@ void CheckerComponent::ResultTimerHandler(void) continue; } - task->GetService().SetPendingCheck(false); + Service service = task->GetService(); + service.SetPendingCheck(false); CheckResult result = task->GetResult(); Application::Log(LogInformation, "checker", "Got result! Plugin output: " + result.Output); + + m_Services.push(service); } m_PendingTasks = unfinishedTasks; @@ -176,6 +178,9 @@ void CheckerComponent::RevokeServiceRequestHandler(const Endpoint::Ptr& sender, if (service.GetName() == name) continue; + if (service.HasPendingCheck()) // TODO: remember services that should be removed once their pending check is done + throw runtime_error("not yet implemented"); + services.push_back(service); } diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index da924d47c..e33402eb1 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -23,14 +23,11 @@ namespace icinga { -struct ServiceCheckPriorityLessComparer +struct ServiceNextCheckLessComparer { public: bool operator()(const Service& a, const Service& b) { - if (a.HasPendingCheck() && !b.HasPendingCheck()) - return true; - return a.GetNextCheck() > b.GetNextCheck(); } }; @@ -44,17 +41,20 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef priority_queue, ServiceCheckPriorityLessComparer> ServiceQueue; + typedef priority_queue, ServiceNextCheckLessComparer> ServiceQueue; virtual string GetName(void) const; virtual void Start(void); virtual void Stop(void); private: - ServiceQueue m_Services; - Timer::Ptr m_CheckTimer; VirtualEndpoint::Ptr m_CheckerEndpoint; + ServiceQueue m_Services; + set m_PendingServices; + + Timer::Ptr m_CheckTimer; + Timer::Ptr m_ResultTimer; vector m_PendingTasks;