eval: limit docker output to not run out of memory

This commit is contained in:
1computer1 2020-06-07 03:43:41 -04:00
parent c57a563ea3
commit 1996ab90ca
27 changed files with 29 additions and 28 deletions

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.apl cat > program.apl
apl --OFF -s -f program.apl || true apl --OFF -s -f program.apl || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.sh cat > program.sh
bash program.sh || true bash program.sh || true

View file

@ -1 +1 @@
printf %s "$1" | bf || true cat | bf || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.c cat > program.c
gcc program.c -o program && ./program || true gcc program.c -o program && ./program || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.clj cat > program.clj
clojure program.clj || true clojure program.clj || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.cpp cat > program.cpp
g++ program.cpp -o program && ./program || true g++ program.cpp -o program && ./program || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.cs cat > program.cs
csc program.cs >/dev/null && mono program.exe || true csc program.cs >/dev/null && mono program.exe || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.exs cat > program.exs
elixir program.exs || true elixir program.exs || true

View file

@ -1,3 +1,3 @@
echo "%% -*- erlang -*-" > program.erl echo "%% -*- erlang -*-" > program.erl
printf %s "$1" >> program.erl cat >> program.erl
escript program.erl || true escript program.erl || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.fs cat > program.fs
fsharpc --optimize- program.fs >/dev/null && mono program.exe || true fsharpc --optimize- program.fs >/dev/null && mono program.exe || true

View file

@ -1,3 +1,3 @@
export GOCACHE=/tmp/"$CODEDIR"/cache export GOCACHE=/tmp/"$CODEDIR"/cache
printf %s "$1" > program.go cat > program.go
go run program.go || true go run program.go || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.hs cat > program.hs
ghc -e main program.hs || true ghc -e main program.hs || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > Main.idr cat > Main.idr
idris --execute ./Main.idr || true idris --execute ./Main.idr || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > Main.java cat > Main.java
javac Main.java && java Main || true javac Main.java && java Main || true

View file

@ -1 +1 @@
printf %s "$1" | node -p || true cat | node -p || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.jl cat > program.jl
julia program.jl || true julia program.jl || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.lua cat > program.lua
lua5.3 program.lua || true lua5.3 program.lua || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.ml cat > program.ml
ocamlopt -cclib --static -o program program.ml && ./program || true ocamlopt -cclib --static -o program program.ml && ./program || true

View file

@ -1,4 +1,4 @@
printf %s "$1" > program.pas cat > program.pas
# fpc does not use stderr, ld however does, capture both # fpc does not use stderr, ld however does, capture both
res="$(fpc program.pas 2>&1)" res="$(fpc program.pas 2>&1)"

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.pl cat > program.pl
perl program.pl || true perl program.pl || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.php cat > program.php
php program.php || true php program.php || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.pl cat > program.pl
swipl --quiet program.pl || true swipl --quiet program.pl || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.py cat > program.py
python program.py || true python program.py || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.rkt cat > program.rkt
racket program.rkt || true racket program.rkt || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.rb cat > program.rb
ruby program.rb || true ruby program.rb || true

View file

@ -1,2 +1,2 @@
printf %s "$1" > program.rs cat > program.rs
rustc -C opt-level=0 --color never program.rs && ./program || true rustc -C opt-level=0 --color never program.rs && ./program || true

View file

@ -179,8 +179,9 @@ evalCode lang@LanguageConfig { name, timeout, retries } numRetries code = withCo
exec_ ["docker exec ", cs cnt, " mkdir eval/", show snowflake] exec_ ["docker exec ", cs cnt, " mkdir eval/", show snowflake]
exec_ ["docker exec ", cs cnt, " chmod 777 eval/", show snowflake] exec_ ["docker exec ", cs cnt, " chmod 777 eval/", show snowflake]
-- User 1001 will be used for the actual execution so that they can't access `eval` itself -- User 1001 will be used for the actual execution so that they can't access `eval` itself
let args = ["exec", "-u1001:1001", "-w/tmp/eval/" <> show snowflake, cnt, "/bin/sh", "/var/run/run.sh", code] let cmd = concat ["docker exec -i -u1001:1001 -w/tmp/eval/", show snowflake, " ", cnt, " /bin/sh /var/run/run.sh | head -c 4K"]
output <- readProcessInterleaved_ $ proc "docker" args pr = setStdin (byteStringInput $ cs code) $ shell cmd
output <- readProcessInterleaved_ pr
exec_ ["docker exec ", cnt, " rm -rf eval/", show snowflake] exec_ ["docker exec ", cnt, " rm -rf eval/", show snowflake]
logInfo ["Ran code in container ", cs cnt, ", evaluation ", cs $ show snowflake] logInfo ["Ran code in container ", cs cnt, ", evaluation ", cs $ show snowflake]
pure $ EvalOk output pure $ EvalOk output