From 7cd828cf329aa89c2106a8a383a9bba9fd2b908f Mon Sep 17 00:00:00 2001 From: Przemyslaw Susko Date: Wed, 25 Oct 2023 08:30:36 +0200 Subject: [PATCH] lock mutex on reading program status --- ebpfdiscoverysrv/src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ebpfdiscoverysrv/src/main.cpp b/ebpfdiscoverysrv/src/main.cpp index be96c1eb..d4ccf853 100644 --- a/ebpfdiscoverysrv/src/main.cpp +++ b/ebpfdiscoverysrv/src/main.cpp @@ -112,8 +112,13 @@ static void initLibbpf() { libbpf_set_print(libbpfPrintFn); } +bool isProgramRunning() { + std::lock_guard lock(programStatusMutex); + return programStatus == ProgramStatus::Running; +} + void servicesProvidingLoop(ebpfdiscovery::Discovery& discoveryInstance, std::chrono::seconds interval) { - while (programStatus == ProgramStatus::Running) { + while (isProgramRunning()) { if (auto services = discoveryInstance.popServices(); !services.empty()) { auto servicesProto = proto::internalToProto(services); LOG_DEBUG("Services list:\n{}\n", servicesProto.DebugString());