From nobody Sun Feb 8 18:49:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541635891767187.57292664849479; Wed, 7 Nov 2018 16:11:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12DC23D968; Thu, 8 Nov 2018 00:11:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A9EE601A1; Thu, 8 Nov 2018 00:11:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CD9494BB79; Thu, 8 Nov 2018 00:11:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA7NviNM011894 for ; Wed, 7 Nov 2018 18:57:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 947056887B; Wed, 7 Nov 2018 23:57:44 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-225.phx2.redhat.com [10.3.116.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39C3968D27; Wed, 7 Nov 2018 23:57:44 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 7 Nov 2018 18:57:39 -0500 Message-Id: <20181107235740.4514-2-jferlan@redhat.com> In-Reply-To: <20181107235740.4514-1-jferlan@redhat.com> References: <20181107235740.4514-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter.Chubb@data61.csiro.au Subject: [libvirt] [PATCH 1/2] util: Fix virCgroupGetMemoryStat X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 08 Nov 2018 00:11:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Peter Chubb Commit 901d2b9c introduced virCgroupGetMemoryStat and replaced the LXC virLXCCgroupGetMemStat logic in commit e634c7cd0. However, in doing so the replacement wasn't exact as the LXC logic used getline() to process the cgroup controller data, while the new virCgroupGetMemoryStat used "memory.stat" manual buffer read/ processing which neglected to forward through @line in order to read each line in the output. To fix that, we should be sure to carry forward the @line value for each line read updating it beyond that current @newLine value once we've calculated the values that we want. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- src/util/vircgroupv1.c | 7 ++++++- src/util/vircgroupv2.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 28a74474ee..678ffda35c 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1476,7 +1476,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, =20 line =3D stat; =20 - while (line) { + while (line && *line) { char *newLine =3D strchr(line, '\n'); char *valueStr =3D strchr(line, ' '); unsigned long long value; @@ -1506,6 +1506,11 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, inactiveFileVal =3D value >> 10; else if (STREQ(line, "unevictable")) unevictableVal =3D value >> 10; + + if (newLine) + line =3D newLine + 1; + else + break; } =20 *cache =3D cacheVal; diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 32adb06784..541e8e790e 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1068,7 +1068,7 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, =20 line =3D stat; =20 - while (line) { + while (line && *line) { char *newLine =3D strchr(line, '\n'); char *valueStr =3D strchr(line, ' '); unsigned long long value; @@ -1102,6 +1102,11 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, inactiveFileVal =3D value >> 10; else if (STREQ(line, "unevictable")) unevictableVal =3D value >> 10; + + if (newLine) + line =3D newLine + 1; + else + break; } =20 *cache =3D cacheVal; --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list