Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send discovered services to standard output #38

Merged
merged 15 commits into from
Oct 25, 2023
Prev Previous commit
Next Next commit
don't wait for servicesProvidingLoop sleep to finish when exiting pro…
…gram
  • Loading branch information
Przemyslaw Susko committed Oct 25, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
bastelfreak Tim Meusel
commit 32180a0d9e2a5c34fc334e63aee7a49ab015c624
10 changes: 3 additions & 7 deletions ebpfdiscoverysrv/src/main.cpp
Original file line number Diff line number Diff line change
@@ -112,20 +112,16 @@ static void initLibbpf() {
libbpf_set_print(libbpfPrintFn);
}

bool isProgramRunning() {
std::lock_guard<std::mutex> lock(programStatusMutex);
return programStatus == ProgramStatus::Running;
}

void servicesProvidingLoop(ebpfdiscovery::Discovery& discoveryInstance, std::chrono::seconds interval) {
while (isProgramRunning()) {
std::unique_lock<std::mutex> lock(programStatusMutex);
while (programStatus == ProgramStatus::Running) {
przsus marked this conversation as resolved.
Show resolved Hide resolved
if (auto services = discoveryInstance.popServices(); !services.empty()) {
auto servicesProto = proto::internalToProto(services);
LOG_DEBUG("Services list:\n{}\n", servicesProto.DebugString());
auto servicesJson = proto::protoToJson(servicesProto);
std::cout << servicesJson << std::endl;
}
std::this_thread::sleep_for(interval);
programStatusCV.wait_for(lock, interval);
}
}