使用原生fork模式

This commit is contained in:
LiYang 2016-10-07 19:25:55 +08:00
parent 191b4bda0d
commit de0b62e61a
5 changed files with 9 additions and 28 deletions

View File

@ -93,7 +93,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
}
else {
// fixme decref
RaiseValueError("seccomp_rule_so_path must be string or None");
RaiseValueError("seccomp_rule_name must be string or None");
}
}

View File

@ -36,10 +36,8 @@ void close_file(FILE *fp, ...) {
}
int child_process(void *args) {
FILE *log_fp = ((child_args *) args)->log_fp;
int child_process(FILE *log_fp, struct config *_config) {
FILE *input_file = NULL, *output_file = NULL, *error_file = NULL;
struct config *_config = ((child_args *) args)->_config;
// set memory limit
if (_config->max_memory != UNLIMITED) {
@ -132,7 +130,7 @@ int child_process(void *args) {
CHILD_ERROR_EXIT(SETUID_FAILED);
}
// load seccomp so
// load seccomp
if (_config->seccomp_rule_name != NULL) {
if (strcmp("c_cpp", _config->seccomp_rule_name) == 0) {
if (c_cpp_seccomp_rules(_config) != SUCCESS) {

View File

@ -12,6 +12,6 @@
}
int child_process(void *config);
int child_process(FILE *log_fp, struct config *_config);
#endif //JUDGER_CHILD_H

View File

@ -19,8 +19,6 @@
#include "child.h"
#include "logger.h"
#define STACK_SIZE (32 * 1024 * 1024)
void init_result(struct result *_result) {
_result->error = SUCCESS;
_result->cpu_time = _result->real_time = _result->signal = _result->exit_code = 0;
@ -50,29 +48,20 @@ void run(struct config *_config, struct result *_result) {
ERROR_EXIT(INVALID_CONFIG);
}
// malloc stack for child process
char *stack = NULL;
stack = malloc(STACK_SIZE);
if (stack == NULL) {
ERROR_EXIT(CLONE_FAILED);
}
// record current time
struct timeval start, end;
gettimeofday(&start, NULL);
// clone
child_args args;
args._config = _config;
args.log_fp = log_fp;
pid_t child_pid = clone(child_process, stack + STACK_SIZE, SIGCHLD, (void *) (&args));
pid_t child_pid = fork();
// pid < 0 shows clone failed
if (child_pid < 0) {
ERROR_EXIT(CLONE_FAILED);
}
else {
else if (child_pid == 0) {
child_process(log_fp, _config);
}
else if (child_pid > 0){
// create new thread to monitor process running time
pthread_t tid = 0;
if (_config->max_real_time != UNLIMITED) {

View File

@ -76,11 +76,5 @@ struct result {
};
typedef struct child_args {
FILE *log_fp;
struct config *_config;
} child_args;
void run(struct config *, struct result *);
#endif //JUDGER_RUNNER_H