Skip to content

Commit

Permalink
refactor: ✨ add hard error for cgroupv1, use rustix instead of libc
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Dec 11, 2023
1 parent 629dec1 commit b9f7306
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 33 deletions.
118 changes: 92 additions & 26 deletions judger/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion judger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ panic = 'abort'
cgroups-rs = "0.3.2"
env_logger = "0.10.1"
futures = "0.3.28"
libc = "0.2.142"
log = "0.4.17"
prost = "0.11.9"
prost-types = "0.11.9"
thiserror = "1.0.40"
toml = "0.7.4"
derive_builder = "0.12.0"

[dependencies.rustix]
version = "0.38.28"
features = ["process","thread"]
[dependencies.uuid]
version = "1.6.1"
features = ["serde"]
Expand Down
10 changes: 5 additions & 5 deletions judger/src/init/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub fn init() {
{
log::warn!("Subsystem Mem(Memory) is unavailable.");
};
log::error!("cgroup v1 is not supported, it fail at cpu task");
std::process::exit(1);
} else {
let hier = hierarchies::V2::new();
let subsystems = hier.subsystems();
Expand All @@ -65,8 +67,8 @@ pub fn init() {
}

if !config.nsjail.rootless {
let uid = unsafe { libc::getuid() };
if uid != 0 {
let uid = rustix::process::getuid();
if !uid.is_root() {
log::warn!("config.rootless is set to false, require root to run");
}
} else {
Expand All @@ -84,10 +86,8 @@ pub fn init() {

if config.platform.output_limit >= config.platform.available_memory.try_into().unwrap() {
log::error!("config.platform.output_limit is too larget or config.platform.available_memory is too low");
unsafe {
libc::abort();
std::process::exit(1);
}
}

if config.platform.output_limit * 8 >= config.platform.available_memory.try_into().unwrap() {
log::warn!("config.platform.output_limit is consider too high");
Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a> Container<'a> {
.done()
.common()
.cmds(args)
.build()?;
.build()?;

let limiter = Limiter::new(&cg_name, limit)?;

Expand Down

0 comments on commit b9f7306

Please sign in to comment.