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"`
|
Language string `json:"language"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Output string `json:"output"`
|
Output string `json:"output"`
|
||||||
|
Stdout string `json:"stdout"`
|
||||||
|
Stderr string `json:"stderr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Language struct {
|
type Language struct {
|
||||||
|
@ -124,6 +126,18 @@ func Versions(res http.ResponseWriter, req *http.Request) {
|
||||||
res.Write(data)
|
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) {
|
func launch(request Inbound, res http.ResponseWriter) {
|
||||||
stamp := time.Now().UnixNano()
|
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"))
|
cmd := exec.Command("../lxc/execute", request.Language, srcfile, strings.Join(request.Args, "\n"))
|
||||||
|
|
||||||
// capture out/err
|
// capture out/err
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr, combined string
|
||||||
cmd.Stdout = &stdout
|
|
||||||
cmd.Stderr = &stderr
|
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()
|
err := cmd.Run()
|
||||||
|
|
||||||
|
@ -179,7 +217,9 @@ func launch(request Inbound, res http.ResponseWriter) {
|
||||||
Ran: err == nil,
|
Ran: err == nil,
|
||||||
Language: request.Language,
|
Language: request.Language,
|
||||||
Version: "",
|
Version: "",
|
||||||
Output: strings.TrimSpace(stdout.String()),
|
Output: combined,
|
||||||
|
Stdout: stdout,
|
||||||
|
Stderr: stderr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve the language version
|
// retrieve the language version
|
||||||
|
|
|
@ -135,9 +135,9 @@ case "$lang" in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# runner
|
# runner
|
||||||
timeout -s KILL 10 \
|
timeout -s KILL 20 \
|
||||||
lxc-attach --clear-env -n piston -- \
|
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
|
# process janitor
|
||||||
lxc-attach --clear-env -n piston -- \
|
lxc-attach --clear-env -n piston -- \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
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"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
cd /tmp/$2
|
runuser runner$1 -c "\
|
||||||
timeout -s KILL 10 g++ -std=c++17 -o binary -x c++ code.code
|
cd /tmp/$2 ; \
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
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
|
runuser runner$1 -c "\
|
||||||
timeout -s KILL 10 mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary
|
cd /tmp/$2 ; \
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary"
|
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
|
cd /tmp/$2
|
||||||
|
|
||||||
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
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
|
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
|
fi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
cp code.code interim.go
|
cp code.code interim.go
|
||||||
file="interim.go"
|
file="interim.go"
|
||||||
timeout -s KILL 10 go build $file
|
go build $file
|
||||||
file=${file%%.*}
|
file=${file%%.*}
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$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
|
cd /tmp/$2
|
||||||
mv code.code code.hs
|
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
|
cp code.code interim.java
|
||||||
name=$(grep -Po "(?<=\n|\A)\s*(public\s+)?(class|interface)\s+\K([^\n\s{]+)" interim.java)
|
name=$(grep -Po "(?<=\n|\A)\s*(public\s+)?(class|interface)\s+\K([^\n\s{]+)" interim.java)
|
||||||
mv interim.java $name.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
|
cd /tmp/$2
|
||||||
cp code.code code.kt
|
cp code.code code.kt
|
||||||
timeout -s KILL 10 kotlinc code.kt -include-runtime -d code.jar
|
runuser runner$1 -c "\
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 java -jar code.jar"
|
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
|
runuser runner$1 -c "\
|
||||||
timeout -s KILL 10 nasm -f elf32 -o binary.o code.code
|
cd /tmp/$2 ; \
|
||||||
timeout -s KILL 10 ld -m elf_i386 binary.o -o binary
|
nasm -f elf32 -o binary.o code.code ; \
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
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
|
runuser runner$1 -c "\
|
||||||
timeout -s KILL 10 nasm -f elf64 -o binary.o code.code
|
cd /tmp/$2 ; \
|
||||||
timeout -s KILL 10 ld -m elf_x86_64 binary.o -o binary
|
nasm -f elf64 -o binary.o code.code ; \
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
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
|
cd /tmp/$2
|
||||||
timeout -s KILL 10 rustc -o binary code.code
|
rustc -o binary 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 ; \
|
||||||
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
cd /tmp/$2
|
runuser runner$1 -c "\
|
||||||
mv code.code interim.ts
|
cd /tmp/$2 ; \
|
||||||
timeout -s KILL 10 tsc interim.ts
|
mv code.code interim.ts ; \
|
||||||
rm interim.ts
|
tsc interim.ts ; \
|
||||||
mv interim.js code.code
|
rm -f interim.ts ; \
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code"
|
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/*
|
chmod 700 /var/lib/lxc/piston/rootfs/exec/*
|
||||||
chown -R root:root /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
|
../execute cpp test.cpp
|
||||||
echo 'testing cs'
|
echo 'testing cs'
|
||||||
../execute cs test.cs
|
../execute cs test.cs
|
||||||
echo 'testing deno ts'
|
echo 'testing deno'
|
||||||
../execute deno testdeno.ts
|
../execute deno testdeno.ts
|
||||||
echo 'testing elisp'
|
echo 'testing elisp'
|
||||||
../execute elisp test.el
|
../execute elisp test.el
|
||||||
|
@ -21,6 +21,8 @@ echo 'testing haskell'
|
||||||
../execute haskell test.hs
|
../execute haskell test.hs
|
||||||
echo 'testing java'
|
echo 'testing java'
|
||||||
../execute java test.java
|
../execute java test.java
|
||||||
|
echo 'testing jelly'
|
||||||
|
../execute jelly test.jelly
|
||||||
echo 'testing jl'
|
echo 'testing jl'
|
||||||
../execute jl test.jl
|
../execute jl test.jl
|
||||||
echo 'testing js'
|
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
|
wget https://github.com/DennisMitchell/jellylanguage/archive/master.zip
|
||||||
unzip master.zip
|
unzip master.zip
|
||||||
cd jellylanguage-master
|
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
|
# install julia
|
||||||
# final binary: /opt/julia/julia-1.5.0/bin/julia
|
# final binary: /opt/julia/julia-1.5.0/bin/julia
|
||||||
|
@ -202,6 +203,7 @@ source /opt/.profile
|
||||||
cd /opt && mkdir emacs && cd emacs
|
cd /opt && mkdir emacs && cd emacs
|
||||||
wget https://mirrors.ocf.berkeley.edu/gnu/emacs/emacs-26.3.tar.xz
|
wget https://mirrors.ocf.berkeley.edu/gnu/emacs/emacs-26.3.tar.xz
|
||||||
tar -xf emacs-26.3.tar.xz
|
tar -xf emacs-26.3.tar.xz
|
||||||
|
rm emacs-26.3.tar.xz
|
||||||
cd emacs-26.3
|
cd emacs-26.3
|
||||||
./configure --with-gnutls=no
|
./configure --with-gnutls=no
|
||||||
make
|
make
|
||||||
|
|
Loading…
Reference in New Issue