Skip to content

Commit

Permalink
rustjail: fix the issue of invalid cgroup_parent path
Browse files Browse the repository at this point in the history
The cgroup_parent path is expected to be abolute path,
if it was passed a relative path, change it to be an
absolute path.

Fixes: kata-containers#336

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
  • Loading branch information
lifupan committed Sep 9, 2020
1 parent 7f20587 commit 0a60f81
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/agent/rustjail/src/cgroups/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,9 +1388,11 @@ impl CgroupManager for Manager {
impl Manager {
pub fn new(cpath: &str) -> Result<Self> {
let mut m = HashMap::new();
let mut cgroup_path = String::from("");

if !cpath.starts_with('/') {
return Err(nix::Error::Sys(Errno::EINVAL).into());
cgroup_path.push('/');
cgroup_path.push_str(cpath);
}

let paths = get_paths()?;
Expand All @@ -1404,9 +1406,9 @@ impl Manager {
}

let p = if value == "/" {
format!("{}{}", mnt.unwrap(), cpath)
format!("{}{}", mnt.unwrap(), cgroup_path)
} else {
format!("{}{}{}", mnt.unwrap(), value, cpath)
format!("{}{}{}", mnt.unwrap(), value, cgroup_path)
};

m.insert(key.to_string(), p);
Expand Down

0 comments on commit 0a60f81

Please sign in to comment.