Skip to contentSkip to conversation

libgenl: report a verbose error if rtnl_talk fails

PATCH In review Denis Kirjanov 2 participants 2 messages Feb 28, 2025 – Mar 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libgenl: report a verbose error if rtnl_talk fails

Currenlty rtnl_talk() doesn't give us the reason
if it fails.

---
 lib/libgenl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/libgenl.c +4 -2
index fca07f9f..9927af84 100644
@@ -58,7 +58,8 @@ int genl_resolve_family(struct rtnl_handle *grth, const char *family)
 		  family, strlen(family) + 1);
 
 	if (rtnl_talk(grth, &req.n, &answer) < 0) {
-		fprintf(stderr, "Error talking to the kernel\n");
+		fprintf(stderr, "Error talking to the kernel: %s (errno %d)\n",
+			strerror(errno), errno);
 		return -2;
 	}
 
@@ -103,7 +104,8 @@ int genl_add_mcast_grp(struct rtnl_handle *grth, __u16 fnum, const char *group)
 	addattr16(&req.n, sizeof(req), CTRL_ATTR_FAMILY_ID, fnum);
 
 	if (rtnl_talk(grth, &req.n, &answer) < 0) {
-		fprintf(stderr, "Error talking to the kernel\n");
+		fprintf(stderr, "Error talking to the kernel: %s (errno %d)\n",
+			strerror(errno), errno);
 		return -2;
 	}
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · On Fri, 28 Feb 2025 16:34:31 +0300 Denis Kirjanov <[email protected]> wrote:

Currenlty rtnl_talk() doesn't give us the reason
if it fails.

---

Don't think this is needed.
- inside rtnl_talk, it already prints (using perror) if it is a kernel reported error
- lots of other places call rtnl_talk() what is special about genl

Better to move any required error prints into libnetlink.c

Even better is to make sure any errors in kernel are using extack to give better messages.