Skip to content

Commit bd40ce6

Browse files
committed
增加自定义运行环境变量
1 parent 3887c5f commit bd40ce6

3 files changed

Lines changed: 23 additions & 24 deletions

File tree

client/Python/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
import hashlib
55
import json
6-
import time
76

87
import requests
98

10-
from languages import c_lang_config, cpp_lang_config, java_lang_config
9+
from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile
1110

1211

1312
class JudgeServerClientError(Exception):
@@ -95,7 +94,7 @@ def compile_spj(self, src, spj_version, spj_compile_config, test_case_id):
9594

9695
client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:12358")
9796
print client.ping(), "\n\n"
98-
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_config["spj_compile"],
97+
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_spj_compile,
9998
test_case_id="spj"), "\n\n"
10099

101100
print client.judge(src=c_src, language_config=c_lang_config,
@@ -113,4 +112,4 @@ def compile_spj(self, src, spj_version, spj_compile_config, test_case_id):
113112
print client.judge(src=c_src, language_config=c_lang_config,
114113
max_cpu_time=1000, max_memory=1024 * 1024 * 128,
115114
test_case_id="spj",
116-
spj_version="1", spj_config=c_lang_config["spj_config"]), "\n\n"
115+
spj_version="1", spj_config=c_lang_spj_config), "\n\n"

client/Python/languages.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,28 @@
88
"max_cpu_time": 3000,
99
"max_real_time": 5000,
1010
"max_memory": 128 * 1024 * 1024,
11-
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 -static {src_path} -lm -o {exe_path}",
11+
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}",
1212
},
1313
"run": {
1414
"command": "{exe_path}",
15-
"seccomp_rule": "c_cpp"
16-
},
17-
"spj_compile": {
18-
"src_name": "spj-{spj_version}.c",
19-
"exe_name": "spj-{spj_version}",
20-
"max_cpu_time": 3000,
21-
"max_real_time": 5000,
22-
"max_memory": 1024 * 1024 * 1024,
23-
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}"
24-
},
25-
"spj_config": {
26-
"exe_name": "spj-{spj_version}",
27-
"command": "{exe_path} {in_file_path} {user_out_file_path}",
28-
"seccomp_rule": "c_cpp"
15+
"seccomp_rule": "c_cpp",
2916
}
3017
}
3118

19+
c_lang_spj_compile = {
20+
"src_name": "spj-{spj_version}.c",
21+
"exe_name": "spj-{spj_version}",
22+
"max_cpu_time": 3000,
23+
"max_real_time": 5000,
24+
"max_memory": 1024 * 1024 * 1024,
25+
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}"
26+
}
27+
28+
c_lang_spj_config = {
29+
"exe_name": "spj-{spj_version}",
30+
"command": "{exe_path} {in_file_path} {user_out_file_path}",
31+
"seccomp_rule": "c_cpp"
32+
}
3233

3334
cpp_lang_config = {
3435
"name": "cpp",
@@ -42,12 +43,10 @@
4243
},
4344
"run": {
4445
"command": "{exe_path}",
45-
"seccomp_rule": "c_cpp",
46-
"max_process_number": -1
46+
"seccomp_rule": "c_cpp"
4747
}
4848
}
4949

50-
5150
java_lang_config = {
5251
"name": "java",
5352
"compile": {
@@ -61,6 +60,6 @@
6160
"run": {
6261
"command": "/usr/bin/java -cp {exe_dir} -Xss1M -XX:MaxPermSize=16M -XX:PermSize=8M -Xms16M -Xmx{max_memory}k -Djava.security.manager -Djava.security.policy==/etc/java_policy -Djava.awt.headless=true Main",
6362
"seccomp_rule": None,
64-
"max_process_number": -1
63+
"env": ["MALLOC_ARENA_MAX=1"]
6564
}
6665
}

judge_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def _judge_one(self, test_case_file_id):
9595
command = self._run_config["command"].format(exe_path=self._exe_path, exe_dir=os.path.dirname(self._exe_path),
9696
max_memory=self._max_memory / 1024).split(" ")
9797
seccomp_rule_name = self._run_config["seccomp_rule"].encode("utf-8") if self._run_config["seccomp_rule"] else None
98+
env = [item.encode("utf-8") for item in ["PATH=" + os.environ.get("PATH", "")] + self._run_config.get("env", [])]
9899

99100
run_result = _judger.run(max_cpu_time=self._max_cpu_time,
100101
max_real_time=self._max_real_time,
@@ -106,7 +107,7 @@ def _judge_one(self, test_case_file_id):
106107
output_path=out_file,
107108
error_path=out_file,
108109
args=[item.encode("utf-8") for item in command[1::]],
109-
env=[("PATH=" + os.getenv("PATH", "")).encode("utf-8")],
110+
env=env,
110111
log_path=JUDGER_RUN_LOG_PATH,
111112
seccomp_rule_name=seccomp_rule_name,
112113
uid=LOW_PRIVILEDGE_UID,

0 commit comments

Comments
 (0)