From 2e045fc10518acd75e1fb7816da5c0b9f5b53bd0 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 6 Jul 2021 12:11:29 +1000 Subject: [PATCH] agent: Fix to parsing of /proc/self/mountinfo get_mounts() parses /proc/self/mountinfo in order to get the mountpoints for various cgroup filesystems. One of the entries in mountinfo is the "device" for each filesystem, but for virtual filesystems like /proc, /sys and cgroups, the device entry is arbitrary. Depending on the exact rootfs setup, it can end up being "-". This breaks get_mounts() because it uses " - " as a separator. There really is a " - " separator in mountinfo, but in this case the device entry shows up as a second one. Fix this, by changing a split to a splitn, which will effectively only consider the first " - " in the line. While we're there, make the warning message more useful, by having it actually show which line it wasn't able to parse. fixes #2182 Signed-off-by: David Gibson --- src/agent/rustjail/src/cgroups/fs/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs index 04aa575379..b18bfc6ace 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -923,12 +923,12 @@ pub fn get_mounts() -> Result> { let paths = get_paths()?; for l in fs::read_to_string(MOUNTS)?.lines() { - let p: Vec<&str> = l.split(" - ").collect(); + let p: Vec<&str> = l.splitn(2, " - ").collect(); let pre: Vec<&str> = p[0].split(' ').collect(); let post: Vec<&str> = p[1].split(' ').collect(); if post.len() != 3 { - warn!(sl!(), "mountinfo corrupted!"); + warn!(sl!(), "can't parse {} line {:?}", MOUNTS, l); continue; }