end
return nitc
end
+
+ # Execute a system command in a more safe context than `Sys::system`.
+ fun safe_exec(command: String): Int
+ do
+ info(command, 2)
+ var real_command = """
+bash -c "
+ulimit -f {{{ulimit_file}}} 2> /dev/null
+ulimit -t {{{ulimit_usertime}}} 2> /dev/null
+{{{command}}}
+"
+"""
+ return system(real_command)
+ end
+
+ # The maximum size (in KB) of files written by a command executed trough `safe_exec`
+ #
+ # Default: 64MB
+ var ulimit_file = 65536 is writable
+
+ # The maximum amount of cpu time (in seconds) for a command executed trough `safe_exec`
+ #
+ # Default: 10 CPU minute
+ var ulimit_usertime = 600 is writable
end
toolcontext.modelbuilder.unit_entities += 1
i += 1
toolcontext.info("Execute doc-unit {du.testcase.attrs["name"]} in {file} {i}", 1)
- var res2 = sys.system("{file.to_program_name}.bin {i} >>'{file}.out1' 2>&1 </dev/null")
+ var res2 = toolcontext.safe_exec("{file.to_program_name}.bin {i} >'{file}.out1' 2>&1 </dev/null")
var msg
f = new FileReader.open("{file}.out1")
var res = compile_unitfile(file)
var res2 = 0
if res == 0 then
- res2 = sys.system("{file.to_program_name}.bin >>'{file}.out1' 2>&1 </dev/null")
+ res2 = toolcontext.safe_exec("{file.to_program_name}.bin >'{file}.out1' 2>&1 </dev/null")
end
var msg
opts.add "-I {mmodule.filepath.dirname}"
end
var cmd = "{nitc} --ignore-visibility --no-color '{file}' {opts.join(" ")} >'{file}.out1' 2>&1 </dev/null -o '{file}.bin'"
- var res = sys.system(cmd)
+ var res = toolcontext.safe_exec(cmd)
return res
end
end
end
var include_dir = module_file.filename.dirname
var cmd = "{nitc} --no-color '{file}.nit' -I {include_dir} -o '{file}.bin' > '{file}.out' 2>&1 </dev/null"
- var res = sys.system(cmd)
+ var res = toolcontext.safe_exec(cmd)
var f = new FileReader.open("{file}.out")
var msg = f.read_all
f.close
var method_name = test_method.name
var test_file = test_suite.test_file
var res_name = "{test_file}_{method_name.escape_to_c}"
- var res = sys.system("{test_file}.bin {method_name} > '{res_name}.out1' 2>&1 </dev/null")
+ var res = toolcontext.safe_exec("{test_file}.bin {method_name} > '{res_name}.out1' 2>&1 </dev/null")
var f = new FileReader.open("{res_name}.out1")
var msg = f.read_all
f.close