Skip to content

Commit 5f2a6dd

Browse files
committed
added timeout options for lxc
1 parent ba6d98f commit 5f2a6dd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/lxc.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import { exec } from "child_process";
44
import { mkdirSync, writeFileSync, readFileSync, chmodSync } from "fs";
55
import { platform } from "os";
6-
import { Language } from "./constants";
6+
import {
7+
defaultExecutionTimeout,
8+
IExecuteOptions,
9+
Language,
10+
} from "./constants";
711

812
class LXC {
913
LXC_ROOT_FS: string;
@@ -77,7 +81,8 @@ class LXC {
7781
input: string,
7882
language: Language,
7983
args: string[] = [],
80-
stdin: string = ""
84+
stdin: string = "",
85+
options: IExecuteOptions = { timeout: defaultExecutionTimeout }
8186
) {
8287
const id = new Date().getTime() + "_" + Math.floor(Math.random() * 10000);
8388

@@ -86,6 +91,10 @@ class LXC {
8691
writeFileSync(`${this.LXC_ROOT_FS}/tmp/${id}/code.code`, input);
8792
writeFileSync(`${this.LXC_ROOT_FS}/tmp/${id}/args.args`, args.join("\n"));
8893
writeFileSync(`${this.LXC_ROOT_FS}/tmp/${id}/stdin.stdin`, stdin);
94+
writeFileSync(
95+
`${this.LXC_ROOT_FS}/tmp/${id}/timeout.timeout`,
96+
(options.timeout || defaultExecutionTimeout).toString()
97+
);
8998

9099
// Copy .sh file to correct location
91100
const shFile = readFileSync(

0 commit comments

Comments
 (0)