mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 20:26:05 -05:00
Merge pull request #6532 from AJ0070/fix-zmc-primelog-sighup
fix: zmc prime failure log rate and SIGHUP during reload
This commit is contained in:
2 files changed
+37
-3
No files matched your search
+3
-3
@@ -313,7 +313,7 @@ int main(int argc, char *argv[]) {
|
||||
Seconds sleep_time = Seconds(0);
|
||||
bool priming_failed = false;
|
||||
while ((monitor->PrimeCapture() <= 0) and !zm_terminate) {
|
||||
if (prime_capture_log_count % 60) {
|
||||
if (prime_capture_log_count % 60 == 0) {
|
||||
logPrintf(Logger::ERROR + monitor->Importance(), "Failed to prime capture of initial monitor");
|
||||
} else {
|
||||
Debug(1, "Failed to prime capture of initial monitor");
|
||||
@@ -503,6 +503,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (zm_reload) {
|
||||
// Clear first so a SIGHUP that arrives while reloading is not lost.
|
||||
zm_reload = false;
|
||||
zmLoadStaticConfig();
|
||||
zmLoadDBConfig();
|
||||
for (std::shared_ptr<Monitor> &monitor : monitors) {
|
||||
@@ -510,8 +512,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
// The dbQueue and stream socket threads are still running and logging.
|
||||
logReload(log_id_string);
|
||||
|
||||
zm_reload = false;
|
||||
} // end if zm_reload
|
||||
} // end while ! zm_terminate outer connection loop
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "zm_monitor.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <getopt.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -74,3 +76,35 @@ TEST_CASE("interruptible sleep stops when asked and keeps ticking", "[zmcmain]")
|
||||
REQUIRE(std::chrono::steady_clock::now() - start < std::chrono::seconds(2));
|
||||
REQUIRE(InterruptibleSleep(std::chrono::milliseconds(150), []() { return false; }, nullptr));
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::string ReadZmcSource() {
|
||||
std::ifstream in(std::string(ZM_SOURCE_DIR) + "/src/zmc.cpp");
|
||||
std::stringstream ss;
|
||||
ss << in.rdbuf();
|
||||
return ss.str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("prime failure logs an error on the first failure and every 60th", "[zmcmain]") {
|
||||
const std::string src = ReadZmcSource();
|
||||
const auto pos = src.find("Failed to prime capture of initial monitor");
|
||||
REQUIRE(pos != std::string::npos);
|
||||
const std::string before = src.substr(pos > 200 ? pos - 200 : 0, pos > 200 ? 200 : pos);
|
||||
REQUIRE(before.find("prime_capture_log_count % 60 == 0") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("zmc clears zm_reload before reloading so a SIGHUP during reload is kept", "[zmcmain]") {
|
||||
const std::string src = ReadZmcSource();
|
||||
const auto start = src.find("if (zm_reload) {\n // Clear first");
|
||||
REQUIRE(start != std::string::npos);
|
||||
const auto reload = src.find("monitor->Reload();", start);
|
||||
REQUIRE(reload != std::string::npos);
|
||||
const auto clear = src.find("zm_reload = false;", start);
|
||||
REQUIRE(clear != std::string::npos);
|
||||
REQUIRE(clear < reload);
|
||||
// No clear after the reload finished, which would drop a SIGHUP that arrived meanwhile.
|
||||
const auto end = src.find("end if zm_reload", reload);
|
||||
REQUIRE(end != std::string::npos);
|
||||
REQUIRE(src.substr(reload, end - reload).find("zm_reload = false") == std::string::npos);
|
||||
}
|
||||
Reference in new issue
Block a user