aboutsummaryrefslogtreecommitdiff
path: root/judge/core.ml
diff options
context:
space:
mode:
Diffstat (limited to 'judge/core.ml')
-rw-r--r--judge/core.ml10
1 files changed, 7 insertions, 3 deletions
diff --git a/judge/core.ml b/judge/core.ml
index 65a43a8..34d5dc9 100644
--- a/judge/core.ml
+++ b/judge/core.ml
@@ -67,6 +67,7 @@ module C (G: GAME) : CORE = struct
type player = {
name: string;
binary: string;
+ dir: string;
log_out: file_descr;
mutable score: int;
}
@@ -149,19 +150,21 @@ module C (G: GAME) : CORE = struct
let rec rd () =
try let s = readdir fd in
try
- let b = Filename.concat (Filename.concat !game_dir s) "player" in
+ let dir = Filename.concat !game_dir s in
+ let b = Filename.concat dir "player" in
let st = Unix.stat b in
if (st.st_kind = S_REG || st.st_kind = S_LNK)
&& (st.st_perm land 0o100 <> 0) then begin
Format.printf "- %s@." s;
(* open log output for player *)
- let p_log_file = Filename.concat (Filename.concat !game_dir s) "stderr.log" in
+ let p_log_file = Filename.concat dir "stderr.log" in
let p_log_out = Unix.openfile p_log_file [O_APPEND; O_CREAT; O_WRONLY] 0o644 in
let f = Format.formatter_of_out_channel (out_channel_of_descr p_log_out) in
Format.fprintf f "---- Begin session %s@." date;
Hashtbl.add players s
{ name = s;
binary = b;
+ dir;
log_out = p_log_out;
score = 0; }
end
@@ -188,12 +191,13 @@ module C (G: GAME) : CORE = struct
Format.printf "Launching match: %s vs. %s@." p1 p2;
let open_c p =
- let f =Format.formatter_of_out_channel (out_channel_of_descr p.log_out) in
+ let f = Format.formatter_of_out_channel (out_channel_of_descr p.log_out) in
Format.fprintf f "--- Begin game (%s vs. %s)@." p1 p2;
let (j2p_i, j2p_o) = pipe () in
let (p2j_i, p2j_o) = pipe () in
let pid = fork() in
if pid = 0 then begin
+ chdir p.dir;
dup2 j2p_i stdin;
dup2 p2j_o stdout;
dup2 p.log_out stderr;