[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] tools/libxenstat: don't skip the /proc/net/dev check after a failure


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
  • Date: Fri, 16 Oct 2026 09:12:58 +0000
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Fri, 16 Oct 2026 09:14:04 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

xenstat_collect_networks() opens /proc/net/dev once and validates its
header before using it. If reading the header fails, or the header isn't
the expected one, an error is returned but the stream is left open in
priv->procnetdev. The next call then finds the stream already open,
skips the validation and parses the file anyway.

Close the stream and clear the pointer on both error paths, so that the
validation is done again on the next call.

Fixes: 49839b535b78 ("Add xenstat framework.")
Assisted-by: Claude-Code:claude-opus-5-5
Signed-off-by: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
---
 tools/libs/stat/xenstat_linux.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index ec627f3ef5..97f7fa9f87 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -296,12 +296,16 @@ int xenstat_collect_networks(xenstat_node * node)
                if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1,
                          priv->procnetdev) != 1) {
                        perror("Error reading /proc/net/dev header");
+                       fclose(priv->procnetdev);
+                       priv->procnetdev = NULL;
                        return 0;
                }
                header[sizeof(PROCNETDEV_HEADER) - 1] = '\0';
                if (strcmp(header, PROCNETDEV_HEADER) != 0) {
                        fprintf(stderr,
                                "Unexpected /proc/net/dev format\n");
+                       fclose(priv->procnetdev);
+                       priv->procnetdev = NULL;
                        return 0;
                }
        }
-- 
2.53.0



--
Olivier Lambert | Vates CEO

XCP-ng & Xen Orchestra - Vates solutions
Book a meeting with me: https://calrs.vates.tech/u/olivier-lambert
web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.