diff --git a/judger/justfile b/judger/justfile index a13a2d46..f2c3c941 100644 --- a/judger/justfile +++ b/judger/justfile @@ -11,7 +11,7 @@ release-plugin: cd plugins sh export-all.sh build-nsjail: - cd nsjail-docker && make nsjail-3.1 + cd nsjail-docker && sudo make nsjail-3.1 cp nsjail-docker/output/*-linux-musl/nsjail-* . prepare: diff --git a/judger/plugins/c-11/compile.c b/judger/plugins/c-11/compile.c index ec290b40..cae07cda 100644 --- a/judger/plugins/c-11/compile.c +++ b/judger/plugins/c-11/compile.c @@ -5,21 +5,24 @@ #include #include #include +#define handle(x,e) { \ + if (e == x) \ + { \ + printf("4: %m\n", errno); \ + return 1; \ + } \ +} #define CC "/usr/local/bin/g++" -#define SRC "/src/src.c" +#define SRC "/src/src.cpp" #define OUT "/src/src.out" #define MAX_SIZE 131072 int main() { FILE *source = fopen(SRC, "w"); - if (source == NULL) - { - printf("2: %m\n", errno); - return 1; - } - else - printf("1: success create file!\n"); + handle(source,NULL); + + printf("1: success create file!\n"); char *code = malloc(MAX_SIZE * sizeof(char)); size_t len = fread(code, sizeof(char), MAX_SIZE, stdin); @@ -29,15 +32,12 @@ int main() char *args[] = {CC, "-x", "c", SRC, "-lm", "-o", OUT, NULL}; int pid, status; - if (execvp(CC, args) != -1) - { - printf("1: success execv!\n"); - if (wait(NULL) != -1) - { - printf("0: success!\n"); - return 0; - } - } - printf("4: %m\n", errno); + + handle(chdir("/tmp"),-1); + handle(execvp(CC, args),-1); + printf("1: success execv!\n"); + + handle(wait(NULL),-1); + printf("0: success!\n"); return 1; } \ No newline at end of file diff --git a/judger/plugins/cpp-11/compile.c b/judger/plugins/cpp-11/compile.c index e21a971d..cad6d2cc 100644 --- a/judger/plugins/cpp-11/compile.c +++ b/judger/plugins/cpp-11/compile.c @@ -5,6 +5,13 @@ #include #include #include +#define handle(x,e) { \ + if (e == x) \ + { \ + printf("4: %m\n", errno); \ + return 1; \ + } \ +} #define CC "/usr/local/bin/g++" #define SRC "/src/src.cpp" #define OUT "/src/src.out" @@ -13,13 +20,9 @@ int main() { FILE *source = fopen(SRC, "w"); - if (source == NULL) - { - printf("2: %m\n", errno); - return 1; - } - else - printf("1: success create file!\n"); + handle(source,NULL); + + printf("1: success create file!\n"); char *code = malloc(MAX_SIZE * sizeof(char)); size_t len = fread(code, sizeof(char), MAX_SIZE, stdin); @@ -29,15 +32,12 @@ int main() char *args[] = {CC, SRC, "-lm", "-o", OUT, NULL}; int pid, status; - if (execvp(CC, args) != -1) - { - printf("1: success execv!\n"); - if (wait(NULL) != -1) - { - printf("0: success!\n"); - return 0; - } - } - printf("4: %m\n", errno); + + handle(chdir("/tmp"),-1); + handle(execvp(CC, args),-1); + printf("1: success execv!\n"); + + handle(wait(NULL),-1); + printf("0: success!\n"); return 1; } \ No newline at end of file diff --git a/judger/src/init/logger.rs b/judger/src/init/logger.rs index cbb3eaf5..4f2685fc 100644 --- a/judger/src/init/logger.rs +++ b/judger/src/init/logger.rs @@ -25,6 +25,7 @@ pub fn init() { let default_panic = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { default_panic(info); + log::error!("Panic at {}",info.location().map(|x|x.to_string()).unwrap_or_default()); std::process::exit(1); })); } diff --git a/judger/src/langs/artifact.rs b/judger/src/langs/artifact.rs index d31ee51a..f1244c5d 100644 --- a/judger/src/langs/artifact.rs +++ b/judger/src/langs/artifact.rs @@ -190,6 +190,7 @@ impl<'a> CompiledArtifact<'a> { time: u64, memory: u64, ) -> Result { + log::debug!("Exit status: {}",self.process.status); debug_assert!(self.process.succeed()); let spec = self.spec; let mut limit = spec.judge_limit.clone().apply_platform(); @@ -227,6 +228,7 @@ impl<'a> CompiledArtifact<'a> { time: u64, memory: u64, ) -> Result { + log::debug!("Exit status: {}",self.process.status); debug_assert!(self.process.succeed()); let spec = self.spec; let mut limit = spec.judge_limit.clone().apply_platform(); diff --git a/judger/src/sandbox/utils/nsjail.rs b/judger/src/sandbox/utils/nsjail.rs index b142f113..5c80e131 100644 --- a/judger/src/sandbox/utils/nsjail.rs +++ b/judger/src/sandbox/utils/nsjail.rs @@ -101,7 +101,9 @@ impl MountBuilder { self } - pub fn done(self) -> CommonBuilder { + pub fn done(mut self) -> CommonBuilder { + self.cmds.push(Cow::Borrowed("--tmpfsmount")); + self.cmds.push(Cow::Borrowed("/tmp")); CommonBuilder { cmds: self.cmds } } }