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 d171838 commit 492daf4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/netlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ void Netlink::connect() {
}

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

prepare_iovec(iov);

if (writev(nl_socket, iov, 3) == -1) {
if (nl_subscribe(nl_socket) == -1) {
util::debug("failed to send PROC_CN_MCAST_LISTEN!");
} else {
util::debug("sent PROC_CN_MCAST_LISTEN to kernel");
Expand Down
7 changes: 6 additions & 1 deletion src/netlink_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
#include <linux/cn_proc.h>
#include <linux/connector.h>
#include <linux/netlink.h>
#include <sys/uio.h>
#include <unistd.h>

/*
It was necessary to separate the code using "<linux/cn_proc.h>" because one of its line can only be compiled in a
C compiler...
*/

void prepare_iovec(struct iovec iov[3]) {
int nl_subscribe(int nl_socket) {
struct iovec iov[3];

char buff[NLMSG_LENGTH(0)];
struct cn_msg cnmsg;
enum proc_cn_mcast_op mcast_op = PROC_CN_MCAST_LISTEN;
Expand Down Expand Up @@ -43,6 +46,8 @@ void prepare_iovec(struct iovec iov[3]) {

iov[2].iov_base = &mcast_op;
iov[2].iov_len = sizeof(mcast_op);

return writev(nl_socket, iov, 3);
}

struct fg_cn_msg parse_cn_msg(struct cn_msg* msg) {
Expand Down
2 changes: 1 addition & 1 deletion src/netlink_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct fg_cn_msg {
enum fg_proc_cn_event event;
};

void prepare_iovec(struct iovec iov[3]);
int nl_subscribe(int nl_socket);

struct fg_cn_msg parse_cn_msg(struct cn_msg* msg);

Expand Down

0 comments on commit 492daf4

Please sign in to comment.