judge: ignore tmpfs error

This commit is contained in:
undefined committed 2020-10-05 20:58:30 +08:00
1 parent b8c316c44b
commit 4b7f18baaa
3 files changed
+35 -28

No files matched your search

+1 -4
View File
@@ -1,11 +1,8 @@
{
"name": "@hydrooj/hydrojudge",
"version": "2.0.13",
"version": "2.0.14",
"main": "package.json",
"author": "masnn",
"os": [
"linux"
],
"dependencies": {
"axios": "^0.20.0",
"bson": "^4.1.0",
+26 -22
View File
@@ -20,9 +20,10 @@ const cache: any = {};
async function stackSize() {
let output = '';
const context: any = {
lang: 'ccWithoutO2',
code: `#include <iostream>
try {
const context: any = {
lang: 'ccWithoutO2',
code: `#include <iostream>
using namespace std;
int i=1;
int main(){
@@ -32,25 +33,28 @@ int main(){
if (i>256) return 0;
main();
}`,
config: {
time: 3000,
memory: 256,
},
stat: {},
clean: [],
next: (data) => {
if (data.case) output = data.case.message;
},
end: () => { },
};
context.tmpdir = path.resolve(tmpdir(), 'hydro', 'tmp', 'sysinfo');
fs.ensureDirSync(context.tmpdir);
tmpfs.mount(context.tmpdir, '64m');
await judge(context).catch((e) => console.error(e));
// eslint-disable-next-line no-await-in-loop
for (const clean of context.clean) await clean().catch();
tmpfs.umount(context.tmpdir);
fs.removeSync(context.tmpdir);
config: {
time: 3000,
memory: 256,
},
stat: {},
clean: [],
next: (data) => {
if (data.case) output = data.case.message;
},
end: () => { },
};
context.tmpdir = path.resolve(tmpdir(), 'hydro', 'tmp', 'sysinfo');
fs.ensureDirSync(context.tmpdir);
tmpfs.mount(context.tmpdir, '64m');
await judge(context).catch((e) => console.error(e));
// eslint-disable-next-line no-await-in-loop
for (const clean of context.clean) await clean().catch();
tmpfs.umount(context.tmpdir);
fs.removeSync(context.tmpdir);
} catch (e) {
return -1;
}
const a = output.split(' ');
return parseInt(a[a.length - 2], 10);
}
+8 -2
View File
@@ -1,11 +1,17 @@
import child from 'child_process';
import fs from 'fs-extra';
import os from 'os';
import { Logger } from 'hydrooj/dist/logger';
const logger = new Logger('judge');
const linux = os.platform() === 'linux';
if (!linux) logger.warn('Not running on linux. tmpfs disabled.');
export function mount(path: string, size = '32m') {
fs.ensureDirSync(path);
child.execSync(`mount tmpfs ${path} -t tmpfs -o size=${size}`);
if (linux) child.execSync(`mount tmpfs ${path} -t tmpfs -o size=${size}`);
}
export function umount(path: string) {
child.execSync(`umount ${path}`);
if (linux) child.execSync(`umount ${path}`);
}