[PATCH 05/12] batctl: netlink: detect receive errors in netlink_print_common

Sven Eckelmann <[email protected]> Wed, 08 Jul 2026 22:00:11 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
netlink_print_common() clears last_err to 0 before each dump and then
ignores the return value of nl_recvmsgs(). It will therefore only print
errors which were received in netlink messages - but not the major errors
when communicating with the kernel.

Capture the nl_recvmsgs() return value, matching the sibling helper
netlink_query_common().

Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 netlink.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/netlink.c b/netlink.c
index e8b41cf..6e0d35a 100644
--- a/netlink.c
+++ b/netlink.c
@@ -537,6 +537,7 @@ int netlink_print_common(struct state *state, char *orig_iface, int read_opt,
 	};
 	int hardifindex = 0;
 	struct nl_msg *msg;
+	int ret;
 
 	if (!state->sock) {
 		last_err = -EOPNOTSUPP;
@@ -588,7 +589,9 @@ int netlink_print_common(struct state *state, char *orig_iface, int read_opt,
 		nlmsg_free(msg);
 
 		last_err = 0;
-		nl_recvmsgs(state->sock, state->cb);
+		ret = nl_recvmsgs(state->sock, state->cb);
+		if (ret < 0)
+			last_err = -EIO;
 
 		/* the header should still be printed when no entry was received */
 		if (!last_err)

-- 
2.47.3