mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
add derive
This commit is contained in:
@ -5,7 +5,7 @@ use izolilib::{
|
||||
cgroup::CGroup, cgroup_option::CGroupOption, cpu_limit::CpuLimit,
|
||||
limit_value::CGroupLimitValue,
|
||||
},
|
||||
izolibox::IzoliBox,
|
||||
izolibox::{IzoliBox, IzoliBoxOptions},
|
||||
};
|
||||
use nix::{sys::wait::waitpid, unistd::execvp};
|
||||
use tracing::Level;
|
||||
@ -23,12 +23,14 @@ fn main() {
|
||||
|
||||
let izolibox = IzoliBox::new(
|
||||
1,
|
||||
Some(CGroupOption {
|
||||
IzoliBoxOptions {
|
||||
cgroup_option: Some(CGroupOption {
|
||||
cpu_max: Some(CpuLimit {
|
||||
max: CGroupLimitValue::Max,
|
||||
period: 100000,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
);
|
||||
let pid = izolibox
|
||||
.enter(Box::new(|| {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum CGroupLimitValue<T>
|
||||
where
|
||||
T: FromStr + std::fmt::Display,
|
||||
|
@ -14,12 +14,17 @@ const STACK_SIZE: usize = 8192;
|
||||
|
||||
pub struct IzoliBox {
|
||||
pub id: usize,
|
||||
pub options: IzoliBoxOptions,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct IzoliBoxOptions {
|
||||
pub cgroup_option: Option<CGroupOption>,
|
||||
}
|
||||
|
||||
impl IzoliBox {
|
||||
pub fn new(id: usize, cgroup_option: Option<CGroupOption>) -> Self {
|
||||
Self { id, cgroup_option }
|
||||
pub fn new(id: usize, options: IzoliBoxOptions) -> Self {
|
||||
Self { id, options }
|
||||
}
|
||||
|
||||
pub fn enter(&self, callback: CloneCb<'_>) -> Result<Pid, nix::errno::Errno> {
|
||||
@ -31,7 +36,7 @@ impl IzoliBox {
|
||||
| CloneFlags::CLONE_NEWPID
|
||||
| CloneFlags::CLONE_NEWNET;
|
||||
|
||||
if let Some(cgroup_option) = &self.cgroup_option {
|
||||
if let Some(cgroup_option) = &self.options.cgroup_option {
|
||||
let cgroup = CGroup::new(&format!("izoli/box_{}", self.id)).unwrap();
|
||||
cgroup.apply_options(cgroup_option).unwrap();
|
||||
cgroup.enter().unwrap();
|
||||
|
Reference in New Issue
Block a user