From 473034fef90408c6794f27bda35ac08aa9f37607 Mon Sep 17 00:00:00 2001 From: slhmy Date: Tue, 1 Oct 2024 21:33:58 +0800 Subject: [PATCH] Add compile timeout --- judge-core/src/compiler.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/judge-core/src/compiler.rs b/judge-core/src/compiler.rs index 7461919..7ffb8d5 100644 --- a/judge-core/src/compiler.rs +++ b/judge-core/src/compiler.rs @@ -10,8 +10,7 @@ const TEMPLATE_ARG_SRC_PATH: &str = "{src_path}"; const TEMPLATE_ARG_TARGET_PATH: &str = "{target_path}"; const RUST_COMPILE_COMMAND_TEMPLATE: &str = "rustc {src_path} -o {target_path}"; -const CPP_COMPILE_COMMAND_TEMPLATE: &str = - "g++ -fmax-include-depth=10 {src_path} -o {target_path} -O2 -static"; +const CPP_COMPILE_COMMAND_TEMPLATE: &str = "g++ {src_path} -o {target_path} -O2 -static"; const PYTHON_COMPILE_COMMAND_TEMPLATE: &str = "cp {src_path} {target_path}"; #[derive(Clone)] @@ -163,7 +162,9 @@ impl Compiler { std::fs::remove_file(target_path)?; } - let output = Command::new("sh") + let output = Command::new("timeout") + .arg("30s") // TODO: make timeout configurable + .arg("sh") .arg("-c") .arg( self.command_builder