mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
wip
This commit is contained in:
8
src/bin/izoli.rs
Normal file
8
src/bin/izoli.rs
Normal 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
40
src/cgroup/cgroup.rs
Normal 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
1
src/cgroup/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod cgroup;
|
Reference in New Issue
Block a user