Skip to contentSkip to conversation

ifstat: make load_info() more verbose on error

PATCH Applied Denis Kirjanov 2 participants 2 messages Jan 26, 2024 – Jan 30, 2024

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

PATCH 1/1 ifstat: make load_info() more verbose on error

From: Denis Kirjanov <[email protected]>

convert frprintf calls to perror() so the caller
can see the reason of an error

---
 misc/ifstat.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
misc/ifstat.c +16 -8
index f6f9ba50..721f4914 100644
@@ -117,16 +117,20 @@ static int get_nlmsg_extended(struct nlmsghdr *m, void *arg)
 		return 0;
 
 	len -= NLMSG_LENGTH(sizeof(*ifsm));
-	if (len < 0)
+	if (len < 0) {
+		errno = EINVAL;
 		return -1;
+	}
 
 	parse_rtattr(tb, IFLA_STATS_MAX, IFLA_STATS_RTA(ifsm), len);
 	if (tb[filter_type] == NULL)
 		return 0;
 
 	n = malloc(sizeof(*n));
-	if (!n)
-		abort();
+	if (!n) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	n->ifindex = ifsm->ifindex;
 	n->name = strdup(ll_index_to_name(ifsm->ifindex));
@@ -161,8 +165,10 @@ static int get_nlmsg(struct nlmsghdr *m, void *arg)
 		return 0;
 
 	len -= NLMSG_LENGTH(sizeof(*ifi));
-	if (len < 0)
+	if (len < 0) {
+		errno = EINVAL;
 		return -1;
+	}
 
 	if (!(ifi->ifi_flags&IFF_UP))
 		return 0;
@@ -172,8 +178,10 @@ static int get_nlmsg(struct nlmsghdr *m, void *arg)
 		return 0;
 
 	n = malloc(sizeof(*n));
-	if (!n)
-		abort();
+	if (!n) {
+		errno = ENOMEM;
+		return -1;
+	}
 	n->ifindex = ifi->ifi_index;
 	n->name = strdup(RTA_DATA(tb[IFLA_IFNAME]));
 	memcpy(&n->ival, RTA_DATA(tb[IFLA_STATS]), sizeof(n->ival));
@@ -204,7 +212,7 @@ static void load_info(void)
 		}
 
 		if (rtnl_dump_filter(&rth, get_nlmsg_extended, NULL) < 0) {
-			fprintf(stderr, "Dump terminated\n");
+			perror("Dump terminated\n");
 			exit(1);
 		}
 	} else {
@@ -214,7 +222,7 @@ static void load_info(void)
 		}
 
 		if (rtnl_dump_filter(&rth, get_nlmsg, NULL) < 0) {
-			fprintf(stderr, "Dump terminated\n");
+			perror("Dump terminated\n");
 			exit(1);
 		}
 	}
Signature · 1 line
2.30.2
#1 lore raw
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 8 lines · On Fri, 26 Jan 2024 05:08:55 -0500 you wrote:

From: Denis Kirjanov <[email protected]>

convert frprintf calls to perror() so the caller
can see the reason of an error

[...]

Here is the summary with links:
- [iproute2] ifstat: make load_info() more verbose on error

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=ddcc9329352a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html