From 2a9de4d7b2f053f55efea8f58f236850ae1bac28 Mon Sep 17 00:00:00 2001 From: Jack Forden <60225273+JForden@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:17:58 -0600 Subject: [PATCH 1/3] Change Java to compiled language to facilitate multi-file Currently, Piston does not support multi-file Java submissions This change turns Java into a compiled language, while still maintaining the flexibility of single file submissions. --- packages/java/15.0.2/compile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packages/java/15.0.2/compile diff --git a/packages/java/15.0.2/compile b/packages/java/15.0.2/compile new file mode 100644 index 0000000..9e3a8db --- /dev/null +++ b/packages/java/15.0.2/compile @@ -0,0 +1,34 @@ +#!/bin/bash + +# Check if exactly one argument is provided +if [ $# -eq 1 ]; then + mv $1 $1.java + filename=$1.java + shift + java $filename "$@" +else + # Initialize an empty array to hold the filenames + declare -a javaFiles + + # Loop through each argument + for file in "$@"; do + # Check if the file already ends with .java + if [[ "$file" == *.java ]]; then + # If it does, add it directly to the array + javaFiles+=("$file") + else + # If it doesn't, add .java extension then add to the array + javaFiles+=("${file}.java") + fi + done + + # Compile all Java files at once + javac "${javaFiles[@]}" + + # Run the compiled Java classes + # Assuming the first argument is the main class file to run + # Remove .java extension from the main class name if present + mainClass="${1%.java}" + # Execute the main class + java "$mainClass" +fi From 6ef0cdf7b4c96e71d49ae267dc905c177ede1d51 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Sat, 8 Feb 2025 15:10:50 +0200 Subject: [PATCH 2/3] Provide HOME in sandbox (#702) --- api/src/job.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/job.js b/api/src/job.js index d46120b..31f688d 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -156,6 +156,8 @@ class Job { '-s', '-c', '/box/submission', + '-E', + 'HOME=/tmp', '-e', `--dir=${this.runtime.pkgdir}`, `--dir=/etc:noexec`, From 1d55a41a2d563318388596b46d7da772027339ba Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Sat, 8 Feb 2025 20:46:46 +0200 Subject: [PATCH 3/3] Explicitly provide env vars instead of inheriting them from parent (#703) --- api/src/job.js | 8 +++----- api/src/runtime.js | 10 +--------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/api/src/job.js b/api/src/job.js index 31f688d..8c3fa79 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -158,7 +158,9 @@ class Job { '/box/submission', '-E', 'HOME=/tmp', - '-e', + ...this.runtime.env_vars.flat_map(v => ['-E', v]), + '-E', + `PISTON_LANGUAGE=${this.runtime.language}`, `--dir=${this.runtime.pkgdir}`, `--dir=/etc:noexec`, `--processes=${this.runtime.max_process_count}`, @@ -177,10 +179,6 @@ class Job { ...args, ], { - env: { - ...this.runtime.env_vars, - PISTON_LANGUAGE: this.runtime.language, - }, stdio: 'pipe', } ); diff --git a/api/src/runtime.js b/api/src/runtime.js index 9a2adf4..90a2225 100644 --- a/api/src/runtime.js +++ b/api/src/runtime.js @@ -178,15 +178,7 @@ class Runtime { const env_file = path.join(this.pkgdir, '.env'); const env_content = fss.read_file_sync(env_file).toString(); - this._env_vars = {}; - - env_content - .trim() - .split('\n') - .map(line => line.split('=', 2)) - .forEach(([key, val]) => { - this._env_vars[key.trim()] = val.trim(); - }); + this._env_vars = env_content.trim().split('\n'); } return this._env_vars;