From 008d55643b31b2cf516495ba87babd901e290e89 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 00:54:57 +0000 Subject: [PATCH] Fix stdin for most languages --- lxc/executors/bash | 8 ++++++-- lxc/executors/brainfuck | 8 ++++++-- lxc/executors/c | 11 +++++++---- lxc/executors/cpp | 11 +++++++---- lxc/executors/csharp | 11 +++++++---- lxc/executors/deno | 11 +++++------ lxc/executors/elixir | 11 +++++------ lxc/executors/emacs | 11 +++++------ lxc/executors/go | 14 ++++++++------ lxc/executors/haskell | 11 ++++++----- lxc/executors/java | 18 ++++++++++-------- lxc/executors/jelly | 8 ++++++-- lxc/executors/julia | 8 ++++++-- lxc/executors/kotlin | 14 ++++++++------ lxc/executors/lua | 8 ++++++-- lxc/executors/nasm | 13 ++++++++----- lxc/executors/nasm64 | 13 ++++++++----- lxc/executors/node | 11 +++++------ lxc/executors/perl | 8 ++++++-- lxc/executors/php | 8 ++++++-- lxc/executors/python2 | 8 ++++++-- lxc/executors/python3 | 8 ++++++-- lxc/executors/ruby | 8 ++++++-- lxc/executors/rust | 10 +++++++--- lxc/executors/swift | 8 ++++++-- lxc/executors/typescript | 17 ++++++++++------- 26 files changed, 172 insertions(+), 103 deletions(-) diff --git a/lxc/executors/bash b/lxc/executors/bash index 410e383..04ebb1c 100755 --- a/lxc/executors/bash +++ b/lxc/executors/bash @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 bash code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + xargs -a args.args -d '\n' timeout -s KILL 3 bash code.code < stdin.stdin +" diff --git a/lxc/executors/brainfuck b/lxc/executors/brainfuck index 94fc7d9..0503bcf 100755 --- a/lxc/executors/brainfuck +++ b/lxc/executors/brainfuck @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 brainfuck code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' brainfuck code.code < stdin.stdin +" diff --git a/lxc/executors/c b/lxc/executors/c index 79ba5b0..8d60422 100755 --- a/lxc/executors/c +++ b/lxc/executors/c @@ -1,4 +1,7 @@ -runuser runner$1 -c "\ - cd /tmp/$2 ; \ - gcc -std=c11 -o binary -x c code.code ; \ - cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" +#!/usr/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + gcc -std=c11 -o binary -x c code.code + timeout -s KILL 3 xargs -a args.args ./binary < stdin.stdin +" diff --git a/lxc/executors/cpp b/lxc/executors/cpp index cfb02dd..8602962 100755 --- a/lxc/executors/cpp +++ b/lxc/executors/cpp @@ -1,4 +1,7 @@ -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 < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + g++ -std=c++17 -o binary -x c++ code.code + timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin +" diff --git a/lxc/executors/csharp b/lxc/executors/csharp index f2ee2ea..4946e27 100755 --- a/lxc/executors/csharp +++ b/lxc/executors/csharp @@ -1,4 +1,7 @@ -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 < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary + timeout -s KILL 3 xargs -a args.args -d '\n' mono binary < stdin.stdin +" diff --git a/lxc/executors/deno b/lxc/executors/deno index 1a92dc8..a18c647 100755 --- a/lxc/executors/deno +++ b/lxc/executors/deno @@ -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 deno run code.code < stdin.stdin" -else - runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 deno run code.code < stdin.stdin" -fi +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' deno run code.code < stdin.stdin +" diff --git a/lxc/executors/elixir b/lxc/executors/elixir index 664501f..0343cf1 100755 --- a/lxc/executors/elixir +++ b/lxc/executors/elixir @@ -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 < stdin.stdin" -fi +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' elixir code.code < stdin.stdin +" diff --git a/lxc/executors/emacs b/lxc/executors/emacs index 6fb0553..3a64ecc 100755 --- a/lxc/executors/emacs +++ b/lxc/executors/emacs @@ -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 emacs -Q --script code.code" -else - runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 emacs -Q --script code.code < stdin.stdin" -fi +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' emacs -Q --script code.code < stdin.stdin +" diff --git a/lxc/executors/go b/lxc/executors/go index b713027..a9aa4fd 100755 --- a/lxc/executors/go +++ b/lxc/executors/go @@ -1,6 +1,8 @@ -cd /tmp/$2 -cp code.code interim.go -file="interim.go" -go build $file -file=${file%%.*} -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + cp code.code interim.go + go build interim.go + timeout -s KILL 3 xargs -a args.args -d '\n' ./interim < stdin.stdin +" diff --git a/lxc/executors/haskell b/lxc/executors/haskell index becc27f..bc13034 100755 --- a/lxc/executors/haskell +++ b/lxc/executors/haskell @@ -1,7 +1,8 @@ -cd /tmp/$2 -mv code.code code.hs +#!/bin/bash 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 < stdin.stdin" + cd /tmp/$2 + 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 +" diff --git a/lxc/executors/java b/lxc/executors/java index 7f84d81..12ac347 100755 --- a/lxc/executors/java +++ b/lxc/executors/java @@ -1,9 +1,11 @@ -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 +#!/bin/bash -runuser runner$1 -c "\ - cd /tmp/$2 ; \ - javac $name.java ; \ - cat args.args | xargs -d '\n' timeout -s KILL 3 java $name < stdin.stdin" +cd /tmp/$2 +name=$(grep -Po "(?<=\n|\A)\s*(public\s+)?(class|interface)\s+\K([^\/\\\n\s{]+)" code.code) + +runuser runner$1 -c " + cd /tmp/$2 + cp code.code $name.java + javac $name.java + timeout -s KILL 3 xargs -a args.args -d '\n' java $name < stdin.stdin +" diff --git a/lxc/executors/jelly b/lxc/executors/jelly index 32b79d9..0c1b343 100755 --- a/lxc/executors/jelly +++ b/lxc/executors/jelly @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 jelly fu code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' jelly fu code.code < stdin.stdin +" diff --git a/lxc/executors/julia b/lxc/executors/julia index 3eeb323..4350335 100755 --- a/lxc/executors/julia +++ b/lxc/executors/julia @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 julia code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' julia code.code < stdin.stdin +" diff --git a/lxc/executors/kotlin b/lxc/executors/kotlin index 6c034e6..efd00e0 100755 --- a/lxc/executors/kotlin +++ b/lxc/executors/kotlin @@ -1,6 +1,8 @@ -cd /tmp/$2 -cp code.code code.kt -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 < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + cp code.code code.kt + kotlinc code.kt -include-runtime -d code.jar + timeout -s KILL 3 xargs -a args.args -d '\n' java -jar code.jar < stdin.stdin +" diff --git a/lxc/executors/lua b/lxc/executors/lua index a5ab76f..c318a87 100755 --- a/lxc/executors/lua +++ b/lxc/executors/lua @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 lua code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' lua code.code < stdin.stdin +" diff --git a/lxc/executors/nasm b/lxc/executors/nasm index 45e1d1c..f48e5bc 100755 --- a/lxc/executors/nasm +++ b/lxc/executors/nasm @@ -1,5 +1,8 @@ -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 < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + 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 +" diff --git a/lxc/executors/nasm64 b/lxc/executors/nasm64 index d498a54..23ad450 100755 --- a/lxc/executors/nasm64 +++ b/lxc/executors/nasm64 @@ -1,5 +1,8 @@ -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 < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + 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 +" diff --git a/lxc/executors/node b/lxc/executors/node index 04113d2..b43fff0 100755 --- a/lxc/executors/node +++ b/lxc/executors/node @@ -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 node code.code < stdin.stdin" -else - runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code < stdin.stdin" -fi +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' node code.code < stdin.stdin +" diff --git a/lxc/executors/perl b/lxc/executors/perl index 9951e18..8657564 100755 --- a/lxc/executors/perl +++ b/lxc/executors/perl @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 perl code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' perl code.code < stdin.stdin +" diff --git a/lxc/executors/php b/lxc/executors/php index 470f494..2acacb9 100755 --- a/lxc/executors/php +++ b/lxc/executors/php @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' php code.code < stdin.stdin +" diff --git a/lxc/executors/python2 b/lxc/executors/python2 index 15b65de..ab90f29 100755 --- a/lxc/executors/python2 +++ b/lxc/executors/python2 @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' python code.code < stdin.stdin +" diff --git a/lxc/executors/python3 b/lxc/executors/python3 index a2bc47f..a944242 100755 --- a/lxc/executors/python3 +++ b/lxc/executors/python3 @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.8 code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' python3.8 code.code < stdin.stdin +" diff --git a/lxc/executors/ruby b/lxc/executors/ruby index 5c5b181..9407d75 100755 --- a/lxc/executors/ruby +++ b/lxc/executors/ruby @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' ruby code.code < stdin.stdin +" diff --git a/lxc/executors/rust b/lxc/executors/rust index ad7d8e2..2a70609 100755 --- a/lxc/executors/rust +++ b/lxc/executors/rust @@ -1,5 +1,9 @@ +#!/bin/bash + cd /tmp/$2 rustc -o binary code.code -runuser runner$1 -c "\ - cd /tmp/$2 ; \ - cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin +" diff --git a/lxc/executors/swift b/lxc/executors/swift index fd8eb9f..6e0565d 100755 --- a/lxc/executors/swift +++ b/lxc/executors/swift @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 swift code.code < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 xargs -a args.args -d '\n' swift code.code < stdin.stdin +" diff --git a/lxc/executors/typescript b/lxc/executors/typescript index 26adfba..20a382f 100755 --- a/lxc/executors/typescript +++ b/lxc/executors/typescript @@ -1,7 +1,10 @@ -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 < stdin.stdin" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + mv code.code interim.ts + tsc interim.ts + rm -f interim.ts + mv interim.js code.code + xargs -a args.args -d '\n' timeout -s KILL 3 node code.code < stdin.stdin +"