From 455b4a53bd3d781ddde82198c5a724c46d8ea395 Mon Sep 17 00:00:00 2001 From: lifubang Date: Fri, 17 Oct 2025 06:13:00 +0000 Subject: [PATCH] v1: fix a regression when reading cpuacct.usage_all MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reading cpuacct.usage_all, we assume each line contains exactly three columns; Lines with a different number of columns should be skipped. However, a regression was introduced when the column count exceeds three. The parameter 'n' in strings.SplitN was changed to 3, causing the split result to always contain exactly three elements—any additional columns are concatenated into the third field. This breaks subsequent unit parsing. Reported-by: vimiix Signed-off-by: lifubang --- fs/cpuacct.go | 5 ++++- fs/cpuacct_test.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/cpuacct.go b/fs/cpuacct.go index 391a023..dd5d7c9 100644 --- a/fs/cpuacct.go +++ b/fs/cpuacct.go @@ -133,7 +133,10 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) { for scanner.Scan() { // Each line is: cpu user system - fields := strings.SplitN(scanner.Text(), " ", 3) + // Keep 'n' at 4 — downstream changes or refactoring of + // "cpuacct.usage_all" could otherwise break system usage parsing. + // (issue: https://github.com/opencontainers/cgroups/issues/46) + fields := strings.SplitN(scanner.Text(), " ", 4) if len(fields) != 3 { continue } diff --git a/fs/cpuacct_test.go b/fs/cpuacct_test.go index c0c9543..2c82756 100644 --- a/fs/cpuacct_test.go +++ b/fs/cpuacct_test.go @@ -20,6 +20,7 @@ const ( 5 872544369885276 638763309884944 6 870104915696359 640081778921247 7 870202363887496 638716766259495 + 8 867579076304580 988021047245223 792312716071280 109505081909990 ` )