Update for new API

This commit is contained in:
Vrganj 2021-01-23 21:31:23 +01:00
commit c10a30b69a
78 changed files with 2063 additions and 868 deletions

View file

@ -4,11 +4,7 @@ dir="$( cd "$( dirname "$0" )" && pwd )"
touch $dir/lockfile
if [ -z "$1" ]; then
echo "invalid args"
exit
fi
if [ -z "$2" ]; then
if [ -z "$1" ] || [ -z "$2" ]; then
echo "invalid args"
exit
fi
@ -18,13 +14,15 @@ epoch=$(date +%s%N)
basepath="/var/lib/lxc/piston/rootfs"
filepath="/tmp/$epoch/code.code"
argpath="/tmp/$epoch/args.args"
stdinpath="/tmp/$epoch/stdin.stdin"
arg=$(basename $argpath)
# write arg file
mkdir -p $basepath/tmp/$epoch
chmod 777 $basepath/tmp/$epoch
cat $2 > $basepath$filepath
echo "${@:3}" > $basepath$argpath
echo $3 > $basepath$stdinpath
echo -n "${@:4}" > $basepath$argpath
# process incrementor
exec 200>$dir/lockfile
@ -40,116 +38,24 @@ else
fi
exec 200>&-
bin=
case "$lang" in
"awk")
bin=awk
;;
"bash")
bin=bash
;;
"brainfuck" | "bf")
bin=brainfuck
;;
"c")
bin=c
;;
"cpp" | "c++")
bin=cpp
;;
"csharp" | "cs" | "c#")
bin=csharp
;;
"d")
bin=d
;;
"elixir" | "exs")
bin=elixir
;;
"go")
bin=go
;;
"haskell" | "hs")
bin=haskell
;;
"java")
bin=java
;;
"jelly")
bin=jelly
;;
"julia" | "jl")
bin=julia
;;
"kotlin")
bin=kotlin
;;
"lua")
bin=lua
;;
"nasm" | "asm")
bin=nasm
;;
"nasm64" | "asm64")
bin=nasm64
;;
"nim")
bin=nim
;;
"node" | "js" | "javascript")
bin=node
;;
"deno" | "denojs" | "denots")
bin=deno
;;
"paradoc")
bin=paradoc
;;
"perl")
bin=perl
;;
"php")
bin=php
;;
"python2")
bin=python2
;;
"python3" | "python")
bin=python3
;;
"ruby")
bin=ruby
;;
"rust")
bin=rust
;;
"swift")
bin=swift
;;
"emacs" | "elisp" | "el")
bin=emacs
;;
"bash")
bin=bash
;;
"typescript" | "ts")
bin=typescript
;;
*)
echo "invalid language"
exit
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 "runuser runner$newinc /exec/$lang $newinc $epoch"
# process janitor
lxc-attach --clear-env -n piston -- \
/bin/bash -l -c "\
for i in {1..100}; do pkill -u runner$newinc --signal SIGKILL; done ;\
find /tmp -user runner$newinc -exec /bin/rm -rf {} \;\
" > /dev/null 2>&1 &
/bin/bash -l -c "
for i in {1..100}
do
pkill -u runner$newinc --signal SIGKILL
done
find /tmp -user runner$newinc -delete
find /var/tmp -user runner$newinc -delete
find /var/lock -user runner$newinc -delete
find /dev/shm -user runner$newinc -delete
find /run/lock -user runner$newinc -delete
" > /dev/null 2>&1 &
rm -rf $basepath/tmp/$epoch

View file

@ -1,4 +1,4 @@
#!/bin/bash
cd /tmp/$2
timeout -s KILL 2 sed "/___code___/Q" code.code > code.stdin
timeout -s KILL 2 sed "1,/___code___/d" code.code > code.awk
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 awk -f code.awk < code.stdin"
timeout -s KILL 3 xargs -a args.args -d '\n' awk -f code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 bash code.code"
xargs -a args.args -d '\n' timeout -s KILL 3 bash code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 brainfuck code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' brainfuck code.code < stdin.stdin

View file

@ -1,3 +1,5 @@
#!/usr/bin/bash
cd /tmp/$2
timeout -s KILL 10 gcc -std=c11 -o binary -x c code.code
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
gcc -std=c11 -o binary -x c code.code
timeout -s KILL 3 xargs -a args.args ./binary < stdin.stdin

View file

@ -1,3 +1,5 @@
#!/bin/bash
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"
g++ -std=c++17 -o binary -x c++ code.code
timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin

View file

@ -1,3 +1,5 @@
#!/bin/bash
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"
mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary
timeout -s KILL 3 xargs -a args.args -d '\n' mono binary < stdin.stdin

View file

@ -1,4 +1,6 @@
#!/bin/bash
cd /tmp/$2
cp code.code code.d
timeout -s KILL 10 dmd code.d
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./code"
xtimeout -s KILL 3 args -a args.args -d '\n' ./code

View file

@ -1,7 +1,4 @@
cd /tmp/$2
#!/bin/bash
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 deno run code.code"
else
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 deno run code.code"
fi
cd /tmp/$2
timeout -s KILL 3 xargs -a args.args -d '\n' deno run code.code < stdin.stdin

View file

@ -1,7 +1,6 @@
cd /tmp/$2
#!/bin/bash
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 elixir code.code"
else
runuser runner$1 -c "cd /tmp/$2 ; cat args.args ; xargs -d '\n' timeout -s KILL 3 elixir code.code"
fi
export LC_ALL="en_US.UTF-8"
cd /tmp/$2
timeout -s KILL 3 xargs -a args.args -d '\n' elixir code.code < stdin.stdin

View file

@ -1,7 +1,4 @@
cd /tmp/$2
#!/bin/bash
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
runuser -l 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"
fi
cd /tmp/$2
timeout -s KILL 3 xargs -a args.args -d '\n' emacs -Q --script code.code < stdin.stdin

View file

@ -1,6 +1,6 @@
#!/bin/bash
cd /tmp/$2
cp code.code interim.go
file="interim.go"
timeout -s KILL 10 go build $file
file=${file%%.*}
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file"
go build interim.go
timeout -s KILL 3 xargs -a args.args -d '\n' ./interim < stdin.stdin

View file

@ -1,4 +1,6 @@
#!/bin/bash
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"
cp code.code code.hs
ghc -dynamic -o binary code.hs > /dev/null 2>&1
timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin

View file

@ -1,6 +1,7 @@
#!/bin/bash
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"
name=$(grep -Po "(?<=\n|\A)\s*(public\s+)?(class|interface)\s+\K([^\/\\\\\n\s{]+)" code.code)
cp code.code $name.java
javac $name.java
timeout -s KILL 3 xargs -a args.args -d '\n' java $name < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 jelly fu code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' jelly fu code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 julia code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' julia code.code < stdin.stdin

View file

@ -1,4 +1,6 @@
#!/bin/bash
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"
kotlinc code.kt -include-runtime -d code.jar
timeout -s KILL 3 xargs -a args.args -d '\n' java -jar code.jar < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 lua code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' lua code.code < stdin.stdin

View file

@ -1,4 +1,6 @@
#!/bin/bash
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"
nasm -f elf32 -o binary.o code.code
ld -m elf_i386 binary.o -o binary
timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin

View file

@ -1,4 +1,6 @@
#!/bin/bash
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"
nasm -f elf64 -o binary.o code.code
ld -m elf_x86_64 binary.o -o binary
timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin

View file

@ -1,4 +0,0 @@
cd /tmp/$2
timeout -s KILL 10 nim --hints:off c code.code
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./code"

View file

@ -1,7 +1,4 @@
cd /tmp/$2
#!/bin/bash
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 node code.code"
else
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code"
fi
cd /tmp/$2
timeout -s KILL 3 xargs -a args.args -d '\n' node code.code < stdin.stdin

View file

@ -1,2 +1,5 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 python3 -m paradoc code.code <<< args.args"
export PYTHONPATH=$PYTHONPATH:/opt/paradoc
timeout -s KILL 3 python3.8 -m paradoc code.code < args.args

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 perl code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' perl code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' php code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' python code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.8 code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' python3.8 code.code < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' ruby code.code < stdin.stdin

View file

@ -1,3 +1,5 @@
#!/bin/bash
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
timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin

View file

@ -1,2 +1,4 @@
#!/bin/bash
cd /tmp/$2
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 swift code.code"
timeout -s KILL 3 xargs -a args.args -d '\n' swift code.code < stdin.stdin

View file

@ -1,6 +1,8 @@
#!/bin/bash
cd /tmp/$2
mv code.code interim.ts
timeout -s KILL 10 tsc interim.ts
rm interim.ts
tsc interim.ts
rm -f 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"
timeout -s KILL 3 xargs -a args.args -d '\n' node code.code < stdin.stdin

View file

@ -3,7 +3,7 @@
mkdir -p /var/lib/lxc/piston/rootfs/exec
rm -f /var/lib/lxc/piston/rootfs/exec/*
cp -f executors/* /var/lib/lxc/piston/rootfs/exec
chmod 700 /var/lib/lxc/piston/rootfs/exec/*
chmod 555 /var/lib/lxc/piston/rootfs/exec/*
chown -R root:root /var/lib/lxc/piston/rootfs/exec
lxc-start -n piston -d

View file

@ -1,57 +1,57 @@
#!/usr/bin/env bash
cd tests
echo 'testing awk'
../execute awk test.awk
echo 'testing c'
../execute c test.c
echo 'testing cpp'
../execute cpp test.cpp
echo 'testing cs'
../execute cs test.cs
echo 'testing d'
../execute d test.d
echo 'testing deno ts'
../execute deno testdeno.ts
echo 'testing elisp'
../execute elisp test.el
echo 'testing elixir'
../execute exs test.exs
echo 'testing go'
../execute go test.go
echo 'testing haskell'
../execute haskell test.hs
echo 'testing java'
../execute java test.java
echo 'testing jl'
../execute jl test.jl
echo 'testing js'
../execute js test.js
echo 'testing kotlin'
../execute kotlin test.kt
echo 'testing asm 32 bit'
../execute asm test.nasm
echo 'testing asm 64 bit'
../execute asm64 test64.nasm
echo 'testing nim'
../execute nim test.nim
echo 'testing php'
../execute php test.php
echo 'testing perl'
../execute perl test.pl
echo 'testing ruby'
../execute ruby test.rb
echo 'testing rust'
../execute rust test.rs
echo 'testing bash'
../execute bash test.sh
echo 'testing swift'
../execute swift test.swift
echo 'testing typescript'
../execute typescript test.ts
echo 'testing python2'
../execute python2 test2.py
echo 'testing python3'
../execute python3 test3.py
echo 'testing paradoc'
../execute python3 test_paradoc.py
echo -n 'testing awk = '
../../cli/execute awk awk.awk
echo -n 'testing bash = '
../../cli/execute bash bash.sh
echo -n 'testing c = '
../../cli/execute c c.c
echo -n 'testing cpp = '
../../cli/execute cpp cpp.cpp
echo -n 'testing csharp = '
../../cli/execute csharp csharp.cs
echo -n 'testing d = '
../../cli/execute d test.d
echo -n 'testing deno = '
../../cli/execute deno deno.ts
echo -n 'testing elixir = '
../../cli/execute elixir elixir.exs
echo -n 'testing emacs = '
../../cli/execute emacs emacs.el
echo -n 'testing go = '
../../cli/execute go go.go
echo -n 'testing haskell = '
../../cli/execute haskell haskell.hs
echo -n 'testing java = '
../../cli/execute java java.java
echo -n 'testing jelly = '
../../cli/execute jelly jelly.jelly good
echo -n 'testing julia = '
../../cli/execute julia julia.jl
echo -n 'testing kotlin = '
../../cli/execute kotlin kotlin.kt
echo -n 'testing nasm 32 bit = '
../../cli/execute nasm nasm.nasm
echo -n 'testing nasm 64 bit = '
../../cli/execute nasm64 nasm64.nasm
echo -n 'testing node = '
../../cli/execute node node.js
echo -n 'testing paradoc = '
../../cli/execute bash paradoc.sh
echo -n 'testing perl = '
../../cli/execute perl perl.pl
echo -n 'testing php = '
../../cli/execute php php.php
echo -n 'testing python2 = '
../../cli/execute python2 python2.py
echo -n 'testing python3 = '
../../cli/execute python3 python3.py
echo -n 'testing ruby = '
../../cli/execute ruby ruby.rb
echo -n 'testing rust = '
../../cli/execute rust rust.rs
echo -n 'testing swift = '
../../cli/execute swift swift.swift
echo -n 'testing typescript = '
../../cli/execute typescript typescript.ts

1
lxc/tests/awk.awk Normal file
View file

@ -0,0 +1 @@
{ print "good" }

1
lxc/tests/jelly.jelly Normal file
View file

@ -0,0 +1 @@
³

3
lxc/tests/kotlin.kt Normal file
View file

@ -0,0 +1,3 @@
fun main() {
println("good")
}

18
lxc/tests/nasm64.nasm Normal file
View file

@ -0,0 +1,18 @@
SECTION .data
good: db "good", 0x0
txtlen: equ $ - good
SECTION .text
GLOBAL _start
_start:
;sys_write
mov rax, 1
mov rdi, 1
mov rsi, good
mov rdx, txtlen
syscall
;sys_exit
mov rax, 60
mov rdi, 0
syscall

11
lxc/tests/paradoc.sh Normal file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# add paradoc module to python python
export PYTHONPATH=$PYTHONPATH:/opt/paradoc
# file for test code
test_code=/tmp/paradoc.test
# save test code to file
echo -n iP>$test_code
# pass param to paradoc module and have it print it
echo good | python3.8 -m paradoc $test_code
# clean test code
rm -f $test_code

View file

@ -1,3 +0,0 @@
good
___code___
{ print }

View file

@ -1,3 +0,0 @@
fun main(args: Array<String>) {
println("good")
}

View file

@ -1,18 +0,0 @@
SECTION .data
good: db "good", 0x0a, 0x0
txtlen: equ $ - good
SECTION .text
GLOBAL _start
_start:
;sys_write
mov rax, 1
mov rdi, 1
mov rsi, good
mov rdx, txtlen
syscall
;sys_exit
mov rax, 60
mov rdi, 0
syscall

View file

@ -1,5 +0,0 @@
try:
import paradoc
print('good')
except:
pass

View file

@ -14,11 +14,11 @@ echo '1.0.0'
echo '---'
echo 'c'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "gcc -v"
lxc-attach --clear-env -n piston -- /bin/bash -l -c "gcc --version"
echo '---'
echo 'cpp'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "g++ -v"
lxc-attach --clear-env -n piston -- /bin/bash -l -c "g++ --version"
echo '---'
echo 'csharp'
@ -73,8 +73,8 @@ echo 'nasm'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "nasm -version"
echo '---'
echo 'nim'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "nim -v | head -n1"
echo 'nasm64'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "nasm -version"
echo '---'
echo 'node'
@ -94,11 +94,11 @@ lxc-attach --clear-env -n piston -- /bin/bash -l -c "python -V"
echo '---'
echo 'python3'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "python3 -V"
lxc-attach --clear-env -n piston -- /bin/bash -l -c "python3.8 -V"
echo '---'
echo 'paradoc'
lxc-attach --clear-env -n piston -- /bin/bash -l -c "python3 -m paradoc --version"
lxc-attach --clear-env -n piston -- /bin/bash -l -c "python3.8 -m paradoc --version"
echo '---'
echo 'ruby'