mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 05:34:48 +02:00
Use Defer
class for cleanup in ApiListener::ReplayLog()
This commit is contained in:
parent
f074e24d2a
commit
73db30c08b
@ -1437,10 +1437,12 @@ void ApiListener::LogGlobHandler(std::vector<int>& files, const String& file)
|
|||||||
void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
|
void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
|
||||||
{
|
{
|
||||||
Endpoint::Ptr endpoint = client->GetEndpoint();
|
Endpoint::Ptr endpoint = client->GetEndpoint();
|
||||||
|
Defer resetEndpointSyncing ([&endpoint]() {
|
||||||
|
ObjectLock olock(endpoint);
|
||||||
|
endpoint->SetSyncing(false);
|
||||||
|
});
|
||||||
|
|
||||||
if (endpoint->GetLogDuration() == 0) {
|
if (endpoint->GetLogDuration() == 0) {
|
||||||
ObjectLock olock2(endpoint);
|
|
||||||
endpoint->SetSyncing(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1457,14 +1459,10 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
|
|||||||
Zone::Ptr target_zone = target_endpoint->GetZone();
|
Zone::Ptr target_zone = target_endpoint->GetZone();
|
||||||
|
|
||||||
if (!target_zone) {
|
if (!target_zone) {
|
||||||
ObjectLock olock2(endpoint);
|
|
||||||
endpoint->SetSyncing(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool stopReplay = false;
|
for (;;) {
|
||||||
|
|
||||||
do {
|
|
||||||
std::unique_lock<std::mutex> lock(m_LogLock);
|
std::unique_lock<std::mutex> lock(m_LogLock);
|
||||||
|
|
||||||
CloseLogFile();
|
CloseLogFile();
|
||||||
@ -1546,9 +1544,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
|
|||||||
|
|
||||||
Log(LogDebug, "ApiListener")
|
Log(LogDebug, "ApiListener")
|
||||||
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
|
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
|
||||||
|
return;
|
||||||
stopReplay = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peer_ts = pmessage->Get("timestamp");
|
peer_ts = pmessage->Get("timestamp");
|
||||||
@ -1569,10 +1565,6 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
|
|||||||
}
|
}
|
||||||
|
|
||||||
logStream->Close();
|
logStream->Close();
|
||||||
|
|
||||||
if (stopReplay) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
@ -1587,12 +1579,9 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
|
|||||||
if (last_sync) {
|
if (last_sync) {
|
||||||
OpenLogFile();
|
OpenLogFile();
|
||||||
|
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
} while (!stopReplay);
|
}
|
||||||
|
|
||||||
ObjectLock olock2 (endpoint);
|
|
||||||
endpoint->SetSyncing(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
|
void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user