diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index ac2c84ca..78e63104 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.6.4", + "version": "2.6.5", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/setting.yaml b/packages/hydrojudge/setting.yaml index e549c01a..33f3b8b5 100644 --- a/packages/hydrojudge/setting.yaml +++ b/packages/hydrojudge/setting.yaml @@ -51,4 +51,11 @@ disable: type: boolean name: disable desc: Disable builtin judge - default: false \ No newline at end of file + default: false +env: + type: text + name: env + desc: Sandbox Env + default: | + PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + HOME=/w \ No newline at end of file diff --git a/packages/hydrojudge/src/config.ts b/packages/hydrojudge/src/config.ts index fa082da2..9dec040b 100644 --- a/packages/hydrojudge/src/config.ts +++ b/packages/hydrojudge/src/config.ts @@ -22,6 +22,9 @@ let config = { parallelism: 2, config: null, langs: null, + env: `\ +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +HOME=/w`, }; export function getConfig(key: string) { diff --git a/packages/hydrojudge/src/sandbox.ts b/packages/hydrojudge/src/sandbox.ts index f6c20beb..23fff978 100644 --- a/packages/hydrojudge/src/sandbox.ts +++ b/packages/hydrojudge/src/sandbox.ts @@ -8,8 +8,6 @@ import { getConfig } from './config'; import { Logger } from './log'; const logger = new Logger('sandbox'); -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') }); let callId = 0; const statusMap = { @@ -33,7 +31,7 @@ function proc({ const size = parseMemoryMB(getConfig('stdio_size')); return { args: cmd(execute.replace(/\$\{dir\}/g, '/w')), - env, + env: getConfig('env').split('\n'), files: [ stdin ? { src: stdin } : { content: '' }, { name: 'stdout', max: 1024 * 1024 * size }, @@ -93,7 +91,7 @@ export async function runMultiple(execute) { body.cmd[1].files[1] = null; 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.create({ baseURL: getConfig('sandbox_host') }).post('/run', body); if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data)); } catch (e) { if (e instanceof FormatError) throw e; @@ -103,7 +101,7 @@ export async function runMultiple(execute) { } export async function del(fileId) { - const res = await axios.delete(`/file/${fileId}`); + const res = await Axios.create({ baseURL: getConfig('sandbox_host') }).delete(`/file/${fileId}`); return res.data; } @@ -116,7 +114,7 @@ export async function run(execute, params?) { const body = { cmd: [proc({ execute, ...params })] }; 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.create({ baseURL: getConfig('sandbox_host') }).post('/run', body); if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data)); [result] = res.data; } catch (e) { diff --git a/packages/hydrojudge/src/service.ts b/packages/hydrojudge/src/service.ts index 273f5d19..5ec37a37 100644 --- a/packages/hydrojudge/src/service.ts +++ b/packages/hydrojudge/src/service.ts @@ -18,7 +18,6 @@ import { getConfig } from './config'; declare module 'hydrooj/dist/interface' { interface SystemKeys { - 'hydrojudge.langs': string, 'hydrojudge.cache_dir': string, 'hydrojudge.tmp_dir': string, 'hydrojudge.tmpfs_size': string,