This commit is contained in:
mii443
2024-10-17 01:36:05 +00:00
parent 350e376897
commit 09ff168cea
3 changed files with 49 additions and 0 deletions

8
src/bin/izoli.rs Normal file
View File

@ -0,0 +1,8 @@
use izolilib::cgroup::cgroup::CGroup;
fn main() {
println!("test");
let cgroup = CGroup::new("test").unwrap();
println!("{:?}", cgroup.get_root_path());
println!("{}", cgroup.check_status());
}

40
src/cgroup/cgroup.rs Normal file
View File

@ -0,0 +1,40 @@
use std::{
fs,
path::{Path, PathBuf},
};
pub struct CGroup {
pub path: PathBuf,
}
impl CGroup {
pub fn new(path: &str) -> Result<Self, std::io::Error> {
let cgroup = CGroup {
path: PathBuf::from(path),
};
if !cgroup.check_status() {
cgroup.create()?;
}
Ok(cgroup)
}
fn create(&self) -> Result<(), std::io::Error> {
let root = self.get_root_path();
fs::create_dir_all(root)
}
pub fn check_status(&self) -> bool {
let root = self.get_root_path();
root.exists() && root.is_dir()
}
pub fn get_root_path(&self) -> PathBuf {
let cgroup_root = PathBuf::from("/sys/fs/cgroup/");
let root = cgroup_root.join(&self.path);
root
}
}

1
src/cgroup/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod cgroup;