Skip to content

Commit

Permalink
Prepare runguard
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 25, 2024
1 parent 262f0c8 commit 6ddcb17
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["judge-core", "judger"]
resolver = "2"
members = ["judge-core", "judger", "runguard"]
resolver = "2"
8 changes: 8 additions & 0 deletions runguard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "runguard"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4", features = ["derive"] }
humantime = "2"
5 changes: 5 additions & 0 deletions runguard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# runguard

A Rust version of
[Domjudge runguard](https://github.com/DOMjudge/domjudge/blob/main/judge/runguard.cc)
written in C++.
102 changes: 102 additions & 0 deletions runguard/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use std::path;

use clap::Parser;

#[derive(Parser)]
#[command(
override_usage = "runguard [OPTION]... <COMMAND>...",
about = "Run COMMAND with specified options.",
after_help = "Note that root privileges are needed for the `root' and `user' options. \
If `user' is set, then `group' defaults to the same to prevent security issues, \
since otherwise the process would retain group root permissions. \
The COMMAND path is relative to the changed ROOT directory if specified. \
TIME may be specified as a float; two floats separated by `:' are treated as soft and hard limits. \
The runtime written to file is that of the last of wall/cpu time options set, \
and defaults to CPU time when neither is set. \
When run setuid without the `user' option, the user ID is set to the real user ID."
)]
pub struct Cli {
/// run COMMAND with root directory set to ROOT
#[arg(short, long)]
root: String,

/// run COMMAND as user with username or ID USER
#[arg(short, long)]
user: String,

/// run COMMAND under group with name or ID GROUP
#[arg(short, long)]
group: String,

/// change to directory DIR after setting root directory
#[arg(short = 'd', long, value_name = "DIR")]
chdir: String,

/// kill COMMAND after TIME wallclock seconds
#[arg(short = 't', long, value_name = "TIME")]
walltime: humantime::Duration,

/// set maximum CPU time to TIME seconds
#[arg(short = 'C', long, value_name = "TIME")]
cputime: humantime::Duration,

/// set total memory limit to SIZE kB
#[arg(short = 'm', long, value_name = "SIZE")]
memsize: u64,

/// set maximum created filesize to SIZE kB
#[arg(short = 'f', long, value_name = "SIZE")]
filesize: u64,

/// set maximum no. processes to N
#[arg(short = 'p', long, value_name = "N")]
nproc: u64,

/// use only processor number ID (or set, e.g. \"0,2-3\")
#[arg(short = 'P', long, value_name = "ID")]
cpuset: String,

/// disable core dumps
#[arg(short = 'c', long)]
no_core: bool,

/// redirect COMMAND stdout output to FILE
#[arg(short = 'o', long, value_name = "FILE")]
stdout: path::PathBuf,

/// redirect COMMAND stderr output to FILE
#[arg(short = 'e', long, value_name = "FILE")]
stderr: path::PathBuf,

/// truncate COMMAND stdout/stderr streams at SIZE kB
#[arg(short, long, value_name = "SIZE")]
streamsize: u64,

/// preserve environment variables (default only PATH)
#[arg(short = 'E', long)]
environment: String,

/// write metadata (runtime, exitcode, etc.) to FILE
#[arg(short = 'M', long, value_name = "FILE")]
metadata: path::PathBuf,

/// process ID of runpipe to send SIGUSR1 signal when
/// timelimit is reached
#[arg(short = 'U', long, value_name = "PID")]
runpipepid: u32,

/// display some extra warnings and information
#[arg(short, long)]
verbose: bool,

/// suppress all warnings and verbose output
#[arg(short, long)]
quiet: bool,

/// output version information and exit
#[arg(long)]
version: bool,

#[arg(required = true)]
command: Vec<String>,
}
8 changes: 8 additions & 0 deletions runguard/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod cli;

use clap::Parser;
use cli::Cli;

fn main() {
let _ = Cli::parse();
}

0 comments on commit 6ddcb17

Please sign in to comment.