fix jelly, move all executor code to runner permission, introduce stdout/stderr separate output to the api
This commit is contained in:
parent
15b6f6e8d6
commit
b81690a9de
48
api/main.go
48
api/main.go
|
@ -28,6 +28,8 @@ type Outbound struct {
|
|||
Language string `json:"language"`
|
||||
Version string `json:"version"`
|
||||
Output string `json:"output"`
|
||||
Stdout string `json:"stdout"`
|
||||
Stderr string `json:"stderr"`
|
||||
}
|
||||
|
||||
type Language struct {
|
||||
|
@ -124,6 +126,18 @@ func Versions(res http.ResponseWriter, req *http.Request) {
|
|||
res.Write(data)
|
||||
}
|
||||
|
||||
type StdWriter struct {
|
||||
combined *string
|
||||
separate *string
|
||||
}
|
||||
|
||||
func (writer *StdWriter) Write(data []byte) (int, error) {
|
||||
*writer.combined += string(data)
|
||||
*writer.separate += string(data)
|
||||
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
func launch(request Inbound, res http.ResponseWriter) {
|
||||
stamp := time.Now().UnixNano()
|
||||
|
||||
|
@ -136,9 +150,33 @@ func launch(request Inbound, res http.ResponseWriter) {
|
|||
cmd := exec.Command("../lxc/execute", request.Language, srcfile, strings.Join(request.Args, "\n"))
|
||||
|
||||
// capture out/err
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
var stdout, stderr, combined string
|
||||
|
||||
cmd.Stdout = &StdWriter{
|
||||
combined: &combined,
|
||||
separate: &stdout,
|
||||
}
|
||||
|
||||
cmd.Stderr = &StdWriter{
|
||||
combined: &combined,
|
||||
separate: &stderr,
|
||||
}
|
||||
|
||||
stdout = strings.TrimSpace(stdout)
|
||||
stderr = strings.TrimSpace(stderr)
|
||||
combined = strings.TrimSpace(combined)
|
||||
|
||||
if len(stdout) > 65536 {
|
||||
stdout = stdout[:65536]
|
||||
}
|
||||
|
||||
if len(stderr) > 65536 {
|
||||
stderr = stdout[:65536]
|
||||
}
|
||||
|
||||
if len(combined) > 65536 {
|
||||
combined = combined[:65536]
|
||||
}
|
||||
|
||||
err := cmd.Run()
|
||||
|
||||
|
@ -179,7 +217,9 @@ func launch(request Inbound, res http.ResponseWriter) {
|
|||
Ran: err == nil,
|
||||
Language: request.Language,
|
||||
Version: "",
|
||||
Output: strings.TrimSpace(stdout.String()),
|
||||
Output: combined,
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
}
|
||||
|
||||
// retrieve the language version
|
||||
|
|
|
@ -135,9 +135,9 @@ case "$lang" in
|
|||
esac
|
||||
|
||||
# runner
|
||||
timeout -s KILL 10 \
|
||||
timeout -s KILL 20 \
|
||||
lxc-attach --clear-env -n piston -- \
|
||||
/bin/bash -l -c "bash /exec/$bin $newinc $epoch 2>&1 | head -c 65536"
|
||||
/bin/bash -l -c "bash /exec/$bin $newinc $epoch"
|
||||
|
||||
# process janitor
|
||||
lxc-attach --clear-env -n piston -- \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
timeout -s KILL 10 gcc -std=c11 -o binary -x c code.code ; \
|
||||
gcc -std=c11 -o binary -x c code.code ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cd /tmp/$2
|
||||
timeout -s KILL 10 g++ -std=c++17 -o binary -x c++ code.code
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
g++ -std=c++17 -o binary -x c++ code.code ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cd /tmp/$2
|
||||
timeout -s KILL 10 mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary"
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
cd /tmp/$2
|
||||
|
||||
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
||||
runuser -l runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 emacs -Q --script code.code"
|
||||
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 emacs -Q --script code.code"
|
||||
else
|
||||
runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 emacs -Q --script code.code"
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 emacs -Q --script code.code"
|
||||
fi
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cd /tmp/$2
|
||||
cp code.code interim.go
|
||||
file="interim.go"
|
||||
timeout -s KILL 10 go build $file
|
||||
go build $file
|
||||
file=${file%%.*}
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file"
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
cd /tmp/$2
|
||||
mv code.code code.hs
|
||||
timeout -s KILL 10 ghc -dynamic -o binary code.hs > /dev/null 2>&1
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
ghc -dynamic -o binary code.hs > /dev/null 2>&1 ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
|
|
@ -2,5 +2,8 @@ cd /tmp/$2
|
|||
cp code.code interim.java
|
||||
name=$(grep -Po "(?<=\n|\A)\s*(public\s+)?(class|interface)\s+\K([^\n\s{]+)" interim.java)
|
||||
mv interim.java $name.java
|
||||
timeout -s KILL 10 javac $name.java
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 java $name"
|
||||
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
javac $name.java ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 java $name"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
cd /tmp/$2
|
||||
cp code.code code.kt
|
||||
timeout -s KILL 10 kotlinc code.kt -include-runtime -d code.jar
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 java -jar code.jar"
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
kotlinc code.kt -include-runtime -d code.jar ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 java -jar code.jar"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
cd /tmp/$2
|
||||
timeout -s KILL 10 nasm -f elf32 -o binary.o code.code
|
||||
timeout -s KILL 10 ld -m elf_i386 binary.o -o binary
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
nasm -f elf32 -o binary.o code.code ; \
|
||||
ld -m elf_i386 binary.o -o binary ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
cd /tmp/$2
|
||||
timeout -s KILL 10 nasm -f elf64 -o binary.o code.code
|
||||
timeout -s KILL 10 ld -m elf_x86_64 binary.o -o binary
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
nasm -f elf64 -o binary.o code.code ; \
|
||||
ld -m elf_x86_64 binary.o -o binary ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
cd /tmp/$2
|
||||
timeout -s KILL 10 rustc -o binary code.code
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
rustc -o binary code.code
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
cd /tmp/$2
|
||||
mv code.code interim.ts
|
||||
timeout -s KILL 10 tsc interim.ts
|
||||
rm interim.ts
|
||||
mv interim.js code.code
|
||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code"
|
||||
runuser runner$1 -c "\
|
||||
cd /tmp/$2 ; \
|
||||
mv code.code interim.ts ; \
|
||||
tsc interim.ts ; \
|
||||
rm -f interim.ts ; \
|
||||
mv interim.js code.code ; \
|
||||
cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code"
|
||||
|
|
|
@ -6,4 +6,4 @@ cp -f executors/* /var/lib/lxc/piston/rootfs/exec
|
|||
chmod 700 /var/lib/lxc/piston/rootfs/exec/*
|
||||
chown -R root:root /var/lib/lxc/piston/rootfs/exec
|
||||
|
||||
lxc-start -n piston -d
|
||||
#lxc-start -n piston -d
|
||||
|
|
|
@ -9,7 +9,7 @@ echo 'testing cpp'
|
|||
../execute cpp test.cpp
|
||||
echo 'testing cs'
|
||||
../execute cs test.cs
|
||||
echo 'testing deno ts'
|
||||
echo 'testing deno'
|
||||
../execute deno testdeno.ts
|
||||
echo 'testing elisp'
|
||||
../execute elisp test.el
|
||||
|
@ -21,6 +21,8 @@ echo 'testing haskell'
|
|||
../execute haskell test.hs
|
||||
echo 'testing java'
|
||||
../execute java test.java
|
||||
echo 'testing jelly'
|
||||
../execute jelly test.jelly
|
||||
echo 'testing jl'
|
||||
../execute jl test.jl
|
||||
echo 'testing js'
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
“3ḅaė;œ»
|
|
@ -157,7 +157,8 @@ cd /opt && mkdir jelly && cd jelly
|
|||
wget https://github.com/DennisMitchell/jellylanguage/archive/master.zip
|
||||
unzip master.zip
|
||||
cd jellylanguage-master
|
||||
pip3.8 install .
|
||||
python3.8 -m pip install .
|
||||
sed -i 's/\/usr\/local\/bin\/python3.8/\/opt\/python3\/Python-3.8.2\/python3.8/' /usr/local/bin/jelly
|
||||
|
||||
# install julia
|
||||
# final binary: /opt/julia/julia-1.5.0/bin/julia
|
||||
|
@ -202,6 +203,7 @@ source /opt/.profile
|
|||
cd /opt && mkdir emacs && cd emacs
|
||||
wget https://mirrors.ocf.berkeley.edu/gnu/emacs/emacs-26.3.tar.xz
|
||||
tar -xf emacs-26.3.tar.xz
|
||||
rm emacs-26.3.tar.xz
|
||||
cd emacs-26.3
|
||||
./configure --with-gnutls=no
|
||||
make
|
||||
|
|
Loading…
Reference in New Issue