mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-28 07:51:42 +00:00
commit
de5f087bd7
@ -100,7 +100,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
}
|
||||
|
||||
void *handler = dlopen("/usr/lib/judger/libjudger.so", RTLD_LAZY);
|
||||
int (*judger_run)(struct config *, struct result *);
|
||||
void (*judger_run)(struct config *, struct result *);
|
||||
|
||||
if (!handler) {
|
||||
RaiseValueError("dlopen error")
|
||||
|
13
src/child.c
13
src/child.c
@ -36,13 +36,15 @@ void close_file(FILE *fp, ...) {
|
||||
}
|
||||
|
||||
|
||||
int child_process(FILE *log_fp, struct config *_config) {
|
||||
void child_process(FILE *log_fp, struct config *_config) {
|
||||
FILE *input_file = NULL, *output_file = NULL, *error_file = NULL;
|
||||
|
||||
struct rlimit max_stack;
|
||||
max_stack.rlim_cur = max_stack.rlim_max = (rlim_t) (_config->max_stack);
|
||||
if (setrlimit(RLIMIT_STACK, &max_stack) != 0) {
|
||||
CHILD_ERROR_EXIT(SETRLIMIT_FAILED);
|
||||
if (_config->max_stack != UNLIMITED) {
|
||||
struct rlimit max_stack;
|
||||
max_stack.rlim_cur = max_stack.rlim_max = (rlim_t) (_config->max_stack);
|
||||
if (setrlimit(RLIMIT_STACK, &max_stack) != 0) {
|
||||
CHILD_ERROR_EXIT(SETRLIMIT_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
// set memory limit
|
||||
@ -157,5 +159,4 @@ int child_process(FILE *log_fp, struct config *_config) {
|
||||
|
||||
execve(_config->exe_path, _config->args, _config->env);
|
||||
CHILD_ERROR_EXIT(EXECVE_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,10 +9,10 @@
|
||||
LOG_FATAL(log_fp, "Error: System errno: %s; Internal errno: "#error_code, strerror(errno)); \
|
||||
close_file(input_file, output_file, error_file); \
|
||||
raise(SIGUSR1); \
|
||||
return -1; \
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
|
||||
|
||||
int child_process(FILE *log_fp, struct config *_config);
|
||||
void child_process(FILE *log_fp, struct config *_config);
|
||||
|
||||
#endif //JUDGER_CHILD_H
|
||||
|
@ -19,7 +19,7 @@ void log_write(int level, const char *source_filename, const int line_number, co
|
||||
#define LOG_DEBUG(log_fp, x...)
|
||||
#endif
|
||||
|
||||
#define LOG_INFO(log_fp, x...) log_write(LOG_LEVEL_INFO, __FILE__ __LINE__, log_fp, ##x)
|
||||
#define LOG_INFO(log_fp, x...) log_write(LOG_LEVEL_INFO, __FILE__, __LINE__, log_fp, ##x)
|
||||
#define LOG_WARNING(log_fp, x...) log_write(LOG_LEVEL_WARNING, __FILE__, __LINE__, log_fp, ##x)
|
||||
#define LOG_FATAL(log_fp, x...) log_write(LOG_LEVEL_FATAL, __FILE__, __LINE__, log_fp, ##x)
|
||||
|
||||
|
52
src/runner.c
52
src/runner.c
@ -97,18 +97,23 @@ void run(struct config *_config, struct result *_result) {
|
||||
};
|
||||
}
|
||||
|
||||
_result->exit_code = WEXITSTATUS(status);
|
||||
_result->cpu_time = (int) (resource_usage.ru_utime.tv_sec * 1000 +
|
||||
resource_usage.ru_utime.tv_usec / 1000);
|
||||
_result->memory = resource_usage.ru_maxrss * 1024;
|
||||
|
||||
if (_result->exit_code != 0) {
|
||||
_result->result = RUNTIME_ERROR;
|
||||
}
|
||||
// if signaled
|
||||
if (WIFSIGNALED(status) != 0) {
|
||||
LOG_DEBUG(log_fp, "signal: %d", WTERMSIG(status));
|
||||
_result->signal = WTERMSIG(status);
|
||||
}
|
||||
|
||||
if(_result->signal == SIGUSR1) {
|
||||
_result->result = SYSTEM_ERROR;
|
||||
}
|
||||
else {
|
||||
_result->exit_code = WEXITSTATUS(status);
|
||||
_result->cpu_time = (int) (resource_usage.ru_utime.tv_sec * 1000 +
|
||||
resource_usage.ru_utime.tv_usec / 1000);
|
||||
_result->memory = resource_usage.ru_maxrss * 1024;
|
||||
|
||||
if (_result->exit_code != 0) {
|
||||
_result->result = RUNTIME_ERROR;
|
||||
}
|
||||
|
||||
if (_result->signal == SIGSEGV) {
|
||||
if (_config->max_memory != UNLIMITED && _result->memory > _config->max_memory) {
|
||||
_result->result = MEMORY_LIMIT_EXCEEDED;
|
||||
@ -117,24 +122,21 @@ void run(struct config *_config, struct result *_result) {
|
||||
_result->result = RUNTIME_ERROR;
|
||||
}
|
||||
}
|
||||
else if(_result->signal == SIGUSR1) {
|
||||
_result->result = SYSTEM_ERROR;
|
||||
}
|
||||
else {
|
||||
_result->result = RUNTIME_ERROR;
|
||||
if (_result->signal != 0) {
|
||||
_result->result = RUNTIME_ERROR;
|
||||
}
|
||||
if (_config->max_memory != UNLIMITED && _result->memory > _config->max_memory) {
|
||||
_result->result = MEMORY_LIMIT_EXCEEDED;
|
||||
}
|
||||
if (_config->max_real_time != UNLIMITED && _result->real_time > _config->max_real_time) {
|
||||
_result->result = REAL_TIME_LIMIT_EXCEEDED;
|
||||
}
|
||||
if (_config->max_cpu_time != UNLIMITED && _result->cpu_time > _config->max_cpu_time) {
|
||||
_result->result = CPU_TIME_LIMIT_EXCEEDED;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_config->max_memory != UNLIMITED && _result->memory > _config->max_memory) {
|
||||
_result->result = MEMORY_LIMIT_EXCEEDED;
|
||||
}
|
||||
}
|
||||
if (_config->max_real_time != UNLIMITED && _result->real_time > _config->max_real_time) {
|
||||
_result->result = REAL_TIME_LIMIT_EXCEEDED;
|
||||
}
|
||||
if (_config->max_cpu_time != UNLIMITED && _result->cpu_time > _config->max_cpu_time) {
|
||||
_result->result = CPU_TIME_LIMIT_EXCEEDED;
|
||||
}
|
||||
|
||||
log_close(log_fp);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user