From 31dab4e7ff9f0af243ad089f43d88690e2d129f8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 21 Apr 2021 08:40:49 -0700 Subject: [PATCH] ignore more tokens in some mountinfo entries (#12104) it seems to be legitimate to have `mountinfo` lines to have keywords with spaces such as ``` rootfs overlay / overlay rw,relatime,lowerdir... ``` This was not expected, but for our requirement we can just ignore this and move forward. fixes #12047 Signed-off-by: Harshavardhana --- pkg/mountinfo/mountinfo_linux.go | 4 +++- pkg/mountinfo/mountinfo_linux_test.go | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/mountinfo/mountinfo_linux.go b/pkg/mountinfo/mountinfo_linux.go index 1a38ee361..ea482e8d8 100644 --- a/pkg/mountinfo/mountinfo_linux.go +++ b/pkg/mountinfo/mountinfo_linux.go @@ -131,9 +131,11 @@ func parseMountFrom(file io.Reader) (mountInfos, error) { if err == io.EOF { break } + fields := strings.Fields(line) if len(fields) != expectedNumFieldsPerLine { - return nil, fmt.Errorf("wrong number of fields (expected %d, got %d): %s", expectedNumFieldsPerLine, len(fields), line) + // ignore incorrect lines. + continue } // Freq should be an integer. diff --git a/pkg/mountinfo/mountinfo_linux_test.go b/pkg/mountinfo/mountinfo_linux_test.go index 1e6f4dd30..9d7794658 100644 --- a/pkg/mountinfo/mountinfo_linux_test.go +++ b/pkg/mountinfo/mountinfo_linux_test.go @@ -214,7 +214,6 @@ func TestReadProcMountFrom(t *testing.T) { // Error cases where parsing fails with invalid Freq and Pass params. { errorCases := []string{ - "/dev/0 /path/to/mount\n", "/dev/1 /path/to/mount type flags a 0\n", "/dev/2 /path/to/mount type flags 0 b\n", }