Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改部分日志提示中错误的单词 #15

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
Core
test/
run_dir/
.idea/
61 changes: 34 additions & 27 deletions core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ void parse_arguments(int argc, char* argv[]) {

while ((opt = getopt(argc, argv, "c:t:m:d:S:s")) != -1) {
switch (opt) {
case 'c': PROBLEM::code_path = optarg; break;
case 't': PROBLEM::time_limit = atoi(optarg); break;
case 'm': PROBLEM::memory_limit = atoi(optarg); break;
case 's': PROBLEM::spj = true; break;
case 'S': PROBLEM::spj_lang = atoi(optarg); break;
case 'd': PROBLEM::run_dir = optarg; break;
case 'c': PROBLEM::code_path = optarg; break; // 待评测的代码路径
case 't': PROBLEM::time_limit = atoi(optarg); break; // 时间限制 单位MS
case 'm': PROBLEM::memory_limit = atoi(optarg); break; // 内存限制 单位KB
case 's': PROBLEM::spj = true; break; // 是否使用SpecialJudge
case 'S': PROBLEM::spj_lang = atoi(optarg); break; // SPJ的语言类型
case 'd': PROBLEM::run_dir = optarg; break; // 运行在什么文件夹,沙箱
default:
FM_LOG_WARNING("Unknown option provided: -%c %s", opt, optarg);
exit(JUDGE_CONF::EXIT_BAD_PARAM);
}
}

// 判断语言类型
if (has_suffix(PROBLEM::code_path, ".cpp")) {
PROBLEM::lang = JUDGE_CONF::LANG_CPP;
} else if (has_suffix(PROBLEM::code_path, ".c")) {
Expand Down Expand Up @@ -108,7 +108,7 @@ void parse_arguments(int argc, char* argv[]) {
case 2: PROBLEM::spj_exec_file = PROBLEM::run_dir + "/SpecialJudge";break;
case 3: PROBLEM::spj_exec_file = PROBLEM::run_dir + "/SpecialJudge";break;
default:
FM_LOG_WARNING("OMG, I really do not kwon the special judge problem language.");
FM_LOG_WARNING("OMG, I really do not know the special judge problem language.");
exit(JUDGE_CONF::EXIT_BAD_PARAM);
}

Expand All @@ -135,7 +135,12 @@ void timeout(int signo) {
exit(JUDGE_CONF::EXIT_TIMEOUT);
}
}

/**
* 设置编译时间限制
* @param which
* @param milliseconds
* @return
*/
static
int malarm(int which, int milliseconds) {
struct itimerval t;
Expand All @@ -147,7 +152,7 @@ int malarm(int which, int milliseconds) {
return setitimer(which, &t, NULL);
}

/*
/**
* 输入输出重定向
*/
static
Expand All @@ -164,25 +169,27 @@ void io_redirect() {
FM_LOG_TRACE("redirect io is OK.");
}

/*
/**
* 安全性控制
* chroot限制程序只能在某目录下操作,无法影响到外界
* setuid使其只拥有nobody的最低系统权限
*/
static
void security_control() {
// 获得用户的登录信息
struct passwd *nobody = getpwnam("nobody");
// nobody 不存在报错
if (nobody == NULL){
FM_LOG_WARNING("Well, where is nobody? I cannot live without him. %d: %s", errno, strerror(errno));
exit(JUDGE_CONF::EXIT_SET_SECURITY);
}

//chdir
//chdir 沙箱目录不存在报错
if (EXIT_SUCCESS != chdir(PROBLEM::run_dir.c_str())) {
FM_LOG_WARNING("chdir(%s) failed, %d: %s", PROBLEM::run_dir.c_str(), errno, strerror(errno));
exit(JUDGE_CONF::EXIT_SET_SECURITY);
}

// 获取当前目录的绝对路径
char cwd[1024], *tmp = getcwd(cwd, 1024);
if (tmp == NULL) {
FM_LOG_WARNING("Oh, where i am now? I cannot getcwd. %d: %s", errno, strerror(errno));
Expand Down Expand Up @@ -297,7 +304,7 @@ static bool in_syscall = true;
static
bool is_valid_syscall(int lang, int syscall_id, pid_t child, user_regs_struct regs) {
in_syscall = !in_syscall;
//FM_LOG_DEBUG("syscall: %d, %s, count: %d", syscall_id, in_syscall?"in":"out", RF_table[syscall_id]);
FM_LOG_DEBUG("syscall: %d, %s, count: %d", syscall_id, in_syscall?"in":"out", RF_table[syscall_id]);
if (RF_table[syscall_id] == 0)
{
//如果RF_table中对应的syscall_id可以被调用的次数为0, 则为RF
Expand Down Expand Up @@ -344,7 +351,7 @@ bool is_valid_syscall(int lang, int syscall_id, pid_t child, user_regs_struct re
} else if (RF_table[syscall_id] > 0) {
//如果RF_table中对应的syscall_id可被调用的次数>0
//且是在退出syscall的时候, 那么次数减一
if (in_syscall == false)
if (!in_syscall)
RF_table[syscall_id]--;
} else {
//RF_table中syscall_id对应的指<0, 表示是不限制调用的
Expand Down Expand Up @@ -431,7 +438,7 @@ void compiler_source_code() {
} else if (WIFSTOPPED(status)){
FM_LOG_WARNING("The compile process stopped by signal");
} else {
FM_LOG_WARNING("I don't kwon why the compile process stopped");
FM_LOG_WARNING("I don't know why the compile process stopped");
}
exit(JUDGE_CONF::EXIT_COMPILE);
}
Expand Down Expand Up @@ -495,7 +502,7 @@ void judge() {

//PROBLEM::result = JUDGE_CONF::PROCEED;
} else {
FM_LOG_WARNING("oh, some error occured.Abnormal quit.");
FM_LOG_WARNING("oh, some error occurred.Abnormal quit.");
PROBLEM::result = JUDGE_CONF::RE;
}
break;
Expand All @@ -519,7 +526,7 @@ void judge() {
case SIGXCPU:
case SIGVTALRM:
case SIGKILL:
FM_LOG_TRACE("Well, Time Limit Exeeded");
FM_LOG_TRACE("Well, Time Limit Exceeded");
PROBLEM::time_usage = 0;
PROBLEM::memory_usage = 0;
PROBLEM::result = JUDGE_CONF::TLE;
Expand All @@ -534,13 +541,13 @@ void judge() {
case SIGFPE:
case SIGBUS:
case SIGABRT:
//FM_LOG_TRACE("RE了");
FM_LOG_TRACE("RE了");
PROBLEM::time_usage = 0;
PROBLEM::memory_usage = 0;
PROBLEM::result = JUDGE_CONF::RE;
break;
default:
//FM_LOG_TRACE("不知道哪儿跪了");
FM_LOG_TRACE("不知道哪儿跪了");
PROBLEM::time_usage = 0;
PROBLEM::memory_usage = 0;
PROBLEM::result = JUDGE_CONF::RE;
Expand All @@ -566,7 +573,7 @@ void judge() {

//获得子进程的寄存器,目的是为了获知其系统调用
if (ptrace(PTRACE_GETREGS, executive, NULL, &regs) < 0) {
FM_LOG_WARNING("ptrace PTRACE_GETREGS failed");
FM_LOG_WARNING("ptrace PTRACE_GETARGS failed");
exit(JUDGE_CONF::EXIT_JUDGE);
}

Expand All @@ -578,12 +585,12 @@ void judge() {
//检查系统调用是否合法
if (syscall_id > 0 &&
!is_valid_syscall(PROBLEM::lang, syscall_id, executive, regs)) {
FM_LOG_WARNING("restricted fuction %d\n", syscall_id);
FM_LOG_WARNING("restricted function %d\n", syscall_id);
if (syscall_id == SYS_rt_sigprocmask){
FM_LOG_WARNING("The glibc failed.");
} else {
//FM_LOG_WARNING("%d\n", SYS_write);
FM_LOG_WARNING("restricted fuction table");
FM_LOG_WARNING("%d\n", is_valid_syscall(PROBLEM::lang, syscall_id, executive, regs));
FM_LOG_WARNING("restricted function table");
}
PROBLEM::result = JUDGE_CONF::RE;
ptrace(PTRACE_KILL, executive, NULL, NULL);
Expand Down Expand Up @@ -777,13 +784,15 @@ void run_spj() {
} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGALRM) {
FM_LOG_WARNING("Well, the special judge program consume too much time.");
} else {
FM_LOG_WARNING("Actually, I do not kwon why the special judge program dead.");
FM_LOG_WARNING("Actually, I do not know why the special judge program dead.");
}
}
}

int main(int argc, char *argv[]) {

parse_arguments(argc, argv);

log_open("./core_log.txt"); //或许写成参数更好,懒得写了

atexit(output_result); //退出程序时的回调函数,用于输出判题结果
Expand All @@ -794,8 +803,6 @@ int main(int argc, char *argv[]) {
exit(JUDGE_CONF::EXIT_UNPRIVILEGED);
}

parse_arguments(argc, argv);

JUDGE_CONF::JUDGE_TIME_LIMIT += PROBLEM::time_limit;

if (EXIT_SUCCESS != malarm(ITIMER_REAL, JUDGE_CONF::JUDGE_TIME_LIMIT)) {
Expand Down
3 changes: 1 addition & 2 deletions core.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ const int LANG_UNKNOWN = 0;
const int LANG_C = 1;
const int LANG_CPP = 2;
const int LANG_JAVA = 3;

}

namespace PROBLEM
{
int id = 0; //貌似没用上
int lang = 0; //待评测的程序语言
int spj_lang = 0; //SpecialJudge程序的语言
int time_limit = 1000; //MS
int time_limit = 1000; //MS 毫秒
int memory_limit = 65535; //KB
int output_limit = 1024000; //KB,输出文件的大小限制
int result = JUDGE_CONF::SE; //结果代号
Expand Down
6 changes: 4 additions & 2 deletions rf_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int RF_C[512] =
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
201, -1,
201, -1,
-1
};

Expand All @@ -72,7 +72,7 @@ int RF_CPP[512] =
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
201, -1,
201, -1,
-1
};

Expand Down Expand Up @@ -137,6 +137,7 @@ int RF_JAVA[512] =
SYS_stat64, -1,
SYS_ugetrlimit, -1,
SYS_uname, -1,
SYS_prctl, -1,
-1
};

Expand Down Expand Up @@ -252,6 +253,7 @@ int RF_JAVA[512] =
SYS_writev, -1,
SYS_time, -1,
SYS_readlink, -1,
SYS_prctl, -1,
-1
};
#endif
Expand Down