Compare commits

..

13 Commits

Author SHA1 Message Date
Thomas Hobson 7d90cddf27
Merge pull request #333 from Brikaa/iverilog
pkg(iverilog-11.0.0): Added iverilog 11.0.0
2021-10-02 00:44:22 +13:00
Omar Brikaa 989ea52bfa
Merge branch 'master' into iverilog 2021-10-01 13:36:06 +02:00
Thomas Hobson 7c6148c8d1
Merge pull request #334 from Brikaa/docs-logs
Add ./piston logs, note about SemVer
2021-10-02 00:27:30 +13:00
Thomas Hobson b6629b3354
Merge branch 'master' into iverilog 2021-10-02 00:24:52 +13:00
Thomas Hobson c6a7ccc77c
Merge pull request #335 from Brikaa/sqlite
pkg(sqlite3-3.36.0): Added sqlite3 3.36.0
2021-10-02 00:15:56 +13:00
Thomas Hobson 8165770cfd
Merge branch 'master' into iverilog 2021-10-02 00:11:06 +13:00
Thomas Hobson 874cc815e9
Merge branch 'master' into sqlite 2021-10-02 00:10:02 +13:00
Thomas Hobson 9e81d2ff67
Merge pull request #343 from engineer-man/process-janitor
rework process janitor
2021-10-02 00:08:58 +13:00
Thomas Hobson 1b6563d181
rework process janitor
Old process janitor required starting a `ps` process.
This was problematic, as `ps` requires another entry in the process table, which in some cases was impossible as it was exhausted.
2021-10-02 00:07:37 +13:00
Brikaa 5cdc71d268 pkg(sqlite3-3.36.0): Added sqlite3 3.36.0 2021-09-30 09:12:22 +02:00
Brikaa e5ac7a2acc Add ./piston logs 2021-09-26 14:09:25 +02:00
Brikaa 474c986879 Add semantic versioning in CONTRIBUTING.MD 2021-09-26 14:02:03 +02:00
Brikaa 56a3c91a6a pkg(iverilog-11.0.0): Added iverilog 11.0.0 2021-09-26 13:25:13 +02:00
18 changed files with 121 additions and 37 deletions

View File

@ -146,26 +146,31 @@ class Job {
const kill_timeout = set_timeout( const kill_timeout = set_timeout(
_ => proc.kill('SIGKILL'), async _ => {
logger.info(`Timeout exceeded timeout=${timeout} uuid=${this.uuid}`)
process.kill(proc.pid, 'SIGKILL')
},
timeout timeout
); );
proc.stderr.on('data', data => { proc.stderr.on('data', async data => {
if(eventBus !== null) { if(eventBus !== null) {
eventBus.emit("stderr", data); eventBus.emit("stderr", data);
} else if (stderr.length > config.output_max_size) { } else if (stderr.length > config.output_max_size) {
proc.kill('SIGKILL'); logger.info(`stderr length exceeded uuid=${this.uuid}`)
process.kill(proc.pid, 'SIGKILL')
} else { } else {
stderr += data; stderr += data;
output += data; output += data;
} }
}); });
proc.stdout.on('data', data => { proc.stdout.on('data', async data => {
if(eventBus !== null){ if(eventBus !== null){
eventBus.emit("stdout", data); eventBus.emit("stdout", data);
} else if (stdout.length > config.output_max_size) { } else if (stdout.length > config.output_max_size) {
proc.kill('SIGKILL'); logger.info(`stdout length exceeded uuid=${this.uuid}`)
process.kill(proc.pid, 'SIGKILL')
} else { } else {
stdout += data; stdout += data;
output += data; output += data;
@ -179,6 +184,7 @@ class Job {
proc.stdout.destroy(); proc.stdout.destroy();
await this.cleanup_processes() await this.cleanup_processes()
logger.debug(`Finished exit cleanup uuid=${this.uuid}`)
}; };
proc.on('exit', async (code, signal) => { proc.on('exit', async (code, signal) => {
@ -284,36 +290,47 @@ class Job {
this.state = job_states.EXECUTED; this.state = job_states.EXECUTED;
} }
async cleanup_processes() { async cleanup_processes(dont_wait = []) {
let processes = [1]; let processes = [1];
logger.debug(`Cleaning up processes uuid=${this.uuid}`)
while (processes.length > 0) { while (processes.length > 0) {
processes = await new Promise((resolve, reject) => processes = []
cp.execFile('ps', ['awwxo', 'pid,ruid'], (err, stdout) => {
if (err === null) {
const lines = stdout.split('\n').slice(1); //Remove header with slice
const procs = lines.map(line => {
const [pid, ruid] = line
.trim()
.split(/\s+/)
.map(n => parseInt(n));
return { pid, ruid };
});
resolve(procs); const proc_ids = await fs.readdir("/proc");
} else {
reject(error);
processes = await Promise.all(proc_ids.map(async (proc_id) => {
if(isNaN(proc_id)) return -1;
try{
const proc_status = await fs.read_file(path.join("/proc",proc_id,"status"));
const proc_lines = proc_status.to_string().split("\n")
const uid_line = proc_lines.find(line=>line.starts_with("Uid:"))
const [_, ruid, euid, suid, fuid] = uid_line.split(/\s+/);
if(ruid == this.uid || euid == this.uid)
return parse_int(proc_id)
}catch{
return -1
} }
})
);
processes = processes.filter(proc => proc.ruid === this.uid); return -1
}))
processes = processes.filter(p => p > 0)
if(processes.length > 0)
logger.debug(`Got processes to kill: ${processes} uuid=${this.uuid}`)
for (const proc of processes) { for (const proc of processes) {
// First stop the processes, but keep their resources allocated so they cant re-fork // First stop the processes, but keep their resources allocated so they cant re-fork
try { try {
process.kill(proc.pid, 'SIGSTOP'); process.kill(proc, 'SIGSTOP');
} catch { } catch {
// Could already be dead // Could already be dead
} }
@ -322,14 +339,17 @@ class Job {
for (const proc of processes) { for (const proc of processes) {
// Then clear them out of the process tree // Then clear them out of the process tree
try { try {
process.kill(proc.pid, 'SIGKILL'); process.kill(proc, 'SIGKILL');
} catch { } catch {
// Could already be dead and just needs to be waited on // Could already be dead and just needs to be waited on
} }
wait_pid(proc.pid); if(!dont_wait.includes(proc))
wait_pid(proc);
} }
} }
logger.debug(`Cleaned up processes uuid=${this.uuid}`)
} }
async cleanup_filesystem() { async cleanup_filesystem() {

4
cli/package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "piston-cli", "name": "piston-cli",
"version": "1.0.0", "version": "1.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "piston-cli", "name": "piston-cli",
"version": "1.0.0", "version": "1.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.2", "axios": "^0.21.2",

View File

@ -2,7 +2,7 @@
## Naming Languages ## Naming Languages
Languages should be named after their interpreters, and the command line binaries you call. Languages should be named after their interpreters, and the command line binaries you call. The language version should use semantic versioning.
For example, the full name of the standard python interpreter is `CPython`, however we would name it `python`, after the main binary which it provides. For example, the full name of the standard python interpreter is `CPython`, however we would name it `python`, after the main binary which it provides.
In the example of NodeJS, we would call this `node`, after the main binary. In the example of NodeJS, we would call this `node`, after the main binary.

17
packages/iverilog/11.0.0/build.sh vendored Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
PREFIX=$(realpath $(dirname $0))
mkdir -p build/iverilog
cd build/iverilog
curl -L https://github.com/steveicarus/iverilog/archive/refs/tags/v11_0.tar.gz -o iverilog.tar.gz
tar xzf iverilog.tar.gz --strip-components=1
chmod +x ./autoconf.sh
./autoconf.sh
./configure --prefix="$PREFIX"
make -j$(nproc)
make install -j$(nproc)
cd ../../
rm -rf build

4
packages/iverilog/11.0.0/compile vendored Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
rename 's/$/\.v/' "$@" # Add .v extension
iverilog *.v

2
packages/iverilog/11.0.0/environment vendored Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
export PATH=$PWD/bin:$PATH

View File

@ -0,0 +1,5 @@
{
"language": "iverilog",
"version": "11.0.0",
"aliases": ["verilog", "vvp"]
}

4
packages/iverilog/11.0.0/run vendored Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
shift
vvp a.out "$@"

7
packages/iverilog/11.0.0/test.verilog vendored Normal file
View File

@ -0,0 +1,7 @@
module hello;
initial
begin
$display("OK");
$finish ;
end
endmodule

10
packages/sqlite3/3.36.0/build.sh vendored Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
PREFIX=$(realpath $(dirname $0))
curl https://www.sqlite.org/2021/sqlite-amalgamation-3360000.zip -o sqlite.zip
unzip -q sqlite.zip
rm -rf sqlite.zip
gcc -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION sqlite-amalgamation-3360000/shell.c sqlite-amalgamation-3360000/sqlite3.c -o sqlite3
rm -rf sqlite-amalgamation-3360000

2
packages/sqlite3/3.36.0/environment vendored Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
export PATH=$PWD:$PATH

5
packages/sqlite3/3.36.0/metadata.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"language": "sqlite3",
"version": "3.36.0",
"aliases": ["sqlite", "sql"]
}

3
packages/sqlite3/3.36.0/run vendored Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
sqlite3 < "$1"

1
packages/sqlite3/3.36.0/test.sql vendored Normal file
View File

@ -0,0 +1 @@
SELECT 'OK';

2
piston
View File

@ -19,6 +19,7 @@ case $1 in
echo "Commands:" echo "Commands:"
echo " select <environment> Select the environment" echo " select <environment> Select the environment"
echo " docker_compose <args...> Interact directly with the docker-compose for the selected environment" echo " docker_compose <args...> Interact directly with the docker-compose for the selected environment"
echo " logs Show docker-compose logs"
echo echo
echo " start Starts piston" echo " start Starts piston"
echo " stop Stops piston" echo " stop Stops piston"
@ -49,6 +50,7 @@ case $1 in
select) echo "$2" > .piston_env ;; select) echo "$2" > .piston_env ;;
docker_compose) shift; docker_compose "$@";; docker_compose) shift; docker_compose "$@";;
logs) docker_compose logs -f ;;
restart) docker_compose restart ;; restart) docker_compose restart ;;
start) docker_compose up -d ;; start) docker_compose up -d ;;

View File

@ -343,6 +343,7 @@ Content-Type: application/json
`golfscript`, `golfscript`,
`groovy`, `groovy`,
`haskell`, `haskell`,
`iverilog`,
`java`, `java`,
`javascript`, `javascript`,
`jelly`, `jelly`,
@ -374,6 +375,7 @@ Content-Type: application/json
`ruby`, `ruby`,
`rust`, `rust`,
`scala`, `scala`,
`sqlite3`,
`swift`, `swift`,
`typescript`, `typescript`,
`basic`, `basic`,

View File

@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
libncursesw5-dev python3-pip libgmp-dev libmpfr-dev python2 libffi-dev gfortran\ libncursesw5-dev python3-pip libgmp-dev libmpfr-dev python2 libffi-dev gfortran\
libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev libfftw3-dev \ libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev libfftw3-dev \
libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev libsundials-dev \ libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev libsundials-dev \
libbz2-dev liblzma-dev libpcre2-dev && \ libbz2-dev liblzma-dev libpcre2-dev gperf bison flex g++ && \
ln -sf /bin/bash /bin/sh && \ ln -sf /bin/bash /bin/sh && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2 update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2