From d8b6379b9a4c4a4c40269da362e7349136528fcb Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 13:14:17 +0100 Subject: [PATCH 01/16] Add CLI written in Node --- api/src/execute.js | 48 ----------- api/src/index.js | 15 +++- api/src/languages.js | 116 +------------------------ cli/execute | 3 + cli/package.json | 12 +++ cli/src/index.js | 30 +++++++ lxc/test_all_lxc | 52 +++++------ shared/execute.js | 43 ++++++++++ shared/languages.json | 194 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 321 insertions(+), 192 deletions(-) delete mode 100644 api/src/execute.js create mode 100755 cli/execute create mode 100644 cli/package.json create mode 100644 cli/src/index.js create mode 100644 shared/execute.js create mode 100644 shared/languages.json diff --git a/api/src/execute.js b/api/src/execute.js deleted file mode 100644 index 1409a7b..0000000 --- a/api/src/execute.js +++ /dev/null @@ -1,48 +0,0 @@ -const { writeFile } = require('fs/promises'); -const { spawn } = require('child_process'); - -async function execute(res, language, body) { - const stamp = new Date().getTime(); - const sourceFile = `/tmp/${stamp}.code`; - - await writeFile(sourceFile, body.source); - - const process = spawn(__dirname + '/../../lxc/execute', [ - language.name, - sourceFile, - body.args?.join('\n') ?? '', - ]); - - const result = { - ran: true, - language: language.name, - stderr: '', - stdout: '', - output: '', - }; - - if (language.version) - result.version = language.version; - - process.stderr.on('data', chunk => { - result.stderr += chunk; - result.output += chunk; - }); - - process.stdout.on('data', chunk => { - result.stdout += chunk; - result.output += chunk; - }); - - process.on('exit', () => { - result.stderr = result.stderr.trim().substring(0, 65535); - result.stdout = result.stdout.trim().substring(0, 65535); - result.output = result.output.trim().substring(0, 65535); - - res.json(result); - }); -} - -module.exports = { - execute, -}; diff --git a/api/src/index.js b/api/src/index.js index c29a461..cd658c5 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -1,5 +1,5 @@ const express = require('express'); -const { execute } = require('./execute'); +const { execute } = require('../../shared/execute'); const { languages } = require('./languages'); const { checkSchema, validationResult } = require('express-validator'); @@ -41,7 +41,7 @@ app.post( }, } }), - (req, res) => { + async (req, res) => { const errors = validationResult(req).array(); if (errors.length === 0) { @@ -49,7 +49,16 @@ app.post( language.aliases.includes(req.body.language.toLowerCase()) ); - execute(res, language, req.body); + const { stdout, stderr, output } = await execute(language, req.body.source, req.body.args); + + res.status(200).json({ + ran: true, + language: language.name, + version: language.version, + stdout, + stderr, + output, + }); } else { res.status(400).json({ message: errors[0].msg, diff --git a/api/src/languages.js b/api/src/languages.js index 9fda547..23e352a 100644 --- a/api/src/languages.js +++ b/api/src/languages.js @@ -1,119 +1,5 @@ const { spawn } = require('child_process'); - -const languages = [ - { - name: 'nasm', - aliases: ['asm', 'nasm'], - }, - { - name: 'nasm64', - aliases: ['asm64', 'nasm64'], - }, - { - name: 'awk', - aliases: ['awk'], - }, - { - name: 'bash', - aliases: ['bash'], - }, - { - name: 'brainfuck', - aliases: ['bf', 'brainfuck'], - }, - { - name: 'c', - aliases: ['c'], - }, - { - name: 'csharp', - aliases: ['c#', 'cs', 'csharp'], - }, - { - name: 'cpp', - aliases: ['c++', 'cpp'], - }, - { - name: 'deno', - aliases: ['deno', 'denojs', 'denots'], - }, - { - name: 'ruby', - aliases: ['duby', 'rb', 'ruby'], - }, - { - name: 'emacs', - aliases: ['el', 'elisp', 'emacs'], - }, - { - name: 'elixir', - aliases: ['elixir'], - }, - { - name: 'haskell', - aliases: ['haskell', 'hs'], - }, - { - name: 'go', - aliases: ['go'], - }, - { - name: 'java', - aliases: ['java'], - }, - { - name: 'node', - aliases: ['javascript', 'js', 'node'], - }, - { - name: 'jelly', - aliases: ['jelly'], - }, - { - name: 'julia', - aliases: ['jl', 'julia'], - }, - { - name: 'kotlin', - aliases: ['kotlin'], - }, - { - name: 'lua', - aliases: ['lua'], - }, - { - name: 'paradoc', - aliases: ['paradoc'], - }, - { - name: 'perl', - aliases: ['perl'], - }, - { - name: 'php', - aliases: ['php', 'php3', 'php4', 'php5'], - }, - { - name: 'python3', - aliases: ['py', 'py3', 'python', 'python3'], - }, - { - name: 'python2', - aliases: ['python2'], - }, - { - name: 'rust', - aliases: ['rs', 'rust'], - }, - { - name: 'swift', - aliases: ['swift'], - }, - { - name: 'typescript', - aliases: ['ts', 'typescript'], - }, -]; +const languages = require('../../shared/languages.json'); { const process = spawn(__dirname + '/../../lxc/versions'); diff --git a/cli/execute b/cli/execute new file mode 100755 index 0000000..37a6b35 --- /dev/null +++ b/cli/execute @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +node src $* diff --git a/cli/package.json b/cli/package.json new file mode 100644 index 0000000..0166712 --- /dev/null +++ b/cli/package.json @@ -0,0 +1,12 @@ +{ + "name": "cli", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/cli/src/index.js b/cli/src/index.js new file mode 100644 index 0000000..c53d132 --- /dev/null +++ b/cli/src/index.js @@ -0,0 +1,30 @@ +const { execute } = require('../../shared/execute'); +const { readFileSync } = require('fs'); +const languages = require('../../shared/languages.json'); + +const [languageName, sourceFile, ...args] = process.argv.slice(2); + +(async () => { + if (!languageName) { + console.error('Provide a language name'); + return; + } + + if (!sourceFile) { + console.error('Provide a source file'); + return; + } + + const source = readFileSync(sourceFile); + + const language = languages.find(language => language.name === languageName); + + if (!language) { + console.error(`${languageName} is not supported by Piston`); + return; + } + + const { output } = await execute(language, source, args); + + console.log(output); +})(); diff --git a/lxc/test_all_lxc b/lxc/test_all_lxc index 873c840..493c4b5 100755 --- a/lxc/test_all_lxc +++ b/lxc/test_all_lxc @@ -2,54 +2,54 @@ cd tests echo 'testing awk' -../execute awk test.awk +../../cli/execute awk test.awk echo 'testing c' -../execute c test.c +../../cli/execute c test.c echo 'testing cpp' -../execute cpp test.cpp +../../cli/execute cpp test.cpp echo 'testing cs' -../execute cs test.cs +../../cli/execute cs test.cs echo 'testing deno' -../execute deno testdeno.ts +../../cli/execute deno testdeno.ts echo 'testing elisp' -../execute elisp test.el +../../cli/execute elisp test.el echo 'testing elixir' -../execute exs test.exs +../../cli/execute exs test.exs echo 'testing go' -../execute go test.go +../../cli/execute go test.go echo 'testing haskell' -../execute haskell test.hs +../../cli/execute haskell test.hs echo 'testing java' -../execute java test.java +../../cli/execute java test.java echo 'testing jelly' -../execute jelly test.jelly +../../cli/execute jelly test.jelly echo 'testing jl' -../execute jl test.jl +../../cli/execute jl test.jl echo 'testing js' -../execute js test.js +../../cli/execute js test.js echo 'testing kotlin' -../execute kotlin test.kt +../../cli/execute kotlin test.kt echo 'testing asm 32 bit' -../execute asm test.nasm +../../cli/execute asm test.nasm echo 'testing asm 64 bit' -../execute asm64 test64.nasm +../../cli/execute asm64 test64.nasm echo 'testing php' -../execute php test.php +../../cli/execute php test.php echo 'testing perl' -../execute perl test.pl +../../cli/execute perl test.pl echo 'testing ruby' -../execute ruby test.rb +../../cli/execute ruby test.rb echo 'testing rust' -../execute rust test.rs +../../cli/execute rust test.rs echo 'testing bash' -../execute bash test.sh +../../cli/execute bash test.sh echo 'testing swift' -../execute swift test.swift +../../cli/execute swift test.swift echo 'testing typescript' -../execute typescript test.ts +../../cli/execute typescript test.ts echo 'testing python2' -../execute python2 test2.py +../../cli/execute python2 test2.py echo 'testing python3' -../execute python3 test3.py +../../cli/execute python3 test3.py echo 'testing paradoc' -../execute python3 test_paradoc.py +../../cli/execute python3 test_paradoc.py diff --git a/shared/execute.js b/shared/execute.js new file mode 100644 index 0000000..22c6dad --- /dev/null +++ b/shared/execute.js @@ -0,0 +1,43 @@ +const { writeFile } = require('fs/promises'); +const { spawn } = require('child_process'); + +function execute(language, source, args) { + return new Promise(async resolve => { + const stamp = new Date().getTime(); + const sourceFile = `/tmp/${stamp}.code`; + + await writeFile(sourceFile, source); + + const process = spawn(__dirname + '/../lxc/execute', [ + language.name, + sourceFile, + args?.join('\n') ?? '', + ]); + + let stdout = ''; + let stderr = ''; + let output = ''; + + process.stderr.on('data', chunk => { + stderr += chunk; + output += chunk; + }); + + process.stdout.on('data', chunk => { + stdout += chunk; + output += chunk; + }); + + process.on('exit', () => { + stderr = stderr.trim().substring(0, 65535); + stdout = stdout.trim().substring(0, 65535); + output = output.trim().substring(0, 65535); + + resolve({ stdout, stderr, output }); + }); + }); +} + +module.exports = { + execute, +}; diff --git a/shared/languages.json b/shared/languages.json new file mode 100644 index 0000000..ba04153 --- /dev/null +++ b/shared/languages.json @@ -0,0 +1,194 @@ +[ + { + "name": "nasm", + "aliases": [ + "asm", + "nasm" + ] + }, + { + "name": "nasm64", + "aliases": [ + "asm64", + "nasm64" + ] + }, + { + "name": "awk", + "aliases": [ + "awk" + ] + }, + { + "name": "bash", + "aliases": [ + "bash" + ] + }, + { + "name": "brainfuck", + "aliases": [ + "bf", + "brainfuck" + ] + }, + { + "name": "c", + "aliases": [ + "c" + ] + }, + { + "name": "csharp", + "aliases": [ + "c#", + "cs", + "csharp" + ] + }, + { + "name": "cpp", + "aliases": [ + "c++", + "cpp" + ] + }, + { + "name": "deno", + "aliases": [ + "deno", + "denojs", + "denots" + ] + }, + { + "name": "ruby", + "aliases": [ + "duby", + "rb", + "ruby" + ] + }, + { + "name": "emacs", + "aliases": [ + "el", + "elisp", + "emacs" + ] + }, + { + "name": "elixir", + "aliases": [ + "elixir" + ] + }, + { + "name": "haskell", + "aliases": [ + "haskell", + "hs" + ] + }, + { + "name": "go", + "aliases": [ + "go" + ] + }, + { + "name": "java", + "aliases": [ + "java" + ] + }, + { + "name": "node", + "aliases": [ + "javascript", + "js", + "node" + ] + }, + { + "name": "jelly", + "aliases": [ + "jelly" + ] + }, + { + "name": "julia", + "aliases": [ + "jl", + "julia" + ] + }, + { + "name": "kotlin", + "aliases": [ + "kotlin" + ] + }, + { + "name": "lua", + "aliases": [ + "lua" + ] + }, + { + "name": "paradoc", + "aliases": [ + "paradoc" + ] + }, + { + "name": "perl", + "aliases": [ + "perl" + ] + }, + { + "name": "php", + "aliases": [ + "php", + "php3", + "php4", + "php5" + ] + }, + { + "name": "python3", + "aliases": [ + "py", + "py3", + "python", + "python3" + ] + }, + { + "name": "python2", + "aliases": [ + "python2" + ] + }, + { + "name": "rust", + "aliases": [ + "rs", + "rust" + ] + }, + { + "name": "swift", + "aliases": [ + "swift" + ] + }, + { + "name": "typescript", + "aliases": [ + "ts", + "typescript" + ] + } +] From f78aa34c10875e1091b5fecebb224e4297991507 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 13:14:46 +0100 Subject: [PATCH 02/16] Read file as string in CLI --- cli/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/index.js b/cli/src/index.js index c53d132..02fdd56 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -15,7 +15,7 @@ const [languageName, sourceFile, ...args] = process.argv.slice(2); return; } - const source = readFileSync(sourceFile); + const source = readFileSync(sourceFile).toString(); const language = languages.find(language => language.name === languageName); From f685bdc7516fc9810e4848ecd799c80e17233c2a Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 13:27:14 +0100 Subject: [PATCH 03/16] Fix aliases, update readme --- cli/execute | 33 +++++++++++++++++++++++++++++++-- cli/package.json | 12 ------------ cli/src/index.js | 30 ------------------------------ readme.md | 8 +++++--- 4 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 cli/package.json delete mode 100644 cli/src/index.js diff --git a/cli/execute b/cli/execute index 37a6b35..a62d120 100755 --- a/cli/execute +++ b/cli/execute @@ -1,3 +1,32 @@ -#!/usr/bin/env bash +#!/usr/bin/env node -node src $* +const { execute } = require('../shared/execute'); +const { readFileSync } = require('fs'); +const languages = require('../shared/languages.json'); + +const [languageName, sourceFile, ...args] = process.argv.slice(2); + +(async () => { + if (!languageName) { + console.error('Provide a language name'); + return; + } + + if (!sourceFile) { + console.error('Provide a source file'); + return; + } + + const source = readFileSync(sourceFile).toString(); + + const language = languages.find(language => language.aliases.includes(languageName.toLowerCase())); + + if (!language) { + console.error(`${languageName} is not supported by Piston`); + return; + } + + const { output } = await execute(language, source, args); + + console.log(output); +})(); diff --git a/cli/package.json b/cli/package.json deleted file mode 100644 index 0166712..0000000 --- a/cli/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "cli", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC" -} diff --git a/cli/src/index.js b/cli/src/index.js deleted file mode 100644 index 02fdd56..0000000 --- a/cli/src/index.js +++ /dev/null @@ -1,30 +0,0 @@ -const { execute } = require('../../shared/execute'); -const { readFileSync } = require('fs'); -const languages = require('../../shared/languages.json'); - -const [languageName, sourceFile, ...args] = process.argv.slice(2); - -(async () => { - if (!languageName) { - console.error('Provide a language name'); - return; - } - - if (!sourceFile) { - console.error('Provide a source file'); - return; - } - - const source = readFileSync(sourceFile).toString(); - - const language = languages.find(language => language.name === languageName); - - if (!language) { - console.error(`${languageName} is not supported by Piston`); - return; - } - - const { output } = await execute(language, source, args); - - console.log(output); -})(); diff --git a/readme.md b/readme.md index 5b2cb85..05f8d93 100644 --- a/readme.md +++ b/readme.md @@ -47,7 +47,7 @@ See `var/install.txt` for how to create a new LXC container and install all of t software. #### CLI Usage -- `lxc/execute [language] [file path] [args]` +- `cli/execute [language] [file path] [args]` #### API Usage To use the API, it must first be started. Please note that if root is required to access @@ -79,14 +79,17 @@ Content-Type: application/json [ { "name": "awk", + "aliases": ["awk"], "version": "1.3.3" }, { "name": "bash", + "aliases": ["bash"], "version": "4.4.20" }, { "name": "c", + "aliases": ["c"], "version": "7.5.0" } ] @@ -130,8 +133,7 @@ HTTP/1.1 400 Bad Request Content-Type: application/json { - "code": "unsupported_language", - "message": "whatever is not supported by Piston" + "message": "Provided language is not supported by Piston" } ``` From 8fd831982eb3589333203fe3dffc5357528193f2 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 14:19:29 +0100 Subject: [PATCH 04/16] Make ran field do something --- api/src/index.js | 4 ++-- shared/execute.js | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/src/index.js b/api/src/index.js index cd658c5..ba234fe 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -49,10 +49,10 @@ app.post( language.aliases.includes(req.body.language.toLowerCase()) ); - const { stdout, stderr, output } = await execute(language, req.body.source, req.body.args); + const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.args); res.status(200).json({ - ran: true, + ran, language: language.name, version: language.version, stdout, diff --git a/shared/execute.js b/shared/execute.js index 22c6dad..ed612bf 100644 --- a/shared/execute.js +++ b/shared/execute.js @@ -28,12 +28,17 @@ function execute(language, source, args) { output += chunk; }); - process.on('exit', () => { + process.on('exit', code => { stderr = stderr.trim().substring(0, 65535); stdout = stdout.trim().substring(0, 65535); output = output.trim().substring(0, 65535); - resolve({ stdout, stderr, output }); + resolve({ + stdout, + stderr, + output, + ran: code === 0, + }); }); }); } From c537cab2da435ed31e080c198b82d745d7068efd Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 18:41:41 +0100 Subject: [PATCH 05/16] Add stdin --- api/src/index.js | 9 ++++++++- cli/execute | 2 +- lxc/execute | 4 +++- lxc/executors/bash | 2 +- lxc/executors/brainfuck | 2 +- lxc/executors/c | 2 +- lxc/executors/cpp | 2 +- lxc/executors/csharp | 2 +- lxc/executors/deno | 4 ++-- lxc/executors/elixir | 2 +- lxc/executors/emacs | 2 +- lxc/executors/go | 2 +- lxc/executors/haskell | 2 +- lxc/executors/java | 2 +- lxc/executors/jelly | 2 +- lxc/executors/julia | 2 +- lxc/executors/kotlin | 2 +- lxc/executors/lua | 2 +- lxc/executors/nasm | 2 +- lxc/executors/nasm64 | 2 +- lxc/executors/node | 4 ++-- lxc/executors/perl | 2 +- lxc/executors/php | 2 +- lxc/executors/python2 | 2 +- lxc/executors/python3 | 2 +- lxc/executors/ruby | 2 +- lxc/executors/rust | 2 +- lxc/executors/swift | 2 +- lxc/executors/typescript | 2 +- shared/execute.js | 3 ++- 30 files changed, 42 insertions(+), 32 deletions(-) diff --git a/api/src/index.js b/api/src/index.js index ba234fe..70878ea 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -39,6 +39,13 @@ app.post( isArray: { errorMessage: 'Supplied args is not an array', }, + }, + stdin: { + in: 'body', + optional: true, + isString: { + errorMessage: 'Supplied stdin is not a string', + }, } }), async (req, res) => { @@ -49,7 +56,7 @@ app.post( language.aliases.includes(req.body.language.toLowerCase()) ); - const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.args); + const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.args, req.body.stdin); res.status(200).json({ ran, diff --git a/cli/execute b/cli/execute index a62d120..a8dc72c 100755 --- a/cli/execute +++ b/cli/execute @@ -26,7 +26,7 @@ const [languageName, sourceFile, ...args] = process.argv.slice(2); return; } - const { output } = await execute(language, source, args); + const { output } = await execute(language, source, '', args); console.log(output); })(); diff --git a/lxc/execute b/lxc/execute index 42d5b52..14db573 100755 --- a/lxc/execute +++ b/lxc/execute @@ -14,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 +cat $3 > $basepath$argpath +echo "${@:4}" > $basepath$argpath # process incrementor exec 200>$dir/lockfile diff --git a/lxc/executors/bash b/lxc/executors/bash index c13ad07..410e383 100755 --- a/lxc/executors/bash +++ b/lxc/executors/bash @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 bash code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 bash code.code < stdin.stdin" diff --git a/lxc/executors/brainfuck b/lxc/executors/brainfuck index b4458a0..94fc7d9 100755 --- a/lxc/executors/brainfuck +++ b/lxc/executors/brainfuck @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 brainfuck code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 brainfuck code.code < stdin.stdin" diff --git a/lxc/executors/c b/lxc/executors/c index 3130257..79ba5b0 100755 --- a/lxc/executors/c +++ b/lxc/executors/c @@ -1,4 +1,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" diff --git a/lxc/executors/cpp b/lxc/executors/cpp index 4b8c6cf..cfb02dd 100755 --- a/lxc/executors/cpp +++ b/lxc/executors/cpp @@ -1,4 +1,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" diff --git a/lxc/executors/csharp b/lxc/executors/csharp index 2c742c7..f2ee2ea 100755 --- a/lxc/executors/csharp +++ b/lxc/executors/csharp @@ -1,4 +1,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary < stdin.stdin" diff --git a/lxc/executors/deno b/lxc/executors/deno index b466288..1a92dc8 100755 --- a/lxc/executors/deno +++ b/lxc/executors/deno @@ -1,7 +1,7 @@ cd /tmp/$2 if [[ -z $(grep '[^[:space:]]' args.args) ]]; then - runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 deno run code.code" + 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" + runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 deno run code.code < stdin.stdin" fi diff --git a/lxc/executors/elixir b/lxc/executors/elixir index 49f9679..664501f 100755 --- a/lxc/executors/elixir +++ b/lxc/executors/elixir @@ -3,5 +3,5 @@ cd /tmp/$2 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" + runuser runner$1 -c "cd /tmp/$2 ; cat args.args ; xargs -d '\n' timeout -s KILL 3 elixir code.code < stdin.stdin" fi diff --git a/lxc/executors/emacs b/lxc/executors/emacs index 31f6186..6fb0553 100755 --- a/lxc/executors/emacs +++ b/lxc/executors/emacs @@ -3,5 +3,5 @@ cd /tmp/$2 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" + 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 diff --git a/lxc/executors/go b/lxc/executors/go index 063af21..b713027 100755 --- a/lxc/executors/go +++ b/lxc/executors/go @@ -3,4 +3,4 @@ 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" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file < stdin.stdin" diff --git a/lxc/executors/haskell b/lxc/executors/haskell index 7593b60..becc27f 100755 --- a/lxc/executors/haskell +++ b/lxc/executors/haskell @@ -4,4 +4,4 @@ mv code.code code.hs 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" diff --git a/lxc/executors/java b/lxc/executors/java index 6fc09e0..7f84d81 100755 --- a/lxc/executors/java +++ b/lxc/executors/java @@ -6,4 +6,4 @@ mv interim.java $name.java runuser runner$1 -c "\ cd /tmp/$2 ; \ javac $name.java ; \ - cat args.args | xargs -d '\n' timeout -s KILL 3 java $name" + cat args.args | xargs -d '\n' timeout -s KILL 3 java $name < stdin.stdin" diff --git a/lxc/executors/jelly b/lxc/executors/jelly index 4107b6b..32b79d9 100755 --- a/lxc/executors/jelly +++ b/lxc/executors/jelly @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 jelly fu code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 jelly fu code.code < stdin.stdin" diff --git a/lxc/executors/julia b/lxc/executors/julia index 7dddb24..3eeb323 100755 --- a/lxc/executors/julia +++ b/lxc/executors/julia @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 julia code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 julia code.code < stdin.stdin" diff --git a/lxc/executors/kotlin b/lxc/executors/kotlin index 5d5070a..6c034e6 100755 --- a/lxc/executors/kotlin +++ b/lxc/executors/kotlin @@ -3,4 +3,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 java -jar code.jar < stdin.stdin" diff --git a/lxc/executors/lua b/lxc/executors/lua index b412013..a5ab76f 100755 --- a/lxc/executors/lua +++ b/lxc/executors/lua @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 lua code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 lua code.code < stdin.stdin" diff --git a/lxc/executors/nasm b/lxc/executors/nasm index 22026af..45e1d1c 100755 --- a/lxc/executors/nasm +++ b/lxc/executors/nasm @@ -2,4 +2,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" diff --git a/lxc/executors/nasm64 b/lxc/executors/nasm64 index a6dc197..d498a54 100755 --- a/lxc/executors/nasm64 +++ b/lxc/executors/nasm64 @@ -2,4 +2,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" diff --git a/lxc/executors/node b/lxc/executors/node index 5fd7d26..04113d2 100755 --- a/lxc/executors/node +++ b/lxc/executors/node @@ -1,7 +1,7 @@ cd /tmp/$2 if [[ -z $(grep '[^[:space:]]' args.args) ]]; then - runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 node code.code" + 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" + runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code < stdin.stdin" fi diff --git a/lxc/executors/perl b/lxc/executors/perl index afb8ad5..9951e18 100755 --- a/lxc/executors/perl +++ b/lxc/executors/perl @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 perl code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 perl code.code < stdin.stdin" diff --git a/lxc/executors/php b/lxc/executors/php index d88a8d2..470f494 100755 --- a/lxc/executors/php +++ b/lxc/executors/php @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code < stdin.stdin" diff --git a/lxc/executors/python2 b/lxc/executors/python2 index d172f18..15b65de 100755 --- a/lxc/executors/python2 +++ b/lxc/executors/python2 @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python code.code < stdin.stdin" diff --git a/lxc/executors/python3 b/lxc/executors/python3 index 0749d88..a2bc47f 100755 --- a/lxc/executors/python3 +++ b/lxc/executors/python3 @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.8 code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.8 code.code < stdin.stdin" diff --git a/lxc/executors/ruby b/lxc/executors/ruby index 9de7477..5c5b181 100755 --- a/lxc/executors/ruby +++ b/lxc/executors/ruby @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code < stdin.stdin" diff --git a/lxc/executors/rust b/lxc/executors/rust index c939259..ad7d8e2 100755 --- a/lxc/executors/rust +++ b/lxc/executors/rust @@ -2,4 +2,4 @@ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin" diff --git a/lxc/executors/swift b/lxc/executors/swift index 4b5d8a1..fd8eb9f 100755 --- a/lxc/executors/swift +++ b/lxc/executors/swift @@ -1,2 +1,2 @@ cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 swift code.code" +runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 swift code.code < stdin.stdin" diff --git a/lxc/executors/typescript b/lxc/executors/typescript index 863d8d0..26adfba 100755 --- a/lxc/executors/typescript +++ b/lxc/executors/typescript @@ -4,4 +4,4 @@ runuser runner$1 -c "\ 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" + cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code < stdin.stdin" diff --git a/shared/execute.js b/shared/execute.js index ed612bf..fbfd5de 100644 --- a/shared/execute.js +++ b/shared/execute.js @@ -1,7 +1,7 @@ const { writeFile } = require('fs/promises'); const { spawn } = require('child_process'); -function execute(language, source, args) { +function execute(language, source, args, stdin) { return new Promise(async resolve => { const stamp = new Date().getTime(); const sourceFile = `/tmp/${stamp}.code`; @@ -11,6 +11,7 @@ function execute(language, source, args) { const process = spawn(__dirname + '/../lxc/execute', [ language.name, sourceFile, + stdin ?? '', args?.join('\n') ?? '', ]); From ea547167748a1ec99fe98fa83ab053844db7f831 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 18:52:18 +0100 Subject: [PATCH 06/16] Fix order of args and stdin --- api/src/index.js | 2 +- shared/execute.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/index.js b/api/src/index.js index 70878ea..d628ba1 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -56,7 +56,7 @@ app.post( language.aliases.includes(req.body.language.toLowerCase()) ); - const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.args, req.body.stdin); + const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.stdin, req.body.args); res.status(200).json({ ran, diff --git a/shared/execute.js b/shared/execute.js index fbfd5de..4124928 100644 --- a/shared/execute.js +++ b/shared/execute.js @@ -1,7 +1,7 @@ const { writeFile } = require('fs/promises'); const { spawn } = require('child_process'); -function execute(language, source, args, stdin) { +function execute(language, source, stdin, args) { return new Promise(async resolve => { const stamp = new Date().getTime(); const sourceFile = `/tmp/${stamp}.code`; From b7ba08ccdfb8570de10bd8b4e1d668815e7e25c8 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 20:02:36 +0100 Subject: [PATCH 07/16] Fix stdin --- lxc/execute | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc/execute b/lxc/execute index 14db573..3438547 100755 --- a/lxc/execute +++ b/lxc/execute @@ -21,7 +21,7 @@ arg=$(basename $argpath) mkdir -p $basepath/tmp/$epoch chmod 777 $basepath/tmp/$epoch cat $2 > $basepath$filepath -cat $3 > $basepath$argpath +echo $3 > $basepath$stdinpath echo "${@:4}" > $basepath$argpath # process incrementor From 008d55643b31b2cf516495ba87babd901e290e89 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 00:54:57 +0000 Subject: [PATCH 08/16] 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 +" From e637a95b335a361cb754c8e0932accca64d34dd4 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 01:12:13 +0000 Subject: [PATCH 09/16] Make execute.js support older Node versions --- shared/execute.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shared/execute.js b/shared/execute.js index 4124928..188a123 100644 --- a/shared/execute.js +++ b/shared/execute.js @@ -1,18 +1,18 @@ -const { writeFile } = require('fs/promises'); +const { writeFileSync } = require('fs'); const { spawn } = require('child_process'); -function execute(language, source, stdin, args) { - return new Promise(async resolve => { +function execute(language, source, stdin = '', args = []) { + return new Promise(resolve => { const stamp = new Date().getTime(); const sourceFile = `/tmp/${stamp}.code`; - await writeFile(sourceFile, source); + writeFileSync(sourceFile, source); const process = spawn(__dirname + '/../lxc/execute', [ language.name, sourceFile, - stdin ?? '', - args?.join('\n') ?? '', + stdin, + args.join('\n'), ]); let stdout = ''; From e462a7d41eb328dd0e0753335e090586cf087715 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 01:23:49 +0000 Subject: [PATCH 10/16] Add additional aliases for languages --- shared/languages.json | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/shared/languages.json b/shared/languages.json index ba04153..b158de2 100644 --- a/shared/languages.json +++ b/shared/languages.json @@ -50,7 +50,9 @@ "name": "cpp", "aliases": [ "c++", - "cpp" + "cpp", + "cc", + "cxx" ] }, { @@ -80,7 +82,8 @@ { "name": "elixir", "aliases": [ - "elixir" + "elixir", + "exs" ] }, { @@ -93,7 +96,8 @@ { "name": "go", "aliases": [ - "go" + "go", + "golang" ] }, { @@ -107,7 +111,8 @@ "aliases": [ "javascript", "js", - "node" + "node", + "node.js" ] }, { @@ -126,7 +131,8 @@ { "name": "kotlin", "aliases": [ - "kotlin" + "kotlin", + "kt" ] }, { @@ -144,7 +150,8 @@ { "name": "perl", "aliases": [ - "perl" + "perl", + "pl" ] }, { @@ -168,7 +175,8 @@ { "name": "python2", "aliases": [ - "python2" + "python2", + "py2" ] }, { From 14565b16e424e8fccf9833e667e0b5f0ad55d38b Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 13:50:40 +0000 Subject: [PATCH 11/16] Compile rust as runner --- api/src/index.js | 2 +- lxc/execute | 20 ++++++++++++-------- lxc/executors/paradoc | 8 ++++++-- lxc/executors/rust | 4 +--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/api/src/index.js b/api/src/index.js index d628ba1..d9a5cae 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -20,7 +20,7 @@ app.post( errorMessage: 'Supplied language is not a string', }, custom: { - options: value => languages.find(language => language.aliases.includes(value?.toLowerCase())), + options: value => value && languages.find(language => language.aliases.includes(value.toLowerCase())), errorMessage: 'Supplied language is not supported by Piston', }, }, diff --git a/lxc/execute b/lxc/execute index 3438547..29c445b 100755 --- a/lxc/execute +++ b/lxc/execute @@ -45,13 +45,17 @@ timeout -s KILL 20 \ # 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 {} \; ;\ - find /var/tmp -user runner$newinc -exec /bin/rm -rf {} \; ;\ - find /var/lock -user runner$newinc -exec /bin/rm -rf {} \; ;\ - find /dev/shm -user runner$newinc -exec /bin/rm -rf {} \; ;\ - find /run/lock -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 diff --git a/lxc/executors/paradoc b/lxc/executors/paradoc index 33fe880..08e6e2c 100755 --- a/lxc/executors/paradoc +++ b/lxc/executors/paradoc @@ -1,2 +1,6 @@ -cd /tmp/$2 -runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 python3 -m paradoc code.code <<< args.args" +#!/bin/bash + +runuser runner$1 -c " + cd /tmp/$2 + timeout -s KILL 3 python3 -m paradoc code.code < args.args +" diff --git a/lxc/executors/rust b/lxc/executors/rust index 2a70609..9dc32ea 100755 --- a/lxc/executors/rust +++ b/lxc/executors/rust @@ -1,9 +1,7 @@ #!/bin/bash -cd /tmp/$2 -rustc -o binary code.code - runuser runner$1 -c " cd /tmp/$2 + rustc -o binary code.code timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin " From 9851352f87a7dbbc9b4e032c86420f93b407e6a9 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 15:44:40 +0000 Subject: [PATCH 12/16] Move runuser to execute --- lxc/execute | 2 +- lxc/executors/awk | 2 +- lxc/executors/bash | 6 ++---- lxc/executors/brainfuck | 6 ++---- lxc/executors/c | 8 +++----- lxc/executors/cpp | 8 +++----- lxc/executors/csharp | 8 +++----- lxc/executors/deno | 6 ++---- lxc/executors/elixir | 6 ++---- lxc/executors/emacs | 6 ++---- lxc/executors/go | 10 ++++------ lxc/executors/haskell | 10 ++++------ lxc/executors/java | 10 +++------- lxc/executors/jelly | 6 ++---- lxc/executors/julia | 6 ++---- lxc/executors/kotlin | 10 ++++------ lxc/executors/lua | 6 ++---- lxc/executors/nasm | 10 ++++------ lxc/executors/nasm64 | 10 ++++------ lxc/executors/node | 6 ++---- lxc/executors/paradoc | 6 ++---- lxc/executors/perl | 6 ++---- lxc/executors/php | 6 ++---- lxc/executors/python2 | 6 ++---- lxc/executors/python3 | 6 ++---- lxc/executors/ruby | 6 ++---- lxc/executors/rust | 8 +++----- lxc/executors/swift | 6 ++---- lxc/executors/typescript | 14 ++++++-------- lxc/start | 2 +- 30 files changed, 76 insertions(+), 132 deletions(-) diff --git a/lxc/execute b/lxc/execute index 29c445b..d7e5b22 100755 --- a/lxc/execute +++ b/lxc/execute @@ -41,7 +41,7 @@ exec 200>&- # runner timeout -s KILL 20 \ lxc-attach --clear-env -n piston -- \ - /bin/bash -l -c "bash /exec/$lang $newinc $epoch" + /bin/bash -l -c "runuser runner$newinc /exec/$lang $newinc $epoch" # process janitor lxc-attach --clear-env -n piston -- \ diff --git a/lxc/executors/awk b/lxc/executors/awk index 26723b3..67cdee8 100755 --- a/lxc/executors/awk +++ b/lxc/executors/awk @@ -1,4 +1,4 @@ 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 awk -f code.awk < code.stdin diff --git a/lxc/executors/bash b/lxc/executors/bash index 04ebb1c..6aeb899 100755 --- a/lxc/executors/bash +++ b/lxc/executors/bash @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - xargs -a args.args -d '\n' timeout -s KILL 3 bash code.code < stdin.stdin -" +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 0503bcf..7ec1bfe 100755 --- a/lxc/executors/brainfuck +++ b/lxc/executors/brainfuck @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' brainfuck code.code < stdin.stdin -" +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 8d60422..096b1d9 100755 --- a/lxc/executors/c +++ b/lxc/executors/c @@ -1,7 +1,5 @@ #!/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 -" +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 8602962..5f7008b 100755 --- a/lxc/executors/cpp +++ b/lxc/executors/cpp @@ -1,7 +1,5 @@ #!/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 -" +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 4946e27..f35c876 100755 --- a/lxc/executors/csharp +++ b/lxc/executors/csharp @@ -1,7 +1,5 @@ #!/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 -" +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 a18c647..31132fa 100755 --- a/lxc/executors/deno +++ b/lxc/executors/deno @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' deno run code.code < stdin.stdin -" +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 0343cf1..49bfb78 100755 --- a/lxc/executors/elixir +++ b/lxc/executors/elixir @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' elixir code.code < stdin.stdin -" +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 3a64ecc..ab41624 100755 --- a/lxc/executors/emacs +++ b/lxc/executors/emacs @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' emacs -Q --script code.code < stdin.stdin -" +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 a9aa4fd..09c1e68 100755 --- a/lxc/executors/go +++ b/lxc/executors/go @@ -1,8 +1,6 @@ #!/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 -" +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 bc13034..df517d9 100755 --- a/lxc/executors/haskell +++ b/lxc/executors/haskell @@ -1,8 +1,6 @@ #!/bin/bash -runuser runner$1 -c "\ - 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 -" +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 12ac347..52f4cf0 100755 --- a/lxc/executors/java +++ b/lxc/executors/java @@ -2,10 +2,6 @@ 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 -" +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 0c1b343..945444e 100755 --- a/lxc/executors/jelly +++ b/lxc/executors/jelly @@ -1,6 +1,4 @@ #!/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 -" +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 4350335..e8b4ea5 100755 --- a/lxc/executors/julia +++ b/lxc/executors/julia @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' julia code.code < stdin.stdin -" +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 efd00e0..c304575 100755 --- a/lxc/executors/kotlin +++ b/lxc/executors/kotlin @@ -1,8 +1,6 @@ #!/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 -" +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 c318a87..4caa4b6 100755 --- a/lxc/executors/lua +++ b/lxc/executors/lua @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' lua code.code < stdin.stdin -" +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 f48e5bc..ffe8fd0 100755 --- a/lxc/executors/nasm +++ b/lxc/executors/nasm @@ -1,8 +1,6 @@ #!/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 -" +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 23ad450..98c2aab 100755 --- a/lxc/executors/nasm64 +++ b/lxc/executors/nasm64 @@ -1,8 +1,6 @@ #!/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 -" +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 b43fff0..3262b53 100755 --- a/lxc/executors/node +++ b/lxc/executors/node @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' node code.code < stdin.stdin -" +cd /tmp/$2 +timeout -s KILL 3 xargs -a args.args -d '\n' node code.code < stdin.stdin diff --git a/lxc/executors/paradoc b/lxc/executors/paradoc index 08e6e2c..be58dad 100755 --- a/lxc/executors/paradoc +++ b/lxc/executors/paradoc @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 python3 -m paradoc code.code < args.args -" +cd /tmp/$2 +timeout -s KILL 3 python3 -m paradoc code.code < args.args diff --git a/lxc/executors/perl b/lxc/executors/perl index 8657564..8b65855 100755 --- a/lxc/executors/perl +++ b/lxc/executors/perl @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' perl code.code < stdin.stdin -" +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 2acacb9..9f21f7b 100755 --- a/lxc/executors/php +++ b/lxc/executors/php @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' php code.code < stdin.stdin -" +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 ab90f29..5fa1c3e 100755 --- a/lxc/executors/python2 +++ b/lxc/executors/python2 @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' python code.code < stdin.stdin -" +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 a944242..6cb93f8 100755 --- a/lxc/executors/python3 +++ b/lxc/executors/python3 @@ -1,6 +1,4 @@ #!/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 -" +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 9407d75..ebb9b06 100755 --- a/lxc/executors/ruby +++ b/lxc/executors/ruby @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' ruby code.code < stdin.stdin -" +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 9dc32ea..137dffa 100755 --- a/lxc/executors/rust +++ b/lxc/executors/rust @@ -1,7 +1,5 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - rustc -o binary code.code - timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin -" +cd /tmp/$2 +rustc -o binary code.code +timeout -s KILL 3 xargs -a args.args -d '\n' ./binary < stdin.stdin diff --git a/lxc/executors/swift b/lxc/executors/swift index 6e0565d..a8327f7 100755 --- a/lxc/executors/swift +++ b/lxc/executors/swift @@ -1,6 +1,4 @@ #!/bin/bash -runuser runner$1 -c " - cd /tmp/$2 - timeout -s KILL 3 xargs -a args.args -d '\n' swift code.code < stdin.stdin -" +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 20a382f..8c1873d 100755 --- a/lxc/executors/typescript +++ b/lxc/executors/typescript @@ -1,10 +1,8 @@ #!/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 -" +cd /tmp/$2 +mv code.code interim.ts +tsc interim.ts +rm -f interim.ts +mv interim.js code.code +timeout -s KILL 3 xargs -a args.args -d '\n' node code.code < stdin.stdin diff --git a/lxc/start b/lxc/start index 6c13c98..fec7aef 100755 --- a/lxc/start +++ b/lxc/start @@ -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 From 7f03de9f71707145751266405c613b054b44f98b Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 15:53:46 +0000 Subject: [PATCH 13/16] Add shebang to awk --- lxc/executors/awk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lxc/executors/awk b/lxc/executors/awk index 67cdee8..dafa525 100755 --- a/lxc/executors/awk +++ b/lxc/executors/awk @@ -1,3 +1,5 @@ +#!/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 From 1c99570e671f10fac04473d2e43f2be0c28bafa8 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 22:29:45 +0000 Subject: [PATCH 14/16] Change awk executor --- lxc/executors/awk | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lxc/executors/awk b/lxc/executors/awk index dafa525..8590654 100755 --- a/lxc/executors/awk +++ b/lxc/executors/awk @@ -1,6 +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 -timeout -s KILL 3 awk -f code.awk < code.stdin +timeout -s KILL 3 awk -f code.code < stdin.stdin From 2b1f213beab77d24bf201dacfc1af6c798bf9ee6 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 22:30:02 +0000 Subject: [PATCH 15/16] Change rust install instructions --- var/install.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/var/install.txt b/var/install.txt index 9be572e..ae81b05 100644 --- a/var/install.txt +++ b/var/install.txt @@ -96,11 +96,13 @@ make make install # install rust -# final binary: /opt/.cargo/bin/rustc -# get version: /opt/.cargo/bin/rustc --version -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -echo 'export PATH=$PATH:/opt/.cargo/bin' >> /opt/.profile -source /opt/.profile +# final binary: /usr/local/bin/rustc +# get version: /usr/local/bin/rustc --version +cd /opt && mkdir rust && cd rust +wget https://static.rust-lang.org/dist/rust-1.49.0-x86_64-unknown-linux-gnu.tar.gz +tar -xzf rust-1.49.0-x86_64-unknown-linux-gnu.tar.gz +cd rust-1.49.0-x86_64-unknown-linux-gnu +./install.sh # install swift # final binary: /opt/swift/swift-5.1.5-RELEASE-ubuntu18.04/usr/bin/swift From a2eeff85b5ae4a363adc75581cbb76cb1d48a02d Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sun, 17 Jan 2021 22:36:52 +0000 Subject: [PATCH 16/16] Revert back to the mess the awk executor was --- lxc/executors/awk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lxc/executors/awk b/lxc/executors/awk index 8590654..dafa525 100755 --- a/lxc/executors/awk +++ b/lxc/executors/awk @@ -1,4 +1,6 @@ #!/bin/bash cd /tmp/$2 -timeout -s KILL 3 awk -f code.code < stdin.stdin +timeout -s KILL 2 sed "/___code___/Q" code.code > code.stdin +timeout -s KILL 2 sed "1,/___code___/d" code.code > code.awk +timeout -s KILL 3 awk -f code.awk < code.stdin