mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
use real uid for killing processes instead of using euid (#206)
This commit is contained in:
parent
972228412a
commit
0da1cd5867
3 changed files with 19 additions and 18 deletions
|
@ -5,7 +5,6 @@ const path = require('path');
|
|||
const config = require('./config');
|
||||
const globals = require('./globals');
|
||||
const fs = require('fs/promises');
|
||||
const ps_list = require('ps-list');
|
||||
const wait_pid = require('waitpid');
|
||||
|
||||
const job_states = {
|
||||
|
@ -194,8 +193,25 @@ class Job {
|
|||
async cleanup_processes(){
|
||||
let processes = [1];
|
||||
while(processes.length > 0){
|
||||
processes = await ps_list();
|
||||
processes = processes.filter(proc => proc.uid == this.uid);
|
||||
processes = await new Promise((resolve, reject) => cp.execFile('ps', ['awwxo', 'pid,ruid'], function(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)
|
||||
}
|
||||
else{
|
||||
reject(error)
|
||||
}
|
||||
}));
|
||||
|
||||
processes = processes.filter(proc => proc.ruid == this.uid);
|
||||
|
||||
for(const proc of processes){
|
||||
// First stop the processes, but keep their resources allocated so they cant re-fork
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue