mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
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 <david@gibson.dropbear.id.au>
This commit is contained in:
parent
75356967c6
commit
1ab72518b3
@ -923,12 +923,12 @@ pub fn get_mounts() -> Result<HashMap<String, String>> {
|
|||||||
let paths = get_paths()?;
|
let paths = get_paths()?;
|
||||||
|
|
||||||
for l in fs::read_to_string(MOUNTS)?.lines() {
|
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 pre: Vec<&str> = p[0].split(' ').collect();
|
||||||
let post: Vec<&str> = p[1].split(' ').collect();
|
let post: Vec<&str> = p[1].split(' ').collect();
|
||||||
|
|
||||||
if post.len() != 3 {
|
if post.len() != 3 {
|
||||||
warn!(sl!(), "mountinfo corrupted!");
|
warn!(sl!(), "can't parse {} line {:?}", MOUNTS, l);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user