mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-29 00:11:41 +00:00
增加可以更改log文件的功能,默认log文件是judger.log
This commit is contained in:
parent
9958ef7c14
commit
a29925b48d
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ main
|
||||
demo
|
||||
.DS_Store
|
||||
judger.log
|
||||
*.swp
|
||||
|
@ -13,7 +13,8 @@ def _compile():
|
||||
max_memory=judger.MEMORY_UNLIMITED,
|
||||
args=[os.path.join(base_path, "demo.c"), "-o", os.path.join(base_path, "demo")],
|
||||
env=["PATH=" + os.environ["PATH"]],
|
||||
use_sandbox=False,
|
||||
use_sandbox=False,
|
||||
log_path="test.log",
|
||||
use_nobody=False)
|
||||
|
||||
|
||||
|
18
judger.c
18
judger.c
@ -10,15 +10,15 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
struct config config;
|
||||
struct result result = {0, 0, 0, 0, 0, 0};
|
||||
PyObject *args_list = NULL, *env_list = NULL, *use_sandbox = NULL, *use_nobody = NULL,
|
||||
*next = NULL, *args_iter = NULL, *env_iter = NULL;
|
||||
*next = NULL, *args_iter = NULL, *env_iter = NULL, *log_path = NULL;
|
||||
int count = 0;
|
||||
static char *kwargs_list[] = {"path", "in_file", "out_file", "max_cpu_time",
|
||||
"max_memory", "args", "env", "use_sandbox", "use_nobody", NULL};
|
||||
"max_memory", "args", "env", "use_sandbox", "use_nobody", "log_path", NULL};
|
||||
|
||||
config.path = config.in_file = config.out_file = NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sssil|OOOO", kwargs_list, &(config.path), &(config.in_file),
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sssil|OOOOO", kwargs_list, &(config.path), &(config.in_file),
|
||||
&(config.out_file), &(config.max_cpu_time), &(config.max_memory),
|
||||
&args_list, &env_list, &use_sandbox, &use_nobody)) {
|
||||
&args_list, &env_list, &use_sandbox, &use_nobody, &log_path)) {
|
||||
RaiseValueError("Invalid args and kwargs");
|
||||
}
|
||||
if (config.max_cpu_time < 1 && config.max_cpu_time != CPU_TIME_UNLIMITED) {
|
||||
@ -100,6 +100,16 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
config.use_nobody = 1;
|
||||
}
|
||||
|
||||
if (log_path != NULL) {
|
||||
if (!PyString_Check(log_path)) {
|
||||
RaiseValueError("log path must be a string");
|
||||
}
|
||||
config.log_path = PyString_AsString(log_path);
|
||||
}
|
||||
else {
|
||||
config.log_path = "judger.log";
|
||||
}
|
||||
|
||||
if(config.use_nobody && getuid() != 0) {
|
||||
RaiseValueError("Root user is required when use_nobody=True");
|
||||
}
|
||||
|
2
logger.h
2
logger.h
@ -149,4 +149,4 @@ void log_add_info(const char *info)
|
||||
snprintf(log_extra_info + len, log_buffer_size - len, "\n [%s]", info);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
4
runner.c
4
runner.c
@ -46,8 +46,8 @@ void run(struct config *config, struct result *result) {
|
||||
|
||||
int syscalls_whitelist_length = sizeof(syscalls_whitelist) / sizeof(int);
|
||||
scmp_filter_ctx ctx = NULL;
|
||||
|
||||
log_open("judger.log");
|
||||
|
||||
log_open(config->log_path);
|
||||
|
||||
#ifdef __APPLE__
|
||||
#warning "setrlimit with RLIMIT_AS to limit memory usage will not work on OSX"
|
||||
|
Loading…
Reference in New Issue
Block a user