|
|
@ -10,6 +10,7 @@ import { Logger } from './log';
|
|
|
|
const logger = new Logger('sandbox');
|
|
|
|
const logger = new Logger('sandbox');
|
|
|
|
const env = ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME=/w'];
|
|
|
|
const env = ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME=/w'];
|
|
|
|
const axios = Axios.create({ baseURL: getConfig('sandbox_host') });
|
|
|
|
const axios = Axios.create({ baseURL: getConfig('sandbox_host') });
|
|
|
|
|
|
|
|
let callId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
const statusMap = {
|
|
|
|
const statusMap = {
|
|
|
|
'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED,
|
|
|
|
'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED,
|
|
|
@ -90,9 +91,10 @@ export async function runMultiple(execute) {
|
|
|
|
body.cmd[0].files[1] = null;
|
|
|
|
body.cmd[0].files[1] = null;
|
|
|
|
body.cmd[1].files[0] = null;
|
|
|
|
body.cmd[1].files[0] = null;
|
|
|
|
body.cmd[1].files[1] = null;
|
|
|
|
body.cmd[1].files[1] = null;
|
|
|
|
if (argv['show-sandbox-call']) logger.debug(JSON.stringify(body));
|
|
|
|
const id = callId++;
|
|
|
|
|
|
|
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
|
|
|
res = await axios.post('/run', body);
|
|
|
|
res = await axios.post('/run', body);
|
|
|
|
if (argv['show-sandbox-call']) logger.debug(JSON.stringify(res.data));
|
|
|
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
throw new SystemError('Sandbox Error');
|
|
|
|
throw new SystemError('Sandbox Error');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -111,9 +113,10 @@ export async function run(execute, params?) {
|
|
|
|
if (typeof execute === 'object') return await runMultiple(execute);
|
|
|
|
if (typeof execute === 'object') return await runMultiple(execute);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const body = { cmd: [proc({ execute, ...params })] };
|
|
|
|
const body = { cmd: [proc({ execute, ...params })] };
|
|
|
|
if (argv['show-sandbox-call']) logger.debug(JSON.stringify(body));
|
|
|
|
const id = callId++;
|
|
|
|
|
|
|
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
|
|
|
const res = await axios.post('/run', body);
|
|
|
|
const res = await axios.post('/run', body);
|
|
|
|
if (argv['show-sandbox-call']) logger.debug(JSON.stringify(res.data));
|
|
|
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
|
|
|
[result] = res.data;
|
|
|
|
[result] = res.data;
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
// FIXME request body larger than maxBodyLength limit
|
|
|
|
// FIXME request body larger than maxBodyLength limit
|
|
|
|