Skip to content

Commit

Permalink
netlink: improved log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Sep 10, 2024
1 parent 79f94ef commit 7490646
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/fastgame_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,9 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
if (nl->listen) {
std::thread t(check_lock_file);

std::thread t_listen([&]() {
nl->handle_events(); // This is a blocking call. It has to be started at the end
});
t.detach();

t_listen.detach();

t.join();
nl->handle_events(); // This is a blocking call. It has to be started at the end

util::info("Netlink event monitor finished.");
}
Expand Down
15 changes: 8 additions & 7 deletions src/netlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "netlink_c.h"
#include "util.hpp"

/*
based on https://gist.github.com/L-P/9487407 and
Expand Down Expand Up @@ -44,9 +45,9 @@ void Netlink::connect() {
if (nl_socket == -1) {
listen = false;

std::cout << log_tag + "socket creation failed!" << '\n';
util::debug("socket creation failed!");
} else {
std::cout << log_tag + "socket created" << '\n';
util::debug("socket created");

sockaddr_nl addr{};

Expand All @@ -59,22 +60,22 @@ void Netlink::connect() {
if (rc == -1) {
listen = false;

std::cout << log_tag + "socket binding failed!" << '\n';
util::debug("socket binding failed!");
} else {
std::cout << log_tag + "socket binding succesful!" << '\n';
util::debug("socket binding succesful!");
}
}
}

void Netlink::subscribe() {
void Netlink::subscribe() const {
struct iovec iov[3];

prepare_iovec(iov);

if (writev(nl_socket, iov, 3) == -1) {
std::cout << log_tag + "failed to send PROC_CN_MCAST_LISTEN!" << '\n';
util::debug("failed to send PROC_CN_MCAST_LISTEN!");
} else {
std::cout << log_tag + "sent PROC_CN_MCAST_LISTEN to kernel" << '\n';
util::debug("sent PROC_CN_MCAST_LISTEN to kernel");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/netlink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Netlink {
int nl_socket = 0;

void connect();
void subscribe();
void subscribe() const;
void handle_msg(cn_msg* msg);

static auto get_cmdline(const int& pid) -> std::string;
Expand Down

0 comments on commit 7490646

Please sign in to comment.