[lxc-devel] [lxcfs/master] cpuview: fix /proc/stat virtualization

brauner on Github lxc-bot at linuxcontainers.org
Tue Jun 2 14:11:06 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 380 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200602/bf9f1d92/attachment-0001.bin>
-------------- next part --------------
From 1494771eb4f0391bd49a26f91f9918e0ba37ac82 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 2 Jun 2020 16:10:20 +0200
Subject: [PATCH] cpuview: fix /proc/stat virtualization

Closes: #406.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/proc_fuse.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index ae06bff..41ac0b1 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -780,6 +780,10 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	if (!f)
 		return 0;
 
+	/* Skip first system cpu line. */
+	if (getline(&line, &linelen, f) < 0)
+		return log_error(0, "proc_stat_read read first line failed");
+
 	/*
 	 * Read cpuacct.usage_all for all CPUs.
 	 * If the cpuacct cgroup is present, it is used to calculate the container's
@@ -796,10 +800,6 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 		lxcfs_v("proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat");
 	}
 
-	//skip first line
-	if (getline(&line, &linelen, f) < 0)
-		return log_error(0, "proc_stat_read read first line failed");
-
 	while (getline(&line, &linelen, f) != -1) {
 		ssize_t l;
 		char cpu_char[10]; /* That's a lot of cores */


More information about the lxc-devel mailing list