Skip to content

Commit

Permalink
netlink: improved event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Sep 10, 2024
1 parent 880e9b8 commit 3a8daae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/netlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ void Netlink::handle_events() {
auto* nlmsg_hdr = reinterpret_cast<nlmsghdr*>(buff.data());

while (NLMSG_OK(nlmsg_hdr, len) && listen) {
if (nlmsg_hdr->nlmsg_type == NLMSG_NOOP) {
if ((nlmsg_hdr->nlmsg_type == NLMSG_ERROR) || (nlmsg_hdr->nlmsg_type == NLMSG_NOOP)) {
continue;
}

if ((nlmsg_hdr->nlmsg_type == NLMSG_ERROR) || (nlmsg_hdr->nlmsg_type == NLMSG_OVERRUN)) {
break;
}

auto* cnmsg = static_cast<cn_msg*>(NLMSG_DATA(nlmsg_hdr));

handle_msg(cnmsg);
if (!handle_msg(cnmsg)) {
continue;
}

if (nlmsg_hdr->nlmsg_type == NLMSG_DONE) {
break;
Expand All @@ -130,9 +128,9 @@ void Netlink::handle_events() {
}
}

void Netlink::handle_msg(cn_msg* msg) {
auto Netlink::handle_msg(cn_msg* msg) -> bool {
if ((msg->id.idx != CN_IDX_PROC) || (msg->id.val != CN_VAL_PROC)) {
return;
return false;
}

struct fg_cn_msg parsed_msg = parse_cn_msg(msg);
Expand Down Expand Up @@ -183,6 +181,8 @@ void Netlink::handle_msg(cn_msg* msg) {
default:
break;
}

return true;
}

auto Netlink::get_comm(const int& pid) -> std::string {
Expand Down
2 changes: 1 addition & 1 deletion src/netlink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Netlink {

void connect();
void subscribe() const;
void handle_msg(cn_msg* msg);
auto handle_msg(cn_msg* msg) -> bool;

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

0 comments on commit 3a8daae

Please sign in to comment.