增加可以更改log文件的功能,默认log文件是judger.log

This commit is contained in:
spxcds 2016-04-26 09:50:28 +08:00
parent 9958ef7c14
commit a29925b48d
6 changed files with 21 additions and 8 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ main
demo
.DS_Store
judger.log
*.swp

View File

@ -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)

View File

@ -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");
}

View File

@ -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

View File

@ -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"

View File

@ -49,6 +49,7 @@ struct config {
char *env[100];
int use_sandbox;
int use_nobody;
char *log_path;
};