aboutsummaryrefslogtreecommitdiffstats
path: root/toj/center
diff options
context:
space:
mode:
authorpzread <netfirewall@gmail.com>2013-06-09 12:20:09 +0800
committerpzread <netfirewall@gmail.com>2013-06-09 12:20:09 +0800
commit872567a4cf3bff7d9d310f5e66f465f5523d58d9 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /toj/center
parent213e4bc6a87d29e847ca8cdf18b5ddf0fa5b299b (diff)
downloadtaiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.tar
taiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.tar.gz
taiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.tar.bz2
taiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.tar.lz
taiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.tar.xz
taiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.tar.zst
taiwan-online-judge-872567a4cf3bff7d9d310f5e66f465f5523d58d9.zip
Clear master
Diffstat (limited to 'toj/center')
-rwxr-xr-xtoj/center/pro/packpro.sh3
-rwxr-xr-xtoj/center/src/Makefile27
-rwxr-xr-xtoj/center/src/center.h47
-rwxr-xr-xtoj/center/src/center_com.h70
-rwxr-xr-xtoj/center/src/center_judge.cpp578
-rwxr-xr-xtoj/center/src/center_judge.h106
-rwxr-xr-xtoj/center/src/center_manage.cpp640
-rwxr-xr-xtoj/center/src/center_manage.h75
-rwxr-xr-xtoj/center/src/center_server.cpp198
-rwxr-xr-xtoj/center/src/center_server.h45
-rwxr-xr-xtoj/center/src/hyperio/Makefile13
-rwxr-xr-xtoj/center/src/hyperio/hyperio_mod.c58
-rwxr-xr-xtoj/center/src/hyperio/hyperio_mod.h21
-rwxr-xr-xtoj/center/src/hyperio/test.cpp173
-rwxr-xr-xtoj/center/src/jmod_test.h17
-rwxr-xr-xtoj/center/src/jmod_test_check.cpp109
-rwxr-xr-xtoj/center/src/jmod_test_check.h4
-rwxr-xr-xtoj/center/src/jmod_test_line.cpp190
-rwxr-xr-xtoj/center/src/jmod_test_line.h11
-rwxr-xr-xtoj/center/src/jmod_test_manage.cpp96
-rwxr-xr-xtoj/center/src/jmod_test_manage.h35
-rw-r--r--toj/center/src/judge.h50
-rwxr-xr-xtoj/center/src/judge_def.h21
-rw-r--r--toj/center/src/judge_manage.cpp371
-rw-r--r--toj/center/src/judge_manage.h60
-rwxr-xr-xtoj/center/src/judge_server.cpp515
-rwxr-xr-xtoj/center/src/judge_server.h87
-rwxr-xr-xtoj/center/src/judgk.h16
-rwxr-xr-xtoj/center/src/judgk_com.h25
-rwxr-xr-xtoj/center/src/judgk_hyperio.c413
-rwxr-xr-xtoj/center/src/judgk_hyperio.h53
-rwxr-xr-xtoj/center/src/judgk_mod.c75
-rwxr-xr-xtoj/center/src/judgk_mod.h31
-rwxr-xr-xtoj/center/src/judgk_proc.c248
-rwxr-xr-xtoj/center/src/judgk_proc.h18
-rwxr-xr-xtoj/center/src/judgk_security.c309
-rwxr-xr-xtoj/center/src/judgk_security.h25
-rw-r--r--toj/center/src/judgk_security_asm.S57
-rwxr-xr-xtoj/center/src/judgk_syscall.c235
-rwxr-xr-xtoj/center/src/judgk_syscall.h69
-rwxr-xr-xtoj/center/src/judgk_syscall_asm.S54
-rwxr-xr-xtoj/center/src/judgm_lib.h419
-rwxr-xr-xtoj/center/src/judgm_line.h19
-rwxr-xr-xtoj/center/src/judgm_manage.h29
-rwxr-xr-xtoj/center/src/netio.h192
-rw-r--r--toj/center/src/tool.cpp296
-rw-r--r--toj/center/src/tool.h26
-rwxr-xr-xtoj/center/src/tpool.h175
48 files changed, 0 insertions, 6404 deletions
diff --git a/toj/center/pro/packpro.sh b/toj/center/pro/packpro.sh
deleted file mode 100755
index b53a707..0000000
--- a/toj/center/pro/packpro.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-tar -jcvf ../tmp/propack/$1.tar.bz2 -C $1 .
diff --git a/toj/center/src/Makefile b/toj/center/src/Makefile
deleted file mode 100755
index 17cbcf3..0000000
--- a/toj/center/src/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-ifneq ($(KERNELRELEASE),)
- judgk-objs := judgk_mod.o judgk_proc.o judgk_syscall.o judgk_syscall_asm.o judgk_security.o judgk_security_asm.o judgk_hyperio.o
- obj-m := judgk.o
-else
- KERNEL_SOURCE := /lib/modules/$(shell uname -r)/build
- PWD := $(shell pwd)
-default:
- ${MAKE} -C ${KERNEL_SOURCE} M=${PWD} modules
- mv judgk.ko ../judge/
-
- g++ -g -rdynamic -fvisibility=hidden -O2 center_server.cpp center_manage.cpp center_judge.cpp tool.cpp /srv/http/toj/php/event_exec.cpp -ldl -lpq -ltar -lbz2 -ljson -lcurl -pthread -o center_server
- g++ -g -O2 judge_server.cpp judge_manage.cpp tool.cpp -ldl -lbz2 -ltar -pthread -o judge_server
- mv center_server ../
- mv judge_server ../judge/
-
- g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_manage.cpp -ldl -ljson -pthread -o jmod_test_manage.so
- g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_line.cpp -ljson -pthread -o jmod_test_line.so
- g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_check.cpp -o jmod_test_check.so
- mv jmod_test_manage.so ../jmod/jmod_test/
- mv jmod_test_line.so ../jmod/jmod_test/
- mv jmod_test_check.so ../jmod/jmod_test/
- tar -jcvf ../tmp/jmodpack/jmod_test.tar.bz2 -C ../jmod/jmod_test .
-
- g++ -shared -fPIC -fvisibility=hidden -O2 sprout_tar_check.cpp -o ../pro/15/private/check.so
-clean:
- ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
-endif
diff --git a/toj/center/src/center.h b/toj/center/src/center.h
deleted file mode 100755
index 2625ab4..0000000
--- a/toj/center/src/center.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#define CENTER_CACHESTATE_READY 0
-#define CENTER_CACHESTATE_UPDATE 1
-
-class center_jmod_info{
-public:
- char name[NAME_MAX + 1];
- int cacheid;
- void *manage_dll;
- void *manage_sub_fn;
- void *manage_res_fn;
-
- int ref_count;
- int state;
- int update_cacheid;
-
- center_jmod_info(char *name,int cacheid){
- this->name[0] = '\0';
- strncat(this->name,name,sizeof(this->name));
- this->cacheid = cacheid;
- this->manage_dll = NULL;
- this->manage_sub_fn = NULL;
- this->manage_res_fn = NULL;
- }
-};
-
-class center_pro_info{
-public:
- int proid;
- int cacheid;
- center_jmod_info *jmod_info;
- int lang_flag;
-
- int ref_count;
- int state;
- int update_cacheid;
-
- center_pro_info(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag){
- this->proid = proid;
- this->cacheid = cacheid;
- this->jmod_info = jmod_info;
- this->lang_flag = lang_flag;
-
- this->ref_count = 0;
- this->state = CENTER_CACHESTATE_READY;
- this->update_cacheid = 0;
- }
-};
diff --git a/toj/center/src/center_com.h b/toj/center/src/center_com.h
deleted file mode 100755
index 6973eec..0000000
--- a/toj/center/src/center_com.h
+++ /dev/null
@@ -1,70 +0,0 @@
-#define CENTER_COMCODE_SETID 1
-#define CENTER_COMCODE_SETINFO 2
-#define CENTER_COMCODE_SUBMIT 3
-#define CENTER_COMCODE_RESULT 4
-
-#define CENTER_COMCODE_SETPRO 10
-#define CENTER_COMCODE_REQPRO 11
-#define CENTER_COMCODE_SENDPRO 12
-#define CENTER_COMCODE_SETJMOD 13
-#define CENTER_COMCODE_REQJMOD 14
-#define CENTER_COMCODE_SENDJMOD 15
-
-#define CENTER_COMCODE_REQCODE 20
-#define CENTER_COMCODE_SENDCODE 21
-
-struct center_com_header{
- int code;
- int size;
-}__attribute__((packed));
-struct center_com_setid{
- int id; //0:new judge
-}__attribute__((packed));
-struct center_com_setinfo{
- int avail;
-}__attribute__((packed));
-struct center_com_submit{ //judt submit header
- int subid;
- int proid;
- int lang;
-}__attribute__((packed));
-struct center_com_result{ //just result header
- int subid;
-}__attribute__((packed));
-
-struct center_com_setpro{
- int proid;
- int cacheid;
- int type; //0:add problem 1:drop problem
-}__attribute__((packed));
-struct center_com_reqpro{
- int proid;
- int cacheid;
-}__attribute__((packed));
-struct center_com_sendpro{
- int proid;
- int cacheid;
- size_t filesize;
-}__attribute__((packed));
-
-struct center_com_setjmod{
- char jmod_name[NAME_MAX + 1];
- int cacheid;
- int type; //0:add jmod 1:drop jmod
-}__attribute__((packed));
-struct center_com_reqjmod{
- char jmod_name[NAME_MAX + 1];
-}__attribute__((packed));
-struct center_com_sendjmod{
- char jmod_name[NAME_MAX + 1];
- int cacheid;
- size_t filesize;
-}__attribute__((packed));
-
-struct center_com_reqcode{
- int subid;
-}__attribute__((packed));
-struct center_com_sendcode{
- int subid;
- size_t filesize;
-}__attribute__((packed));
diff --git a/toj/center/src/center_judge.cpp b/toj/center/src/center_judge.cpp
deleted file mode 100755
index 46600c2..0000000
--- a/toj/center/src/center_judge.cpp
+++ /dev/null
@@ -1,578 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<unistd.h>
-#include<fcntl.h>
-#include<limits.h>
-#include<errno.h>
-#include<sys/stat.h>
-#include<sys/types.h>
-#include<sys/epoll.h>
-#include<sys/sendfile.h>
-#include<map>
-#include<list>
-#include<queue>
-#include<string>
-
-#include"netio.h"
-#include"judge_def.h"
-#include"judgm_manage.h"
-#include"center.h"
-#include"center_com.h"
-#include"center_judge.h"
-
-int judge_info::last_id = 0;
-judge_info::judge_info(){
- last_id++;
- this->id = last_id;
- this->avail = 0;
-
- judge_idmap.insert(std::pair<int,judge_info*>(id,this));
- judge_runlist.push_back(this);
- judge_it = judge_runlist.end();
- judge_it--;
-}
-judge_info::~judge_info(){
- judge_idmap.erase(id);
- judge_runlist.erase(judge_it);
-}
-int judge_info::setavail(int avail){
- int old;
-
- old = this->avail;
- this->avail = avail;
- if(this->avail > 0 && old <= 0){
- judge_runlist.erase(judge_it);
- judge_runlist.push_front(this);
- judge_it = judge_runlist.begin();
- }else if(this->avail <= 0 && old > 0){
- judge_runlist.erase(judge_it);
- judge_runlist.push_back(this);
- judge_it = judge_runlist.end();
- judge_it--;
- }
-
- return 0;
-}
-int judge_info::setinfo(int avail){
- setavail(avail);
- return 0;
-}
-int judge_info::submit(judge_submit_info *sub_info){
- setavail(avail - 1);
- conn_main->send_submit(sub_info);
- return 0;
-}
-int judge_info::result(int subid,char *res_data){
- setavail(avail + 1);
-
- printf("submitid:%d\n",subid);
- center_manage_result(subid,res_data);
-
- judge_run_waitqueue();
- return 0;
-}
-int judge_info::updatepro(std::vector<std::pair<int,int> > &pro_list){
- int i;
-
- for(i = 0;i < pro_list.size();i++){
- pro_map.erase(pro_list[i].first);
- }
- conn_main->send_setpro(pro_list,0);
-
- return 0;
-}
-int judge_info::updatejmod(std::vector<std::pair<char*,int> > &jmod_list){
- int i;
-
- for(i = 0;i < jmod_list.size();i++){
- jmod_map.erase(jmod_list[i].first);
- }
- conn_main->send_setjmod(jmod_list,0);
-
- return 0;
-}
-
-
-judge_conn::judge_conn(int fd):netio(fd){
- this->info = NULL;
- this->recv_dispatch_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_dispatch);
- this->recv_setid_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setid);
- this->recv_setinfo_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setinfo);
- this->recv_result_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_result);
- this->recv_setpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setpro);
- this->recv_reqpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqpro);
- this->done_sendpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::done_sendpro);
- this->recv_setjmod_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setjmod);
- this->recv_reqjmod_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqjmod);
- this->recv_reqcode_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqcode);
-}
-judge_conn::~judge_conn(){
- info->conn_list.erase(conn_it);
- if(info->conn_main == this){
- info->conn_main = NULL;
- }
- if(info->conn_list.empty()){
- delete info;
- }
-
- delete recv_dispatch_fn;
- delete recv_setid_fn;
- delete recv_setinfo_fn;
- delete recv_result_fn;
- delete recv_setpro_fn;
- delete recv_reqpro_fn;
- delete done_sendpro_fn;
- delete recv_setjmod_fn;
- delete recv_reqjmod_fn;
- delete recv_reqcode_fn;
-}
-char* judge_conn::create_combuf(int code,int size,int &len,void **data){
- char *buf;
- center_com_header *header;
-
- buf = new char[sizeof(center_com_header) + size];
- header = (center_com_header*)buf;
- header->code = code;
- header->size = size;
- len = sizeof(center_com_header) + size;
- *data = (void*)(buf + sizeof(center_com_header));
-
- return buf;
-}
-int judge_conn::send_setid(int judgeid){
- char *write_buf;
- int write_len;
- center_com_setid *setid;
-
- write_buf = create_combuf(CENTER_COMCODE_SETID,sizeof(center_com_setid),write_len,(void**)&setid);
- setid->id = judgeid;
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int judge_conn::send_submit(judge_submit_info *sub_info){
- char *write_buf;
- int write_len;
- center_com_submit *sub;
-
- if(sub_info->set_len > JUDGE_SET_DATAMAX){
- delete sub_info;
- return -1;
- }
-
- write_buf = create_combuf(CENTER_COMCODE_SUBMIT,sizeof(center_com_submit) + sub_info->set_len,write_len,(void**)&sub);
- sub->subid = sub_info->subid;
- sub->proid = sub_info->proid;
- sub->lang = sub_info->lang;
- memcpy((void*)(write_buf + sizeof(center_com_header) + sizeof(center_com_submit)),sub_info->set_data,sub_info->set_len);
- writebytes(write_buf,write_len,NULL,NULL);
-
- delete sub_info;
- return 0;
-}
-int judge_conn::send_setpro(std::vector<std::pair<int,int> > &pro_list,int type){
- int i;
-
- int count;
- char *write_buf;
- int write_len;
- center_com_setpro *setpro;
-
- count = pro_list.size();
- write_buf = create_combuf(CENTER_COMCODE_SETPRO,sizeof(center_com_setpro) * count,write_len,(void**)&setpro);
-
- for(i = 0;i < count;i++){
- setpro[i].proid = pro_list[i].first;
- setpro[i].cacheid = pro_list[i].second;
- setpro[i].type = type;
- }
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int judge_conn::send_setjmod(std::vector<std::pair<char*,int> > &jmod_list,int type){
- int i;
-
- int count;
- char *write_buf;
- int write_len;
- center_com_setjmod *setjmod;
-
- count = jmod_list.size();
- write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod);
-
- for(i = 0;i < count;i++){
- setjmod[i].jmod_name[0] = '\0';
- strncat(setjmod[i].jmod_name,jmod_list[i].first,sizeof(setjmod[i].jmod_name));
- setjmod[i].cacheid = jmod_list[i].second;
- setjmod[i].type = type;
- }
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int judge_conn::readidle(){
- readbytes(new center_com_header,sizeof(center_com_header),recv_dispatch_fn,NULL);
- return 0;
-}
-void judge_conn::recv_dispatch(void *buf,size_t len,void *data){
- center_com_header *header;
- char *readbuf;
-
- header = (center_com_header*)buf;
- readbuf = new char[header->size];
-
- printf("code:%d size:%d\n",header->code,header->size);
- switch(header->code){
- case CENTER_COMCODE_SETID:
- readbytes(readbuf,header->size,recv_setid_fn,NULL);
- break;
- case CENTER_COMCODE_SETINFO:
- readbytes(readbuf,header->size,recv_setinfo_fn,NULL);
- break;
- case CENTER_COMCODE_RESULT:
- readbytes(readbuf,header->size,recv_result_fn,NULL);
- break;
- case CENTER_COMCODE_SETPRO:
- readbytes(readbuf,header->size,recv_setpro_fn,NULL);
- break;
- case CENTER_COMCODE_REQPRO:
- readbytes(readbuf,header->size,recv_reqpro_fn,NULL);
- break;
- case CENTER_COMCODE_SETJMOD:
- readbytes(readbuf,header->size,recv_setjmod_fn,NULL);
- break;
- case CENTER_COMCODE_REQJMOD:
- readbytes(readbuf,header->size,recv_reqjmod_fn,NULL);
- break;
- case CENTER_COMCODE_REQCODE:
- readbytes(readbuf,header->size,recv_reqcode_fn,NULL);
- break;
- }
-
- delete header;
-}
-void judge_conn::recv_setid(void *buf,size_t len,void *data){
- center_com_setid *setid;
- std::map<int,judge_info*>::iterator it;
-
- setid = (center_com_setid*)buf;
- if(setid->id == 0){
- info = new judge_info();
-
- info->conn_list.push_front(this);
- conn_it = info->conn_list.begin();
- info->conn_main = this;
-
- this->send_setid(info->id);
- }else{
- if((it = judge_idmap.find(setid->id)) != judge_idmap.end()){
- info = it->second;
- info->conn_list.push_front(this);
- conn_it = info->conn_list.begin();
- }
- }
-
- delete setid;
-}
-void judge_conn::recv_setinfo(void *buf,size_t len,void *data){
- int i;
- int count;
-
- center_com_setinfo *setinfo;
- std::map<std::string,center_jmod_info*>::iterator jmod_it;
- std::vector<std::pair<char*,int> > jmod_list;
- std::map<int,center_pro_info*>::iterator pro_it;
- std::vector<std::pair<int,int> > pro_list;
-
- setinfo = (center_com_setinfo*)buf;
- info->setinfo(setinfo->avail);
-
- count = center_manage_jmodmap.size();
- jmod_it = center_manage_jmodmap.begin();
- for(i = 0;i < count;i++,jmod_it++){
- jmod_list.push_back(std::make_pair(jmod_it->second->name,jmod_it->second->cacheid));
- }
- send_setjmod(jmod_list,0);
-
- count = center_manage_promap.size();
- pro_it = center_manage_promap.begin();
- for(i = 0;i < count;i++,pro_it++){
- pro_list.push_back(std::make_pair(pro_it->second->proid,pro_it->second->cacheid));
- }
- send_setpro(pro_list,0);
-
- delete setinfo;
-}
-void judge_conn::recv_result(void *buf,size_t len,void *data){
- int subid;
- char *res_data;
-
- subid = ((center_com_result*)buf)->subid;
- res_data = (char*)((char*)buf + sizeof(center_com_result));
-
- info->result(subid,res_data);
-
- delete (char*)buf;
-}
-void judge_conn::recv_setpro(void *buf,size_t len,void *data){
- int i;
- int count;
-
- center_com_setpro *setpro;
- center_pro_info *pro_info;
- std::map<int,center_pro_info*>::iterator pro_it;
-
- count = len / sizeof(center_com_setpro);
- setpro = (center_com_setpro*)buf;
- for(i = 0;i < count;i++){
- if(setpro[i].type == 0){
- if((pro_info = center_manage_getprobyid(setpro[i].proid)) == NULL){
- continue;
- }
-
- if(pro_info->cacheid == setpro[i].cacheid){
- info->pro_map.insert(std::pair<int,int>(pro_info->proid,pro_info->cacheid));
- }
- center_manage_putpro(pro_info);
-
- }else if(setpro[i].type == 1){
- info->pro_map.erase(setpro[i].proid);
- }
- }
-
- judge_run_waitqueue();
- delete setpro;
-}
-void judge_conn::recv_reqpro(void *buf,size_t len,void *data){
- center_com_reqpro *reqpro;
- std::map<int,center_pro_info*>::iterator pro_it;
- center_pro_info *pro_info;
-
- char tpath[PATH_MAX + 1];
- int fd;
- struct stat st;
-
- char *write_buf;
- int write_len;
- center_com_sendpro *sendpro;
-
- reqpro = (center_com_reqpro*)buf;
- try{
- if((pro_info = center_manage_getprobyid(reqpro->proid)) == NULL){
- throw -1;
- }
- if(pro_info->cacheid != reqpro->cacheid){
- throw -1;
- }
-
- snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid);
- fd = open(tpath,O_RDONLY);
- fstat(fd,&st);
- write_buf = create_combuf(CENTER_COMCODE_SENDPRO,sizeof(center_com_sendpro),write_len,(void**)&sendpro);
- sendpro->proid = pro_info->proid;
- sendpro->cacheid = pro_info->cacheid;
- sendpro->filesize = st.st_size;
- printf("sendpro:%lu\n",sendpro->filesize);
-
- writebytes(write_buf,write_len,NULL,NULL);
- writefile(fd,st.st_size,done_sendpro_fn,pro_info);
- }catch(int err){
- if(pro_info != NULL){
- center_manage_putpro(pro_info);
- }
- }
-
- delete reqpro;
-}
-void judge_conn::done_sendpro(void *buf,size_t len,void *data){
- close((int)((long)buf));
- center_manage_putpro((center_pro_info*)data);
-}
-void judge_conn::recv_setjmod(void *buf,size_t len,void *data){
- int i;
- int count;
-
- center_com_setjmod *setjmod;
- std::map<std::string,center_jmod_info*>::iterator jmod_it;
-
- count = len / sizeof(center_com_setjmod);
- setjmod = (center_com_setjmod*)buf;
- for(i = 0;i < count;i++){
- if(setjmod[i].type == 0){
- if((jmod_it = center_manage_jmodmap.find(setjmod[i].jmod_name)) == center_manage_jmodmap.end()){
- continue;
- }
- if(jmod_it->second->cacheid != setjmod[i].cacheid){
- continue;
- }
-
- info->jmod_map.insert(std::pair<std::string,center_jmod_info*>(jmod_it->second->name,jmod_it->second));
- }else if(setjmod[i].type == 1){
- info->jmod_map.erase(setjmod[i].jmod_name);
- }
- }
-
- judge_run_waitqueue();
- delete setjmod;
-}
-void judge_conn::recv_reqjmod(void *buf,size_t len,void *data){
- center_com_reqjmod *reqjmod;
- std::map<std::string,center_jmod_info*>::iterator jmod_it;
- center_jmod_info *jmod_info;
-
- char tpath[PATH_MAX + 1];
- int fd;
- struct stat st;
-
- char *write_buf;
- int write_len;
- center_com_sendjmod *sendjmod;
-
- reqjmod = (center_com_reqjmod*)buf;
- if((jmod_it = center_manage_jmodmap.find(reqjmod->jmod_name)) == center_manage_jmodmap.end()){
- //fix
- }else{
- jmod_info = jmod_it->second;
-
- snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s.tar.bz2",jmod_info->name);
- fd = open(tpath,O_RDONLY);
- if(fstat(fd,&st)){
- //fix
- }else{
- write_buf = create_combuf(CENTER_COMCODE_SENDJMOD,sizeof(center_com_sendjmod),write_len,(void**)&sendjmod);
- sendjmod->jmod_name[0] = '\0';
- strncat(sendjmod->jmod_name,jmod_info->name,sizeof(sendjmod->jmod_name));
- sendjmod->cacheid = jmod_info->cacheid;
- sendjmod->filesize = st.st_size;
- printf("sendjmod:%lu\n",sendjmod->filesize);
-
- writebytes(write_buf,write_len,NULL,NULL);
- writefile(fd,st.st_size,NULL,NULL);
- }
- }
-
- delete reqjmod;
-}
-void judge_conn::recv_reqcode(void *buf,size_t len,void *data){
- center_com_reqcode *reqcode;
- char tpath[PATH_MAX + 1];
- int fd;
- struct stat st;
-
- char *write_buf;
- int write_len;
- center_com_header *header;
- center_com_sendcode *sendcode;
-
- reqcode = (center_com_reqcode*)buf;
- snprintf(tpath,sizeof(tpath),"tmp/codepack/%d.tar.bz2",reqcode->subid);
- fd = open(tpath,O_RDONLY);
- if(fstat(fd,&st)){
- //fix
- }else{
- write_buf = create_combuf(CENTER_COMCODE_SENDCODE,sizeof(center_com_sendcode),write_len,(void**)&sendcode);
- sendcode->subid = reqcode->subid;
- sendcode->filesize = st.st_size;
- printf("sendcode:%lu\n",sendcode->filesize);
-
- writebytes(write_buf,write_len,NULL,NULL);
- writefile(fd,st.st_size,NULL,NULL);
- }
-
- delete reqcode;
-}
-
-
-static int judge_run_waitqueue(){
- int count;
- judge_submit_info *sub_info;
- bool wait_flag;
- std::list<judge_info*>::iterator judge_it;
- judge_info *info;
- std::map<int,center_pro_info*>::iterator pro_it;
- center_pro_info *pro_info;
-
- count = judge_submitqueue.size();
- printf(" remain count %d\n",count);
- for(;count > 0;count--){
- sub_info = judge_submitqueue.front();
- judge_submitqueue.pop();
-
- if((pro_it = center_manage_promap.find(sub_info->proid)) == center_manage_promap.end()){
- continue;
- }
- pro_info = pro_it->second;
-
- wait_flag = true;
- for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){
- info = *judge_it;
- if(info->avail <= 0){
- break;
- }
- if(info->pro_map.find(pro_info->proid) != info->pro_map.end() && info->jmod_map.find(pro_info->jmod_info->name) != info->jmod_map.end()){
- info->submit(sub_info);
- wait_flag = false;
- break;
- }
- }
- if(wait_flag == true){
- judge_submitqueue.push(sub_info);
- }
- }
- return 0;
-}
-int center_judge_init(){
- return 0;
-}
-void* center_judge_addconn(int fd){
- return new judge_conn(fd);
-}
-int center_judge_dispatch(int evflag,void *data){
- judge_conn *cinfo;
-
- cinfo = (judge_conn*)data;
- if(evflag & EPOLLRDHUP){
- printf("close %d\n",cinfo->fd);
- delete cinfo;
- }else{
- if(evflag & EPOLLIN){
- cinfo->readio();
- }
- if(evflag & EPOLLOUT){
- cinfo->writeio();
- }
- }
-
- return 0;
-}
-int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len){
- judge_submitqueue.push(new judge_submit_info(subid,proid,lang,set_data,set_len));
- judge_run_waitqueue();
- return 0;
-}
-int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list){
- int i;
- int j;
- std::list<judge_info*>::iterator judge_it;
- judge_info *info;
-
- for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){
- (*judge_it)->updatepro(pro_list);
- }
-
- return 0;
-}
-int center_judge_updatejmod(std::vector<std::pair<char*,int> > &jmod_list){
- int i;
- int j;
- std::list<judge_info*>::iterator judge_it;
- judge_info *info;
-
- for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){
- (*judge_it)->updatejmod(jmod_list);
- }
-
- return 0;
-}
diff --git a/toj/center/src/center_judge.h b/toj/center/src/center_judge.h
deleted file mode 100755
index a955ce9..0000000
--- a/toj/center/src/center_judge.h
+++ /dev/null
@@ -1,106 +0,0 @@
-class judge_info;
-class judge_conn;
-class judge_submit_info;
-
-class judge_info{
-private:
- static int last_id;
-
-public:
- int id;
- int avail;
- judge_conn *conn_main;
- std::list<judge_conn*> conn_list;
- std::list<judge_info*>::iterator judge_it;
- std::map<int,int> pro_map;
- std::map<std::string,center_jmod_info*> jmod_map;
-
- judge_info();
- ~judge_info();
- int setavail(int value);
- int setinfo(int avail);
- int submit(judge_submit_info *submit_info);
- int result(int subid,char *res_data);
- int updatepro(std::vector<std::pair<int,int> > &pro_list);
- int updatejmod(std::vector<std::pair<char*,int> > &jmod_list);
-};
-
-class judge_conn : public netio{
-private:
- netio_iofn<judge_conn> *recv_dispatch_fn;
- netio_iofn<judge_conn> *recv_setid_fn;
- netio_iofn<judge_conn> *recv_setinfo_fn;
- netio_iofn<judge_conn> *recv_result_fn;
- netio_iofn<judge_conn> *recv_setpro_fn;
- netio_iofn<judge_conn> *recv_reqpro_fn;
- netio_iofn<judge_conn> *done_sendpro_fn;
- netio_iofn<judge_conn> *recv_setjmod_fn;
- netio_iofn<judge_conn> *recv_reqjmod_fn;
- netio_iofn<judge_conn> *recv_reqcode_fn;
-
- char* create_combuf(int code,int size,int &len,void **data);
- void recv_dispatch(void *buf,size_t len,void *data);
- void recv_setid(void *buf,size_t len,void *data);
- void recv_setinfo(void *buf,size_t len,void *data);
- void recv_result(void *buf,size_t len,void *data);
- void recv_setpro(void *buf,size_t len,void *data);
- void recv_reqpro(void *buf,size_t len,void *data);
- void done_sendpro(void *buf,size_t len,void *data);
- void recv_setjmod(void *buf,size_t len,void *data);
- void recv_reqjmod(void *buf,size_t len,void *data);
- void recv_reqcode(void *buf,size_t len,void *data);
-
-public:
- judge_info *info;
- std::list<judge_conn*>::iterator conn_it;
-
- judge_conn(int fd);
- ~judge_conn();
- int send_setid(int judgeid);
- int send_submit(judge_submit_info* submit_info);
- int send_setpro(std::vector<std::pair<int,int> > &pro_list,int type);
- int send_setjmod(std::vector<std::pair<char*,int> > &jmod_list,int type);
- virtual int readidle();
-};
-
-class judge_submit_info{
-public:
- int subid;
- int proid;
- int lang;
- char *set_data;
- size_t set_len;
-
- judge_submit_info(int subid,int proid,int lang,char *set_data,size_t set_len){
- this->subid = subid;
- this->proid = proid;
- this->lang = lang;
- this->set_data = new char[set_len];
- memcpy(this->set_data,set_data,set_len);
- this->set_len = set_len;
- }
- ~judge_submit_info(){
- delete this->set_data;
- }
-};
-
-static int judge_run_waitqueue();
-
-static std::map<int,judge_info*> judge_idmap;
-static std::list<judge_info*> judge_runlist;
-static std::queue<judge_submit_info*> judge_submitqueue;
-
-int center_judge_init();
-void* center_judge_addconn(int fd);
-int center_judge_dispatch(int evflag,void *data);
-int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len);
-int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list);
-int center_judge_updatejmod(std::vector<std::pair<char*,int> > &jmod_list);
-
-extern int center_manage_result(int subid,char *res_data);
-extern center_pro_info* center_manage_getprobyid(int proid);
-extern int center_manage_getpro(center_pro_info *pro_info);
-extern int center_manage_putpro(center_pro_info *pro_info);
-
-extern std::map<std::string,center_jmod_info*> center_manage_jmodmap;
-extern std::map<int,center_pro_info*> center_manage_promap;
diff --git a/toj/center/src/center_manage.cpp b/toj/center/src/center_manage.cpp
deleted file mode 100755
index a6a759c..0000000
--- a/toj/center/src/center_manage.cpp
+++ /dev/null
@@ -1,640 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<limits.h>
-#include<dlfcn.h>
-#include<unistd.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<libpq-fe.h>
-#include<sys/eventfd.h>
-#include<sys/stat.h>
-#include<json/json.h>
-#include<vector>
-#include<queue>
-#include<map>
-#include<string>
-
-#include"tpool.h"
-#include"/srv/http/toj/php/event_exec.h"
-#include"judge_def.h"
-#include"judgm_manage.h"
-#include"center.h"
-#include"center_manage.h"
-
-int center_manage_init(tpool **tpinfo){
- manage_tp = new tpool(4);
- manage_tp->start();
- *tpinfo = manage_tp;
-
- manage_updatepro_thfn = new tpool_static_fn(manage_updatepro_th);
- manage_updatepro_cbfn = new tpool_static_fn(manage_updatepro_cb);
- manage_updatejmod_thfn = new tpool_static_fn(manage_updatejmod_th);
- manage_updatejmod_cbfn = new tpool_static_fn(manage_updatejmod_cb);
- manage_submit_thfn = new tpool_static_fn(manage_submit_th);
- manage_submit_cbfn = new tpool_static_fn(manage_submit_cb);
-
- //run when startup
- center_manage_updatedata();
- center_manage_submitwait();
- return 0;
-}
-PGconn* center_manage_conndb(){
- return PQconnectdb("host=localhost port=5432 dbname=xxxxx user=xxxxx password=xxxxx");
-}
-int center_manage_closedb(PGconn *conn){
- PQfinish(conn);
- return 0;
-}
-int center_manage_updatedata(){
- int i;
-
- PGconn *db_conn;
- PGresult *db_res;
- int db_count;
- int cacheid;
- center_jmod_info *jmod_info;
- int proid;
- int lang_flag;
- std::map<std::string,center_jmod_info*>::iterator jmod_it;
- center_pro_info *pro_info;
-
- std::vector<std::pair<int,int> > pro_list;
-
- if((db_conn = center_manage_conndb()) == NULL){
- return -1;
- }
-
- db_res = PQexec(db_conn,"SELECT DISTINCT \"jmodname\" FROM \"mod\";");
- if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
- center_manage_closedb(db_conn);
- return -1;
- }
-
- db_count = PQntuples(db_res);
- for(i = 0;i < db_count;i++){
- jmod_info = new center_jmod_info(PQgetvalue(db_res,i,0),2);
- center_manage_jmodmap.insert(std::pair<std::string,center_jmod_info*>(jmod_info->name,jmod_info));
- }
- PQclear(db_res);
-
- db_res = PQexec(db_conn,"SELECT \"proid\",\"cacheid\",\"lang\",\"jmodname\" FROM \"problem\" INNER JOIN \"mod\" ON (\"problem\".\"modid\"=\"mod\".\"modid\");");
- if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
- center_manage_closedb(db_conn);
- return -1;
- }
-
- db_count = PQntuples(db_res);
- for(i = 0;i < db_count;i++){
- sscanf(PQgetvalue(db_res,i,0),"%d",&proid);
- sscanf(PQgetvalue(db_res,i,1),"%d",&cacheid);
- sscanf(PQgetvalue(db_res,i,2),"%d",&lang_flag);
- if((jmod_it = center_manage_jmodmap.find(PQgetvalue(db_res,i,3))) == center_manage_jmodmap.end()){
- continue;
- }
-
- if(manage_updatepro(proid,cacheid,jmod_it->second,lang_flag) == 1){
- pro_list.push_back(std::make_pair(proid,cacheid));
-
- printf("pro update %d %d\n",proid,cacheid);
- }
- }
- PQclear(db_res);
-
- if(!pro_list.empty()){
- center_judge_updatepro(pro_list);
- }
-
- center_manage_closedb(db_conn);
- return 0;
-}
-int center_manage_submitwait(){
- int i;
-
- PGconn *db_conn;
- PGresult *db_res;
- int db_count;
- int subid;
-
- if((db_conn = center_manage_conndb()) == NULL){
- return -1;
- }
-
- db_res = PQexec(db_conn,"SELECT \"subid\" FROM \"submit\" WHERE \"result\"=100;");
- if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
- center_manage_closedb(db_conn);
- return -1;
- }
-
- db_count = PQntuples(db_res);
- for(i = 0;i < db_count;i++){
- sscanf(PQgetvalue(db_res,i,0),"%d",&subid);
- center_manage_submit(subid,"{}");
- }
-
- PQclear(db_res);
- center_manage_closedb(db_conn);
- return 0;
-}
-
-
-int center_manage_submit(int subid,char *param){
- PGconn *db_conn;
- PGresult *db_res;
- char *db_param[1];
- char db_subid[64];
-
- int uid;
- int proid;
- int lang;
- int result;
- bool rejudge_flag;
- std::map<int,center_pro_info*>::iterator pro_it;
- center_pro_info *pro_info;
- center_jmod_info *jmod_info;
- manage_submit_info *sub_info;
-
- if((db_conn = center_manage_conndb()) == NULL){
- return -1;
- }
-
- snprintf(db_subid,sizeof(db_subid),"%d",subid);
- db_param[0] = db_subid;
- db_res = PQexecParams(db_conn,
- "SELECT \"uid\",\"proid\",\"lang\",\"result\" FROM \"submit\" WHERE \"subid\"=$1;",
- 1,
- NULL,
- db_param,
- NULL,
- NULL,
- 0);
- if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
- center_manage_closedb(db_conn);
- return -1;
- }
-
- sscanf(PQgetvalue(db_res,0,0),"%d",&uid);
- sscanf(PQgetvalue(db_res,0,1),"%d",&proid);
- sscanf(PQgetvalue(db_res,0,2),"%d",&lang);
- sscanf(PQgetvalue(db_res,0,3),"%d",&result);
- PQclear(db_res);
- center_manage_closedb(db_conn);
-
- if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){
- return -1;
- }
- pro_info = pro_it->second;
-
- if((lang & pro_info->lang_flag) == 0){
- return -1;
- }
- jmod_info = pro_info->jmod_info;
-
- if(result == JUDGE_WAIT){
- rejudge_flag = false;
- }else{
- rejudge_flag = true;
- }
-
- center_manage_getpro(pro_info);
-
- sub_info = new manage_submit_info(subid,uid,jmod_info,pro_info,lang,rejudge_flag,param);
- manage_submap.insert(std::pair<int,manage_submit_info*>(sub_info->subid,sub_info));
- manage_tp->add(manage_submit_thfn,sub_info,manage_submit_cbfn,sub_info);
-
- return 0;
-}
-static void manage_submit_th(void *data){
- manage_submit_info *sub_info;
- char dir_path[PATH_MAX + 1];
- char pack_path[PATH_MAX + 1];
-
- sub_info = (manage_submit_info*)data;
-
- snprintf(dir_path,sizeof(dir_path),"submit/%d/%d/data",(sub_info->subid / 1000) * 1000,sub_info->subid);
- snprintf(pack_path,sizeof(pack_path),"tmp/codepack/%d.tar.bz2",sub_info->subid);
- tool_pack(pack_path,dir_path);
-}
-static void manage_submit_cb(void *data){
- manage_submit_info *sub_info;
- center_jmod_info *jmod_info;
- center_pro_info *pro_info;
-
- char cwd_path[PATH_MAX + 1];
- char tpath[PATH_MAX + 1];
- judgm_manage_info *mg_info;
- judgm_manage_submit_fn mg_sub_fn;
- FILE *set_file;
- char lchr;
- char tchr;
-
- try{
- sub_info = (manage_submit_info*)data;
- jmod_info = sub_info->jmod_info;
- pro_info = sub_info->pro_info;
-
- if(jmod_info->manage_dll == NULL){
- getcwd(cwd_path,sizeof(cwd_path));
- snprintf(tpath,sizeof(tpath),"%s/jmod/%s/%s_manage.so",cwd_path,jmod_info->name,jmod_info->name);
-
- jmod_info->manage_dll = dlopen(tpath,RTLD_NOW);
- jmod_info->manage_sub_fn = dlsym(jmod_info->manage_dll,"submit");
- jmod_info->manage_res_fn = dlsym(jmod_info->manage_dll,"result");
- }
- mg_sub_fn = (judgm_manage_submit_fn)jmod_info->manage_sub_fn;
-
- mg_info = sub_info->manage_info;
- snprintf(mg_info->pro_path,sizeof(mg_info->pro_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
- snprintf(mg_info->res_path,sizeof(mg_info->res_path),"submit/%d/%d/result",(sub_info->subid / 1000) * 1000,sub_info->subid);
-
- snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d/setting",pro_info->proid,pro_info->cacheid);
- if((set_file = fopen(tpath,"r")) == NULL){
- throw 0;
- }
- lchr = '\n';
- while((tchr = fgetc(set_file)) != EOF){
- if(lchr == '\n' && tchr == '='){
- while(fgetc(set_file) != '\n');
- break;
- }
- lchr = tchr;
- }
-
- mg_sub_fn(mg_info,set_file);
-
- fclose(set_file);
- }catch(...){
- manage_finish_result(sub_info->subid,
- sub_info->uid,
- sub_info->pro_info->proid,
- JUDGE_ERR,
- 0,
- 0,
- 0,
- sub_info->rejudge_flag);
- }
-}
-DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len){
- center_judge_submit(subid,proid,lang,set_data,set_len);
- return 0;
-}
-
-int center_manage_result(int subid,char *res_data){
- std::map<int,manage_submit_info*>::iterator sub_it;
- manage_submit_info *sub_info;
- center_jmod_info *jmod_info;
-
- char res_path[PATH_MAX + 1];
- judgm_manage_info *mg_info;
- judgm_manage_result_fn mg_res_fn;
-
- if((sub_it = manage_submap.find(subid)) == manage_submap.end()){
- return -1;
- }
- sub_info = sub_it->second;
- jmod_info = sub_info->jmod_info;
- mg_info = sub_info->manage_info;
-
- mg_res_fn = (judgm_manage_result_fn)jmod_info->manage_res_fn;
- if(mg_res_fn(mg_info,res_data)){
- manage_submap.erase(sub_it);
-
- manage_finish_result(subid,
- sub_info->uid,
- sub_info->pro_info->proid,
- mg_info->result,
- mg_info->score,
- mg_info->runtime,
- mg_info->memory,
- sub_info->rejudge_flag);
-
- center_manage_putpro(sub_info->pro_info);
- delete sub_info;
- }else{
- return -1;
- }
-
- return 0;
-}
-static int manage_finish_result(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag){
- PGconn *db_conn;
- PGresult *db_res;
- char db_result[32];
- char db_score[32];
- char db_runtime[32];
- char db_memory[32];
- char db_subid[32];
- char *db_param[5];
-
- if((db_conn = center_manage_conndb()) == NULL){
- return -1;
- }
-
- snprintf(db_result,sizeof(db_result),"%d",result);
- snprintf(db_score,sizeof(db_score),"%lf",score);
- snprintf(db_runtime,sizeof(db_runtime),"%lu",runtime);
- snprintf(db_memory,sizeof(db_memory),"%lu",memory / 1024UL);
- snprintf(db_subid,sizeof(db_subid),"%d",subid);
- db_param[0] = db_result;
- db_param[1] = db_score;
- db_param[2] = db_runtime;
- db_param[3] = db_memory;
- db_param[4] = db_subid;
- db_res = PQexecParams(db_conn,
- "UPDATE \"submit\" SET \"result\"=$1,\"score\"=$2,\"runtime\"=$3,\"memory\"=$4 WHERE \"subid\"=$5;",
- 5,
- NULL,
- db_param,
- NULL,
- NULL,
- 0);
- PQclear(db_res);
- center_manage_closedb(db_conn);
-
- manage_notice(subid,
- uid,
- proid,
- result,
- score,
- runtime,
- memory,
- rejudge_flag);
-
- return 0;
-}
-static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag){
- char msg[4096];
- json_object *jso_msg;
- json_object *jso_arg;
-
- jso_msg = json_object_new_object();
- json_object_object_add(jso_msg,"type",json_object_new_string("result"));
- json_object_object_add(jso_msg,"subid",json_object_new_int(subid));
- json_object_object_add(jso_msg,"proid",json_object_new_int(proid));
- json_object_object_add(jso_msg,"result",json_object_new_int(result));
- json_object_object_add(jso_msg,"score",json_object_new_double(score));
- json_object_object_add(jso_msg,"runtime",json_object_new_int(runtime));
- json_object_object_add(jso_msg,"memory",json_object_new_int(memory / 1024UL));
- json_object_object_add(jso_msg,"rejudge_flag",json_object_new_boolean(rejudge_flag));
-
- jso_arg = json_object_new_array();
- json_object_array_add(jso_arg,json_object_new_int(uid));
- json_object_array_add(jso_arg,jso_msg);
-
- event_exec("pzreadtest.php","center_result_event",json_object_get_string(jso_arg));
- json_object_put(jso_arg);
-
- return 0;
-}
-
-
-center_pro_info* center_manage_getprobyid(int proid){
- std::map<int,center_pro_info*>::iterator pro_it;
- center_pro_info *pro_info;
-
- if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){
- return NULL;
- }
- pro_info = pro_it->second;
-
- if(center_manage_getpro(pro_info)){
- return NULL;
- }
-
- return pro_info;
-}
-int center_manage_getpro(center_pro_info *pro_info){
- pro_info->ref_count++;
- return 0;
-}
-int center_manage_putpro(center_pro_info *pro_info){
- char tpath[PATH_MAX + 1];
-
- pro_info->ref_count--;
- if(pro_info->ref_count == 0){
- snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
- tool_cleardir(tpath);
- rmdir(tpath);
-
- snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid);
- unlink(tpath);
-
- delete pro_info;
- }
- return 0;
-}
-static int manage_updatepro(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag){
- std::map<int,center_pro_info*>::iterator pro_it;
- center_pro_info *old_pro_info;
- center_pro_info *update_pro_info;
-
- char tpath[PATH_MAX + 1];
- struct stat st;
- std::pair<std::map<int,center_pro_info*>::iterator,bool> ins_ret;
-
- if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){
- old_pro_info = NULL;
- }else{
- old_pro_info = pro_it->second;
-
- if(old_pro_info->state == CENTER_CACHESTATE_READY && cacheid == old_pro_info->cacheid){
- return 1;
- }
- if(old_pro_info->state == CENTER_CACHESTATE_UPDATE && (cacheid <= old_pro_info->cacheid || cacheid <= old_pro_info->update_cacheid)){
- return -1;
- }
-
- old_pro_info->state = CENTER_CACHESTATE_UPDATE;
- old_pro_info->update_cacheid = cacheid;
- }
-
- update_pro_info = new center_pro_info(proid,cacheid,jmod_info,lang_flag); //set cacheid 0 to new pro
- center_manage_getpro(update_pro_info);
-
- snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d",update_pro_info->proid,update_pro_info->cacheid);
- if(!stat(tpath,&st)){
- snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",update_pro_info->proid,update_pro_info->cacheid);
- if(!stat(tpath,&st)){
-
- if(old_pro_info != NULL){
- center_manage_putpro(old_pro_info);
- }
-
- ins_ret = center_manage_promap.insert(std::make_pair(update_pro_info->proid,update_pro_info));
- if(ins_ret.second == false){
- ins_ret.first->second = update_pro_info;
- }
-
- return 1;
- }
- }
-
- manage_tp->add(manage_updatepro_thfn,update_pro_info,manage_updatepro_cbfn,update_pro_info);
-
- return 0;
-}
-static void manage_updatepro_th(void *data){
- center_pro_info *pro_info;
- char src_path[PATH_MAX + 1];
- char dir_path[PATH_MAX + 1];
- char pack_path[PATH_MAX + 1];
-
- pro_info = (center_pro_info*)data;
-
- snprintf(src_path,sizeof(src_path),"pro/%d",pro_info->proid);
- snprintf(dir_path,sizeof(dir_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
- tool_copydir(src_path,dir_path);
-
- snprintf(pack_path,sizeof(pack_path),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid);
- tool_pack(pack_path,dir_path);
-}
-static void manage_updatepro_cb(void *data){
- center_pro_info *old_pro_info;
- center_pro_info *update_pro_info;
- std::pair<std::map<int,center_pro_info*>::iterator,bool> ins_ret;
- std::vector<std::pair<int,int> > pro_pair;
-
- update_pro_info = (center_pro_info*)data;
-
- ins_ret = center_manage_promap.insert(std::make_pair(update_pro_info->proid,update_pro_info));
- if(ins_ret.second == false){
- old_pro_info = ins_ret.first->second;
-
- if(update_pro_info->cacheid <= old_pro_info->cacheid){
- center_manage_putpro(update_pro_info);
- return;
- }
-
- center_manage_putpro(ins_ret.first->second);
- ins_ret.first->second = update_pro_info;
- }
-
- pro_pair.push_back(std::make_pair(update_pro_info->proid,update_pro_info->cacheid));
- center_judge_updatepro(pro_pair);
-}
-
-center_jmod_info* center_manage_getjmodbyname(char *name){
- std::map<std::string,center_jmod_info*>::iterator jmod_it;
- center_jmod_info *jmod_info;
-
- if((jmod_it = center_manage_jmodmap.find(name)) == center_manage_jmodmap.end()){
- return NULL;
- }
- jmod_info = jmod_it->second;
-
- if(center_manage_getjmod(jmod_info)){
- return NULL;
- }
-
- return jmod_info;
-}
-int center_manage_getjmod(center_jmod_info *jmod_info){
- jmod_info->ref_count++;
- return 0;
-}
-int center_manage_putjmod(center_jmod_info *jmod_info){
- char tpath[PATH_MAX + 1];
-
- jmod_info->ref_count--;
- if(jmod_info->ref_count == 0){
- snprintf(tpath,sizeof(tpath),"tmp/jmod/%s_%d",jmod_info->name,jmod_info->cacheid);
- tool_cleardir(tpath);
- rmdir(tpath);
-
- snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s_%d.tar.bz2",jmod_info->name,jmod_info->cacheid);
- unlink(tpath);
-
- delete jmod_info;
- }
- return 0;
-}
-static int manage_updatejmod(char *name,int cacheid){
- std::map<std::string,center_jmod_info*>::iterator jmod_it;
- center_jmod_info *old_jmod_info;
- center_jmod_info *update_jmod_info;
-
- char tpath[PATH_MAX + 1];
- struct stat st;
- std::pair<std::map<std::string,center_jmod_info*>::iterator,bool> ins_ret;
-
- if((jmod_it = center_manage_jmodmap.find(name)) == center_manage_jmodmap.end()){
- old_jmod_info = NULL;
- }else{
- old_jmod_info = jmod_it->second;
-
- if(old_jmod_info->state == CENTER_CACHESTATE_READY && cacheid == old_jmod_info->cacheid){
- return -1;
- }
- if(old_jmod_info->state == CENTER_CACHESTATE_UPDATE && (cacheid <= old_jmod_info->cacheid || cacheid <= old_jmod_info->update_cacheid)){
- return -1;
- }
-
- old_jmod_info->state = CENTER_CACHESTATE_UPDATE;
- old_jmod_info->update_cacheid = cacheid;
- }
-
- update_jmod_info = new center_jmod_info(name,cacheid);
- center_manage_getjmod(update_jmod_info);
-
- snprintf(tpath,sizeof(tpath),"tmp/jmod/%s_%d",update_jmod_info->name,update_jmod_info->cacheid);
- if(!stat(tpath,&st)){
- snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s_%d.tar.bz2",update_jmod_info->name,update_jmod_info->cacheid);
- if(!stat(tpath,&st)){
-
- if(old_jmod_info != NULL){
- center_manage_putjmod(old_jmod_info);
-
- ins_ret = center_manage_jmodmap.insert(std::make_pair(update_jmod_info->name,update_jmod_info));
- if(ins_ret.second == false){
- ins_ret.first->second = update_jmod_info;
- }
-
- return 1;
- }
- }
- }
-
- manage_tp->add(manage_updatejmod_thfn,update_jmod_info,manage_updatejmod_cbfn,update_jmod_info);
-
- return 0;
-}
-static void manage_updatejmod_th(void *data){
- center_jmod_info *jmod_info;
- char src_path[PATH_MAX + 1];
- char dir_path[PATH_MAX + 1];
- char pack_path[PATH_MAX + 1];
-
- jmod_info = (center_jmod_info*)data;
-
- snprintf(src_path,sizeof(src_path),"jmod/%s",jmod_info->name);
- snprintf(dir_path,sizeof(dir_path),"tmp/jmod/%s_%d.tar.bz2",jmod_info->name,jmod_info->cacheid);
- tool_copydir(src_path,dir_path);
-
- snprintf(pack_path,sizeof(pack_path),"tmp/jmodpack/%s_%d.tar.bz2",jmod_info->name,jmod_info->cacheid);
- tool_pack(pack_path,dir_path);
-}
-static void manage_updatejmod_cb(void *data){
- center_jmod_info *old_jmod_info;
- center_jmod_info *update_jmod_info;
- std::pair<std::map<std::string,center_jmod_info*>::iterator,bool> ins_ret;
- std::vector<std::pair<std::string,int> > jmod_pair;
-
- update_jmod_info = (center_jmod_info*)data;
-
- ins_ret = center_manage_jmodmap.insert(std::make_pair(update_jmod_info->name,update_jmod_info));
- if(ins_ret.second == false){
- old_jmod_info = ins_ret.first->second;
-
- if(update_jmod_info->cacheid <= old_jmod_info->cacheid){
- center_manage_putjmod(update_jmod_info);
- }
-
- center_manage_putjmod(old_jmod_info);
- ins_ret.first->second = update_jmod_info;
- }
-
- jmod_pair.push_back(std::make_pair(update_jmod_info->name,update_jmod_info->cacheid));
- //wait
-
- //
-}
diff --git a/toj/center/src/center_manage.h b/toj/center/src/center_manage.h
deleted file mode 100755
index b2ee36e..0000000
--- a/toj/center/src/center_manage.h
+++ /dev/null
@@ -1,75 +0,0 @@
-class manage_submit_info{
-public:
- int subid;
- int uid;
- center_jmod_info *jmod_info;
- center_pro_info *pro_info;
- int lang;
- bool rejudge_flag;
- char param[JUDGE_SUB_PARAMMAX];
- judgm_manage_info *manage_info;
-
- manage_submit_info(int subid,int uid,center_jmod_info *jmod_info,center_pro_info *pro_info,int lang,bool rejudge_flag,char *param){
- this->subid = subid;
- this->uid = uid;
- this->jmod_info = jmod_info;
- this->pro_info = pro_info;
- this->lang = lang;
- this->rejudge_flag = rejudge_flag;
- this->param[0] = '\0';
- strncat(this->param,param,sizeof(this->param));
-
- this->manage_info = new judgm_manage_info(this->subid,this->uid,pro_info->proid,this->lang,this->param);
- }
- ~manage_submit_info(){
- delete this->manage_info;
- }
-};
-
-static void manage_submit_th(void *data);
-static void manage_submit_cb(void *data);
-static int manage_finish_result(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag);
-static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag);
-
-static int manage_updatepro(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag);
-static void manage_updatepro_th(void *data);
-static void manage_updatepro_cb(void *data);
-static int manage_updatejmod(char *name,int cacheid);
-static void manage_updatejmod_th(void *data);
-static void manage_updatejmod_cb(void *data);
-
-static tpool *manage_tp;
-static tpool_static_fn *manage_updatepro_thfn;
-static tpool_static_fn *manage_updatepro_cbfn;
-static tpool_static_fn *manage_updatejmod_thfn;
-static tpool_static_fn *manage_updatejmod_cbfn;
-static tpool_static_fn *manage_submit_thfn;
-static tpool_static_fn *manage_submit_cbfn;
-static std::map<int,manage_submit_info*> manage_submap;
-
-int center_manage_init(tpool **tpinfo);
-PGconn* center_manage_conndb();
-int center_manage_closedb(PGconn *conn);
-int center_manage_updatedata();
-int center_manage_submitwait();
-int center_manage_submit(int subid,char *param);
-int center_manage_result(int subid,char *res_data);
-DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len);
-
-center_pro_info* center_manage_getprobyid(int proid);
-int center_manage_getpro(center_pro_info*);
-int center_manage_putpro(center_pro_info *pro_info);
-center_jmod_info* center_manage_getjmodbyname(char *name);
-int center_manage_getjmod(center_jmod_info *jmod_info);
-int center_manage_putjmod(center_jmod_info *jmod_info);
-
-std::map<int,center_pro_info*> center_manage_promap;
-std::map<std::string,center_jmod_info*> center_manage_jmodmap;
-
-extern int tool_pack(char *pack_path,char *dir_path);
-extern int tool_unpack(char *pack_path,char *dir_path);
-extern int tool_cleardir(char *path);
-extern int tool_copydir(char *old_path,char *new_path);
-
-extern int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len);
-extern int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list);
diff --git a/toj/center/src/center_server.cpp b/toj/center/src/center_server.cpp
deleted file mode 100755
index 030e273..0000000
--- a/toj/center/src/center_server.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<unistd.h>
-#include<signal.h>
-#include<limits.h>
-#include<errno.h>
-#include<fcntl.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<libpq-fe.h>
-#include<sys/socket.h>
-#include<sys/epoll.h>
-#include<sys/eventfd.h>
-#include<netinet/in.h>
-#include<arpa/inet.h>
-#include<libpq-fe.h>
-#include<vector>
-#include<queue>
-
-#include"tpool.h"
-#include"center_server.h"
-
-server_epevdata::server_epevdata(int fd,int type,void *data){
- this->fd = fd;
- this->type = type;
- this->data = data;
-}
-
-
-server_web_conn::server_web_conn(int fd){
- this->fd = fd;
- this->off = 0;
- this->count = 0;
-}
-server_web_conn::~server_web_conn(){
- epoll_ctl(server_epfd,EPOLL_CTL_DEL,fd,NULL);
- close(fd);
-}
-int server_web_conn::readio(){
- int ret;
- char c;
- int len;
- int subid;
- char *param;
-
- while((ret = read(fd,&c,1)) > 0){
- buf[off] = c;
- off++;
- if(c == '\0'){
- count++;
- if(count == 2){
- break;
- }
- }
- }
-
- if(count == 2){
- off = 0;
- count = 0;
-
- sscanf(buf,"%d",&subid);
- param = buf + strlen(buf) + 1;
- printf("%d %s\n",subid,param);
-
- //test
- if(subid == -1){
- center_manage_updatedata();
- }else{
- center_manage_submit(subid,param);
- }
-
- //test
-
- write(fd,"S",2);
- }
-
- return 0;
-}
-
-
-static int server_addepev(int fd,unsigned int flag,int type,void *data){
- server_epevdata *epevdata;
- epoll_event epev;
-
- epevdata = new server_epevdata(fd,type,data);
- epev.events = flag;
- epev.data.ptr = epevdata;
- epoll_ctl(server_epfd,EPOLL_CTL_ADD,fd,&epev);
-
- return 0;
-}
-static int server_delepev(server_epevdata *epevdata){
- epoll_ctl(server_epfd,EPOLL_CTL_DEL,epevdata->fd,NULL);
- delete epevdata;
- return 0;
-}
-int main(){
- int ret;
- int i;
-
- int judge_sfd;
- int web_sfd;
- int cfd;
- sockaddr_in saddr;
- sockaddr_in caddr;
- epoll_event epev;
- epoll_event epevs[SERVER_EPOLL_MAXEVENT];
- int nevs;
-
- unsigned int ev_flag;
- server_epevdata *epevdata;
- server_web_conn *winfo;
- tpool *tpinfo;
-
- signal(SIGPIPE,SIG_IGN);
- server_epfd = epoll_create1(0);
- center_manage_init(&tpinfo);
- server_addepev(tpinfo->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,tpinfo);
- center_judge_init();
-
- judge_sfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6);
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(SERVER_JUDGE_PORT);
- //saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- //saddr.sin_addr.s_addr = htonl(INADDR_ANY);
- saddr.sin_addr.s_addr = inet_addr("10.8.0.2");
- setsockopt(judge_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr));
- bind(judge_sfd,(sockaddr*)&saddr,sizeof(saddr));
-
- server_addepev(judge_sfd,EPOLLIN | EPOLLET,SERVER_EPEV_JUDGESERVER,NULL);
- listen(judge_sfd,4096);
-
- web_sfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6);
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(SERVER_WEB_PORT);
- saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- //saddr.sin_addr.s_addr = htonl(INADDR_ANY);
- setsockopt(web_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr));
- bind(web_sfd,(sockaddr*)&saddr,sizeof(saddr));
-
- server_addepev(web_sfd,EPOLLIN | EPOLLET,SERVER_EPEV_WEBSERVER,NULL);
- listen(web_sfd,4096);
-
- while(true){
- nevs = epoll_wait(server_epfd,epevs,SERVER_EPOLL_MAXEVENT,-1);
- for(i = 0;i < nevs;i++){
- ev_flag = epevs[i].events;
- epevdata = (server_epevdata*)epevs[i].data.ptr;
-
- if(epevdata->type == SERVER_EPEV_JUDGESERVER){
- while(true){
- ret = 0;
- if((cfd = accept4(epevdata->fd,(sockaddr*)&caddr,(socklen_t*)&ret,SOCK_NONBLOCK)) == -1){
- break;
- }
-
- server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,center_judge_addconn(cfd));
- }
- }else if(epevdata->type == SERVER_EPEV_JUDGECLIENT){
- center_judge_dispatch(ev_flag,epevdata->data);
- if(ev_flag & EPOLLRDHUP){
- server_delepev(epevdata);
- }
- }else if(epevdata->type == SERVER_EPEV_WEBSERVER){
- printf("test\n");
- while(true){
- ret = 0;
- if((cfd = accept4(epevdata->fd,(sockaddr*)&caddr,(socklen_t*)&ret,SOCK_NONBLOCK)) == -1){
- break;
- }
-
- server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_WEBCLIENT,new server_web_conn(cfd));
- }
- }else if(epevdata->type == SERVER_EPEV_WEBCLIENT){
- winfo = (server_web_conn*)epevdata->data;
- if(ev_flag & EPOLLIN){
- winfo->readio();
- }
- if(ev_flag & EPOLLRDHUP){
- delete winfo;
- delete (server_epevdata*)epev.data.ptr;
- }
- }else if(epevdata->type == SERVER_EPEV_TPOOL){
- tpinfo = (tpool*)epevdata->data;
- if(ev_flag & EPOLLIN){
- tpinfo->done();
- }
- }
- }
- }
-
- close(judge_sfd);
- close(server_epfd);
- close(web_sfd);
-
- return 0;
-}
diff --git a/toj/center/src/center_server.h b/toj/center/src/center_server.h
deleted file mode 100755
index 039e84b..0000000
--- a/toj/center/src/center_server.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#define SERVER_JUDGE_PORT 2573
-#define SERVER_WEB_PORT 2501
-#define SERVER_EPOLL_MAXEVENT 4096
-
-#define SERVER_EPEV_JUDGESERVER 0
-#define SERVER_EPEV_JUDGECLIENT 1
-#define SERVER_EPEV_WEBSERVER 2
-#define SERVER_EPEV_WEBCLIENT 3
-#define SERVER_EPEV_TPOOL 4
-class server_epevdata{
-public:
- int fd;
- int type;
- void *data;
-
- server_epevdata(int fd,int type,void *data);
-};
-
-class server_web_conn{
-private:
- int fd;
- char buf[65536];
- int off;
- int count;
-
-public:
- server_web_conn(int fd);
- ~server_web_conn();
- int readio();
-};
-
-static int server_addepev(int fd,unsigned int flag,int type,void *data);
-static int server_delepev(server_epevdata *epevdata);
-static int server_epfd;
-
-extern int center_manage_init(tpool **tpinfo);
-extern int center_manage_updatedata();
-extern int center_manage_submit(int subid,char *param);
-
-extern int center_judge_init();
-extern void* center_judge_addconn(int fd);
-extern int center_judge_dispatch(int ev_flag,void *data);
-
-extern int pack_pack(char *pack_path,char *dir_path);
-extern int pack_unpack(char *pack_path,char *target_path);
diff --git a/toj/center/src/hyperio/Makefile b/toj/center/src/hyperio/Makefile
deleted file mode 100755
index 655e473..0000000
--- a/toj/center/src/hyperio/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-ifneq ($(KERNELRELEASE),)
- hyperio-objs := hyperio_mod.o judgk_hyperio.o
- obj-m := hyperio.o
-else
- KERNEL_SOURCE := /usr/lib/modules/$(shell uname -r)/build
- PWD := $(shell pwd)
-default:
- ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
-
- g++ -O2 test.cpp -o test
-clean:
- ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
-endif
diff --git a/toj/center/src/hyperio/hyperio_mod.c b/toj/center/src/hyperio/hyperio_mod.c
deleted file mode 100755
index a188b14..0000000
--- a/toj/center/src/hyperio/hyperio_mod.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include<linux/module.h>
-#include<linux/kernel.h>
-#include<linux/kdev_t.h>
-#include<linux/device.h>
-#include<linux/cdev.h>
-#include<linux/fs.h>
-
-#include"../judgk.h"
-#include"../judgk_com.h"
-#include"hyperio_mod.h"
-
-static int __init mod_init(){
- alloc_chrdev_region(&mod_dev,0,1,"hyperio");
- mod_class = class_create(THIS_MODULE,"chardev");
- device_create(mod_class,NULL,mod_dev,NULL,"hyperio");
- cdev_init(&mod_cdev,&mod_fops);
- cdev_add(&mod_cdev,mod_dev,1);
-
- judgk_hyperio_init();
-
- pr_alert("hyperio:Init\n");
- return 0;
-}
-static void __exit mod_exit(){
- judgk_hyperio_exit();
-
- cdev_del(&mod_cdev);
- device_destroy(mod_class,mod_dev);
- class_destroy(mod_class);
- unregister_chrdev_region(mod_dev,1);
-
- pr_alert("hyperio:Exit\n");
-}
-module_init(mod_init);
-module_exit(mod_exit);
-MODULE_LICENSE("Dual BSD/GPL");
-
-static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg){
- long ret;
-
- ret = 0;
- switch(cmd){
- case IOCTL_HYPERIO_ADD:
- ret = judgk_hyperio_add(filp);
- break;
- case IOCTL_HYPERIO_READ:
- ret = judgk_hyperio_read(filp,arg);
- break;
- case IOCTL_HYPERIO_WRITE:
- ret = judgk_hyperio_write(filp,arg);
- break;
- case IOCTL_HYPERIO_DEL:
- ret = judgk_hyperio_del(filp);
- break;
- }
-
- return ret;
-}
diff --git a/toj/center/src/hyperio/hyperio_mod.h b/toj/center/src/hyperio/hyperio_mod.h
deleted file mode 100755
index 3d75b68..0000000
--- a/toj/center/src/hyperio/hyperio_mod.h
+++ /dev/null
@@ -1,21 +0,0 @@
-static int __init mod_init(void);
-static void __exit mod_exit(void);
-
-static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg);
-
-static dev_t mod_dev;
-static struct cdev mod_cdev;
-static struct class *mod_class;
-extern int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
-static struct file_operations mod_fops = {
- .owner = THIS_MODULE,
- .unlocked_ioctl = mod_ioctl,
- .mmap = judgk_hyperio_mmap
-};
-
-extern int judgk_hyperio_init(void);
-extern int judgk_hyperio_exit(void);
-extern int judgk_hyperio_add(struct file *filp);
-extern int judgk_hyperio_read(struct file *filp,size_t len);
-extern int judgk_hyperio_write(struct file *filp,size_t len);
-extern int judgk_hyperio_del(struct file *filp);
diff --git a/toj/center/src/hyperio/test.cpp b/toj/center/src/hyperio/test.cpp
deleted file mode 100755
index 18e536b..0000000
--- a/toj/center/src/hyperio/test.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<unistd.h>
-#include<fcntl.h>
-#include<time.h>
-#include<limits.h>
-#include<math.h>
-#include<termios.h>
-#include<sys/ioctl.h>
-#include<sys/types.h>
-#include<sys/mman.h>
-#include<sys/wait.h>
-
-#include"../judge_def.h"
-#include"../judgm_lib.h"
-
-int fd;
-/*char *rbuf;
-off_t roff = 0;
-
-int judgm_hyperio_compare(char *buf,size_t len){
- int flag;
- size_t remain;
- off_t off;
- size_t data_len;
- size_t cmp_len;
-
- flag = 0;
- remain = len;
- off = 0;
- data_len = 0;
- cmp_len = 0;
- while(remain > 0 && flag == 0){
- if(data_len == 0){
- if((data_len = ioctl(fd,IOCTL_READ,cmp_len)) <= 0){
- return -1;
- }
- }
- if(remain < data_len){
- cmp_len = remain;
- }else{
- cmp_len = data_len;
- }
-
- if((roff + cmp_len) < BUF_SIZE){
- flag |= memcmp(rbuf + roff,buf + off,cmp_len);
- roff += cmp_len;
- }else{
- flag |= memcmp(rbuf + roff,buf + off,BUF_SIZE - roff);
- flag |= memcmp(rbuf,buf + off + (BUF_SIZE - roff),(cmp_len + roff) - BUF_SIZE);
- roff = (cmp_len + roff) - BUF_SIZE;
- }
- remain -= cmp_len;
- off += cmp_len;
- }
- if(cmp_len > 0){
- ioctl(fd,IOCTL_READ,-(long)cmp_len);
- }
-
- if(flag == 0){
- return 0;
- }else{
- return -1;
- }
-}*/
-
-int main(){
- int i,j;
- char *buf;
- int idx;
- int pid;
- char str[4096];
- int a,b;
- int l;
-
- judgm_hyperio *hyperio;
-
- fd = open("/dev/judgk",O_RDWR);
- hyperio = new judgm_hyperio(fd);
-
- printf("%d\n",hyperio->tty_idx);
-
- if((pid = fork()) == 0){
- int outfd;
-
- outfd = judgm_hyperio::get_ttyfd(0);
-
- //dup2(fd,0);
- dup2(outfd,1);
-
- printf("Hello World\n");
- char *argv[] = {NULL,NULL};
- char *envp[] = {NULL};
-
- execve("/srv/http/toj/center/judge/tmp/run/1/test",argv,envp);
- exit(0);
- }
-
- printf("%d\n",hyperio->compare("Hello World\n",12));
-
- waitpid(pid,NULL,0);
-
- getchar();
- delete hyperio;
- close(fd);
-
- /*flag = 0;
- roff = 0;
- woff = 0;
- srand(23);
- for(i = 0;i < 1000000;i++){
- a = rand() % 65536;
- b = rand() % 65536;
-
- snprintf(str,sizeof(str),"%d %d\n",a,b);
- l = strlen(str);
- j = l;
- len = 0;
- while(j > 0){
- len = ioctl(fd,IOCTL_WRITE,len);
- if(j < len){
- len = j;
- }
-
- if((len + woff) < BUF_SIZE){
- memcpy(wbuf + woff,str + (l - j),len);
- woff += len;
- }else{
- memcpy(wbuf + woff,str + (l - j),BUF_SIZE - woff);
- memcpy(wbuf,str + (l - j) + (BUF_SIZE - woff),(len + woff) - BUF_SIZE);
- woff = (len + woff) - BUF_SIZE;
- }
-
- j -= len;
- }
- ioctl(fd,IOCTL_WRITE,-len);
-
- snprintf(str,sizeof(str),"%d\n",a + b);
- l = strlen(str);
- j = l;
- len = 0;
- while(j > 0){
- len = ioctl(fd,IOCTL_READ,len);
- if(len <= 0){
- flag = 1;
- break;
- }
- if(j < len){
- len = j;
- }
-
- if((roff + len) < BUF_SIZE){
- flag |= memcmp(rbuf + roff,str + (l - j),len);
- roff += len;
- }else{
- flag |= memcmp(rbuf + roff,str + (l - j),BUF_SIZE - roff);
- flag |= memcmp(rbuf,str + (l - j) + (BUF_SIZE - roff),(len + roff) - BUF_SIZE);
- roff = (len + roff) - BUF_SIZE;
- }
-
- j -= len;
- }
- ioctl(fd,IOCTL_READ,-len);
-
- if(flag != 0){
- printf("WA\n");
- break;
- }
- }*/
-
- return 0;
-}
diff --git a/toj/center/src/jmod_test.h b/toj/center/src/jmod_test.h
deleted file mode 100755
index 844f5c8..0000000
--- a/toj/center/src/jmod_test.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#define LINE_ERRMSG_MAXSIZE 4096
-
-typedef int (*check_init_fn)(int judgk_modfd,char *data_path,char *run_path);
-typedef int (*check_run_fn)(int &status,char *err_msg);
-typedef int (*check_stop_fn)();
-
-struct line_set_data{
- int id;
-};
-struct line_result_data{
- int id;
- int status;
- double score;
- unsigned long runtime;
- unsigned long memory;
- char err_msg[LINE_ERRMSG_MAXSIZE];
-};
diff --git a/toj/center/src/jmod_test_check.cpp b/toj/center/src/jmod_test_check.cpp
deleted file mode 100755
index ae4d060..0000000
--- a/toj/center/src/jmod_test_check.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<limits.h>
-#include<unistd.h>
-#include<fcntl.h>
-#include<errno.h>
-
-#include"judge_def.h"
-#include"judgm_lib.h"
-#include"jmod_test.h"
-#include"jmod_test_check.h"
-
-static int ansfd;
-static judgm_hyperio *hyperio;
-static int tty_idx;
-
-int p[2];
-
-DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath){
- char tpath[PATH_MAX + 1];
- char dstpath[PATH_MAX + 1];
-
- pipe(p);
-
- snprintf(tpath,sizeof(tpath),"%s/in",datapath);
- snprintf(dstpath,sizeof(dstpath),"%s/in",runpath);
- if(link(tpath,dstpath)){
- return -1;
- }
- snprintf(tpath,sizeof(tpath),"%s/ans",datapath);
- if((ansfd = open(tpath,O_RDONLY)) == -1){
- return -1;
- }
-
- //hyperio = new judgm_hyperio(judgk_modfd);
- //tty_idx = hyperio->tty_idx;
-
- return 0;
-}
-DLL_PUBLIC int run(int &status,char *err_msg){
- int ret;
-
- char *inbuf;
- char *ansbuf;
-
- status = JUDGE_AC;
- inbuf = new char[65536];
- ansbuf = new char[65536];
-
- /*while((ret = read(ansfd,ansbuf,65536)) > 0){
- if(hyperio->compare(ansbuf,ret)){
- status = JUDGE_WA;
- break;
- }
- }
- if(status == JUDGE_AC && hyperio->wait() > 0){
- status = JUDGE_WA;
- }
-
- delete inbuf;
- delete ansbuf;
- close(ansfd);
- delete hyperio;*/
-
- close(p[1]);
- int c_read=-1,pre_status=status;
- while((ret = read(p[0],inbuf,65536)) > 0){
- if((c_read=read(ansfd,ansbuf,ret)) != ret){
- status = JUDGE_WA;
- break;
- }
- if(memcmp(ansbuf,inbuf,ret)){
- status = JUDGE_WA;
- break;
- }
- }
-// if(c_read - ret == 1 && ansbuf[c_read-1]=='\n'){
-// status = pre_status;
-// }
-
- if(status == JUDGE_AC && ((c_read = read(ansfd,ansbuf,1)) > 1 || c_read == 1 && ansbuf[0]!='\n')){
- status = JUDGE_WA;
- }
-
- return 0;
-}
-DLL_PUBLIC int proc(){
- int infd;
- int outfd;
-
- if((infd = open("in",O_RDONLY)) == -1){
- return -1;
- }
- /*if((outfd = judgm_hyperio::get_ttyfd(tty_idx)) == -1){
- return -1;
- }*/
-
- close(p[0]);
- outfd = p[1];
- dup2(infd,0);
- dup2(outfd,1);
- dup2(outfd,2);
-
- return 0;
-}
-DLL_PUBLIC int stop(){
- return 0;
-}
diff --git a/toj/center/src/jmod_test_check.h b/toj/center/src/jmod_test_check.h
deleted file mode 100755
index 20a6286..0000000
--- a/toj/center/src/jmod_test_check.h
+++ /dev/null
@@ -1,4 +0,0 @@
-DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath);
-DLL_PUBLIC int run(int &status,char *err_msg);
-DLL_PUBLIC int proc();
-DLL_PUBLIC int stop();
diff --git a/toj/center/src/jmod_test_line.cpp b/toj/center/src/jmod_test_line.cpp
deleted file mode 100755
index be1177c..0000000
--- a/toj/center/src/jmod_test_line.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<limits.h>
-#include<dlfcn.h>
-#include<pthread.h>
-#include<json/json.h>
-
-#include"judge_def.h"
-#include"judgm_lib.h"
-#include"judgm_line.h"
-#include"jmod_test.h"
-#include"jmod_test_line.h"
-
-static int line_load_setfile(FILE *set_file,int id,int &timelimit,int &memlimit,double &score){
- int ret;
-
- json_object *jso;
- char buf[JUDGE_SET_FILEMAX];
-
- fread(buf,1,sizeof(buf),set_file);
- jso = json_tokener_parse(buf);
-
- timelimit = json_object_get_int(json_object_object_get(jso,"timelimit"));
- memlimit = json_object_get_int(json_object_object_get(jso,"memlimit"));
- score = json_object_get_double(json_object_array_get_idx(json_object_object_get(jso,"score"),id - 1));
-
- json_object_put(jso);
- return 0;
-}
-static void line_sigaction(int sig_num,siginfo_t *sig_info,void *context){
- if(sig_info->si_pid == line_proc->pid && line_proc->status == JUDGE_RUN){
- if(!line_proc->proc_wait(false)){
- line_chk_stop_fn();
- }
- }
-}
-static int line_sig_set(){
- struct sigaction sig;
-
- sig.sa_sigaction = line_sigaction;
- sigemptyset(&sig.sa_mask);
- sig.sa_flags = SA_SIGINFO | SA_RESTART;
- if(sigaction(SIGCHLD,&sig,NULL)){
- return -1;
- }
-
- return 0;
-}
-static int line_sig_restore(){
- struct sigaction sig;
-
- sig.sa_handler = SIG_DFL;
- sigemptyset(&sig.sa_mask);
- sig.sa_flags = 0;
- if(sigaction(SIGCHLD,&sig,NULL)){
- return -1;
- }
-
- return 0;
-}
-static int line_sig_block(){
- sigset_t mask;
-
- sigemptyset(&mask);
- sigaddset(&mask,SIGCHLD);
- if(pthread_sigmask(SIG_BLOCK,&mask,NULL)){
- return -1;
- }
-
- return 0;
-}
-static int line_sig_unblock(){
- sigset_t mask;
-
- sigemptyset(&mask);
- sigaddset(&mask,SIGCHLD);
- if(pthread_sigmask(SIG_UNBLOCK,&mask,NULL)){
- return -1;
- }
-
- return 0;
-}
-static int line_sig_wait(){
- sigset_t mask;
- int num;
-
- sigfillset(&mask);
- sigdelset(&mask,SIGKILL);
- sigdelset(&mask,SIGTERM);
- sigdelset(&mask,SIGINT);
- sigdelset(&mask,SIGCHLD);
- sigsuspend(&mask);
-
- return 0;
-}
-DLL_PUBLIC int run(judgm_line_info *info){
- int i;
-
- line_result_data *res_data;
-
- int set_timelimit;
- int set_memlimit;
- double set_score;
- line_set_data *set_data;
-
- char main_path[PATH_MAX + 1];
- char exe_path[PATH_MAX + 1];
-
- check_init_fn chk_init_fn;
- check_run_fn chk_run_fn;
- judgm_proc_check_fn chk_proc_fn;
-
- char data_path[PATH_MAX + 1];
- int chk_status;
-
- set_data = (line_set_data*)info->set_data;
-
- res_data = (line_result_data*)info->res_data;
- info->res_len = sizeof(line_result_data);
-
- res_data->id = set_data->id;
- res_data->status = JUDGE_ERR;
- res_data->score = 0;
- res_data->runtime = 0;
- res_data->memory = 0;
- res_data->err_msg[0] = '\0';
-
- if(line_load_setfile(info->set_file,set_data->id,set_timelimit,set_memlimit,set_score)){
- return -1;
- }
-
- snprintf(main_path,sizeof(main_path),"%s/main.cpp",info->code_path);
- snprintf(exe_path,sizeof(exe_path),"%s/test",info->run_path);
- if(judgm_compile(info->subid,main_path,exe_path,info->lang,false,res_data->err_msg,LINE_ERRMSG_MAXSIZE)){
- res_data->status = JUDGE_CE;
- return -1;
- }
-
- chk_init_fn = (check_init_fn)dlsym(info->check_dll,"init");
- chk_run_fn = (check_run_fn)dlsym(info->check_dll,"run");
- chk_proc_fn = (judgm_proc_check_fn)dlsym(info->check_dll,"proc");
- line_chk_stop_fn = (check_stop_fn)dlsym(info->check_dll,"stop");
- line_proc = new judgm_proc(info->judgk_modfd,info->run_path,exe_path,set_timelimit,(set_timelimit * 10 + 5000),set_memlimit,chk_proc_fn);
-
- snprintf(data_path,sizeof(data_path),"%s/private/%d",info->pro_path,set_data->id);
- if(chk_init_fn(info->judgk_modfd,data_path,info->run_path)){
- delete line_proc;
- return -1;
- }
- if(line_sig_set()){
- delete line_proc;
- return -1;
- }
-
- if(line_proc->proc_run()){
- delete line_proc;
- return -1;
- }
- chk_run_fn(chk_status,res_data->err_msg);
-
- line_sig_block();
- if(line_proc->status == JUDGE_RUN){
- line_proc->proc_kill();
- line_sig_wait();
- }
- line_sig_unblock();
-
- printf("check status %d proc status %d\n",chk_status,line_proc->status);
-
- if(line_sig_restore()){
- delete line_proc;
- return -1;
- }
-
- if(line_proc->status != JUDGE_AC){
- res_data->status = line_proc->status;
- }else{
- res_data->status = chk_status;
- }
- if(res_data->status == JUDGE_AC){
- res_data->score = set_score;
- }else{
- res_data->score = 0;
- }
- res_data->runtime = line_proc->runtime;
- res_data->memory = line_proc->memory;
-
- delete line_proc;
- return 0;
-}
diff --git a/toj/center/src/jmod_test_line.h b/toj/center/src/jmod_test_line.h
deleted file mode 100755
index c09a503..0000000
--- a/toj/center/src/jmod_test_line.h
+++ /dev/null
@@ -1,11 +0,0 @@
-static int line_load_setfile(FILE *set_file,int test_id,int &timelimit,int &memlimit,double &score);
-static int line_sig_set();
-static int line_sig_restore();
-static int line_sig_block();
-static int line_sig_unblock();
-static int line_sig_wait();
-
-static judgm_proc *line_proc;
-static check_stop_fn line_chk_stop_fn;
-
-DLL_PUBLIC int run(judgm_line_info *info);
diff --git a/toj/center/src/jmod_test_manage.cpp b/toj/center/src/jmod_test_manage.cpp
deleted file mode 100755
index e77adc9..0000000
--- a/toj/center/src/jmod_test_manage.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<limits.h>
-#include<dlfcn.h>
-#include<json/json.h>
-
-#include"judge_def.h"
-#include"judgm_lib.h"
-#include"judgm_manage.h"
-#include"jmod_test.h"
-#include"jmod_test_manage.h"
-
-static void __attribute__ ((constructor)) manage_init(){
- manage_queuesubmit_fn = (judgm_manage_queuesubmit_fn)dlsym(dlopen(NULL,RTLD_NOW),"center_manage_queuesubmit");
-}
-static int manage_load_setfile(FILE *set_file,int &count){
- int ret;
-
- json_object *jso;
- char buf[JUDGE_SET_FILEMAX];
-
- fread(buf,1,sizeof(buf),set_file);
- jso = json_tokener_parse(buf);
-
- count = json_object_get_int(json_object_object_get(jso,"count"));
-
- json_object_put(jso);
- return 0;
-}
-
-DLL_PUBLIC int submit(judgm_manage_info *info,FILE *set_file){
- int i;
-
- int count;
- manage_result_info *res_info;
- line_set_data set_data;
-
- manage_load_setfile(set_file,count);
-
- res_info = new manage_result_info(count);
- info->private_data = res_info;
-
- for(i = 0;i < count;i++){
- set_data.id = i + 1;
- manage_queuesubmit_fn(info->subid,info->proid,info->lang,(char*)&set_data,sizeof(line_set_data));
- }
-
- return 0;
-}
-DLL_PUBLIC int result(judgm_manage_info *info,line_result_data *res_data){
- manage_result_info *res_info;
- json_object *jso_item;
- char tpath[PATH_MAX + 1];
-
- res_info = (manage_result_info*)info->private_data;
- res_info->count++;
-
- if(res_data->status > res_info->result){
- res_info->result = res_data->status;
- }
- res_info->totalscore += res_data->score;
- res_info->totalruntime += res_data->runtime;
- if(res_data->memory > res_info->maxmemory){
- res_info->maxmemory = res_data->memory;
- }
-
- jso_item = json_object_new_object();
- json_object_object_add(jso_item,"status",json_object_new_int(res_data->status));
- json_object_object_add(jso_item,"score",json_object_new_double(res_data->score));
- json_object_object_add(jso_item,"runtime",json_object_new_int64(res_data->runtime));
- json_object_object_add(jso_item,"memory",json_object_new_int64(res_data->memory / 1024UL));
- if(strlen(res_data->err_msg) > 0){
- printf(" strlen %d\n",strlen(res_data->err_msg));
- json_object_object_add(jso_item,"errmsg",json_object_new_string(res_data->err_msg));
- }
- json_object_array_put_idx(res_info->jso_resarray,res_data->id - 1,jso_item);
-
- printf("jmod count %d %d\n",res_info->count,res_info->allcount);
-
- if(res_info->count == res_info->allcount){
- snprintf(tpath,sizeof(tpath),"%s/result",info->res_path);
- json_object_to_file_ext(tpath,res_info->jso_res,JSON_C_TO_STRING_PLAIN);
-
- info->result = res_info->result;
- info->score = res_info->totalscore;
- info->runtime = res_info->totalruntime;
- info->memory = res_info->maxmemory;
-
- delete res_info;
- return 1;
- }
- return 0;
-}
-
-
diff --git a/toj/center/src/jmod_test_manage.h b/toj/center/src/jmod_test_manage.h
deleted file mode 100755
index b0244e3..0000000
--- a/toj/center/src/jmod_test_manage.h
+++ /dev/null
@@ -1,35 +0,0 @@
-class manage_result_info{
-public:
- int allcount;
- int count;
- int result;
- double totalscore;
- unsigned long totalruntime;
- unsigned long maxmemory;
- json_object *jso_res;
- json_object *jso_resarray;
-
- manage_result_info(int allcount){
- this->allcount = allcount;
- this->count = 0;
- this->result = JUDGE_AC;
- this->totalscore = 0;
- this->totalruntime = 0;
- this->maxmemory = 0;
-
- this->jso_res = json_object_new_object();
- this->jso_resarray = json_object_new_array();
- json_object_object_add(this->jso_res,"result",this->jso_resarray);
- }
- ~manage_result_info(){
- json_object_put(jso_res);
- }
-};
-
-DLL_PUBLIC int submit(judgm_manage_info *info,FILE *set_file);
-DLL_PUBLIC int result(judgm_manage_info *info,line_result_data *res_data);
-
-static void __attribute__ ((constructor)) manage_init();
-static int manage_load_setfile(FILE *setfile,int &count);
-
-static judgm_manage_queuesubmit_fn manage_queuesubmit_fn;
diff --git a/toj/center/src/judge.h b/toj/center/src/judge.h
deleted file mode 100644
index 1b5a885..0000000
--- a/toj/center/src/judge.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef JUDGE_H
-#define JUDGE_H
-
-#define JUDGE_THREAD_MAX 16
-#define JUDGE_THREAD_JUDGEMAX 2
-
-#define JUDGE_CACHESTATE_READY 0
-#define JUDGE_CACHESTATE_UPDATE 1
-
-class judge_pro_info{
-public:
- int proid;
- int cacheid;
- int ref_count;
-
- int state;
- int update_cacheid;
-
- judge_pro_info(int proid,int cacheid){
- this->proid = proid;
- this->cacheid = cacheid;
- this->ref_count = 0;
-
- this->state = JUDGE_CACHESTATE_READY;
- this->update_cacheid = 0;
- }
-};
-
-class judge_submit_info{
-public:
- int subid;
- judge_pro_info *pro_info;
- int lang;
- char *set_data;
- int set_len;
-
- judge_submit_info(int subid,judge_pro_info *pro_info,int lang,char *set_data,int set_len){
- this->subid = subid;
- this->pro_info = pro_info;
- this->lang = lang;
- this->set_data = new char[set_len];
- memcpy(this->set_data,set_data,set_len);
- this->set_len = set_len;
- }
- ~judge_submit_info(){
- delete this->set_data;
- }
-};
-
-#endif
diff --git a/toj/center/src/judge_def.h b/toj/center/src/judge_def.h
deleted file mode 100755
index f0722d0..0000000
--- a/toj/center/src/judge_def.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#define JUDGE_AC 0
-#define JUDGE_WA 1
-#define JUDGE_TLE 2
-#define JUDGE_MLE 3
-#define JUDGE_RF 4
-#define JUDGE_RE 5
-#define JUDGE_CE 6
-#define JUDGE_ERR 7
-#define JUDGE_WAIT 100
-#define JUDGE_RUN 101
-
-#define JUDGE_CPP 0x1
-#define JUDGE_JAVA 0x2
-#define JUDGE_PASCEL 0x4
-
-#define JUDGE_SUB_PARAMMAX 4096
-#define JUDGE_SET_FILEMAX 65536
-#define JUDGE_SET_DATAMAX 4096
-#define JUDGE_RES_DATAMAX 65536
-
-#define DLL_PUBLIC extern "C" __attribute__ ((visibility ("default")))
diff --git a/toj/center/src/judge_manage.cpp b/toj/center/src/judge_manage.cpp
deleted file mode 100644
index 32181bc..0000000
--- a/toj/center/src/judge_manage.cpp
+++ /dev/null
@@ -1,371 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<unistd.h>
-#include<limits.h>
-#include<dirent.h>
-#include<dlfcn.h>
-#include<sys/types.h>
-#include<sys/stat.h>
-#include<sys/mman.h>
-#include<map>
-
-#include"tpool.h"
-#include"judge_def.h"
-#include"judge.h"
-#include"judgm_line.h"
-#include"judgm_lib.h"
-#include"judge_manage.h"
-
-int judge_manage_init(){
- int i;
-
- manage_tp = new tpool(JUDGE_THREAD_MAX);
- judge_server_addtpool(manage_tp);
- manage_tp->start();
-
- manage_judgk_modfd = open("/dev/judgk",O_RDWR);
- for(i = 0;i < JUDGE_THREAD_JUDGEMAX;i++){
- manage_judgepool[i] = new manage_judgeth_info(i);
- }
- manage_updatepro_thfn = new tpool_static_fn(manage_updatepro_th);
- manage_updatepro_cbfn = new tpool_static_fn(manage_updatepro_cb);
- manage_unpackcode_thfn = new tpool_static_fn(manage_unpackcode_th);
- manage_unpackcode_cbfn = new tpool_static_fn(manage_unpackcode_cb);
- manage_judge_thfn = new tpool_static_fn(manage_judge_th);
- manage_judge_cbfn = new tpool_static_fn(manage_judge_cb);
-
- judge_manage_updatedata();
- return 0;
-}
-int judge_manage_updatedata(){
- DIR *dirp;
- char *buf;
- dirent *entry;
- int proid;
- int cacheid;
- judge_pro_info *pro_info;
-
- if((dirp = opendir("tmp/pro")) == NULL){
- return -1;
- }
- buf = new char[sizeof(dirent) + NAME_MAX + 1];
-
- while(true){
- readdir_r(dirp,(dirent*)buf,&entry);
- if(entry == NULL){
- break;
- }
- if(strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0){
- continue;
- }
-
- if(entry->d_type == DT_DIR){
- sscanf(entry->d_name,"%d_%d",&proid,&cacheid);
- pro_info = new judge_pro_info(proid,cacheid);
- judge_manage_getpro(pro_info);
- judge_manage_promap.insert(std::make_pair(proid,pro_info));
- }
- }
-
- delete(buf);
- closedir(dirp);
-
- return 0;
-}
-
-judge_pro_info* judge_manage_getprobyid(int proid){
- std::map<int,judge_pro_info*>::iterator pro_it;
- judge_pro_info *pro_info;
-
- if((pro_it = judge_manage_promap.find(proid)) == judge_manage_promap.end()){
- return NULL;
- }
- pro_info = pro_it->second;
-
- if(judge_manage_getpro(pro_info)){
- return NULL;
- }
-
- return pro_info;
-}
-int judge_manage_getpro(judge_pro_info *pro_info){
- pro_info->ref_count++;
- return 0;
-}
-int judge_manage_putpro(judge_pro_info *pro_info){
- std::map<int,judge_pro_info*> pro_it;
- char tpath[PATH_MAX + 1];
- char src_path[PATH_MAX + 1];
-
- pro_info->ref_count--;
- if(pro_info->ref_count == 0){
- snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
- tool_cleardir(tpath);
- rmdir(tpath);
-
- delete pro_info;
- }
- return 0;
-}
-int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info){ //If check_flag = true, just check
- int ret;
-
- std::map<int,judge_pro_info*>::iterator pro_it;
- judge_pro_info *old_pro_info;
-
- if((pro_it = judge_manage_promap.find(proid)) == judge_manage_promap.end()){
- if(check_flag == true){
- return 0;
- }
- }else{
- old_pro_info = pro_it->second;
-
- if(old_pro_info->state == JUDGE_CACHESTATE_READY && cacheid == old_pro_info->cacheid){
- return 1;
- }
- if(old_pro_info->state == JUDGE_CACHESTATE_UPDATE && (cacheid <= old_pro_info->cacheid || cacheid <= old_pro_info->update_cacheid)){
- return -1;
- }
-
- if(check_flag == true){
- return 0;
- }
-
- old_pro_info->update_cacheid = cacheid;
- old_pro_info->state = JUDGE_CACHESTATE_UPDATE;
- }
-
- *update_pro_info = new judge_pro_info(proid,cacheid);
- judge_manage_getpro(*update_pro_info);
-
- return 0;
-}
-int judge_manage_done_updatepro(judge_pro_info *pro_info){
- manage_tp->add(manage_updatepro_thfn,pro_info,manage_updatepro_cbfn,pro_info);
- return 0;
-}
-static void manage_updatepro_th(void *data){
- judge_pro_info *pro_info;
- int proid;
- int cacheid;
- char pack_path[PATH_MAX + 1];
- char dir_path[PATH_MAX + 1];
- char tpath[PATH_MAX + 1];
- FILE *f;
-
- pro_info = (judge_pro_info*)data;
-
- snprintf(pack_path,sizeof(pack_path),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid);
- snprintf(dir_path,sizeof(dir_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
- mkdir(dir_path,0755);
- tool_cleardir(dir_path);
- tool_unpack(pack_path,dir_path);
- //unlink(pack_path);
-
- snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d/cacheinfo",pro_info->proid,pro_info->cacheid);
- f = fopen(tpath,"w");
- fprintf(f,"%d",pro_info->cacheid);
- fclose(f);
-}
-static void manage_updatepro_cb(void *data){
- judge_pro_info *old_pro_info;
- judge_pro_info *update_pro_info;
- std::pair<std::map<int,judge_pro_info*>::iterator,bool> ins_ret;
- std::vector<std::pair<int,int> > pro_list;
-
- update_pro_info = (judge_pro_info*)data;
-
- ins_ret = judge_manage_promap.insert(std::make_pair(update_pro_info->proid,update_pro_info));
- if(ins_ret.second == false){
- old_pro_info = ins_ret.first->second;
-
- if(update_pro_info->cacheid < old_pro_info->cacheid){
- judge_manage_putpro(update_pro_info);
- return;
- }
-
- judge_manage_putpro(ins_ret.first->second);
- ins_ret.first->second = update_pro_info;
- }
-
- pro_list.push_back(std::make_pair(update_pro_info->proid,update_pro_info->cacheid));
- judge_server_setpro(pro_list);
-}
-
-
-int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len){
- judge_pro_info *pro_info;
- judge_submit_info *sub_info;
-
- char tpath[PATH_MAX + 1];
- struct stat st;
-
- pro_info = judge_manage_getprobyid(proid);
- sub_info = new judge_submit_info(subid,pro_info,lang,set_data,set_len);
-
- if(manage_submap.find(subid) == manage_submap.end()){
- snprintf(tpath,sizeof(tpath),"tmp/code/%d",subid);
- if(!stat(tpath,&st)){
- manage_queuejudge(sub_info);
- }else{
- judge_server_reqcode(subid);
- manage_submap.insert(std::make_pair(subid,sub_info));
- }
- }else{
- manage_submap.insert(std::make_pair(subid,sub_info));
- }
-
- return 0;
-}
-int judge_manage_done_code(int subid){
- manage_tp->add(manage_unpackcode_thfn,(void*)((long)subid),manage_unpackcode_cbfn,(void*)((long)subid));
- return 0;
-}
-static void manage_unpackcode_th(void *data){
- int subid;
- char pack_path[PATH_MAX + 1];
- char dir_path[PATH_MAX + 1];
- char tpath[PATH_MAX + 1];
- FILE *f;
-
- subid = (int)((long)data);
-
- snprintf(pack_path,sizeof(pack_path),"tmp/codepack/%d.tar.bz2",subid);
- snprintf(dir_path,sizeof(dir_path),"tmp/code/%d",subid);
- mkdir(dir_path,0755);
- tool_cleardir(dir_path);
- tool_unpack(pack_path,dir_path);
-}
-static void manage_unpackcode_cb(void *data){
- int subid;
- std::multimap<int,judge_submit_info*>::iterator sub_it;
- judge_submit_info *sub_info;
-
- subid = (int)((long)data);
-
- while((sub_it = manage_submap.find(subid)) != manage_submap.end()){
- sub_info = sub_it->second;
- manage_queuejudge(sub_info);
- manage_submap.erase(sub_it);
- }
-}
-static int manage_queuejudge(judge_submit_info *sub_info){
- int i;
-
- printf("queue judge %d %d\n",sub_info->subid,sub_info->pro_info->proid);
- for(i = 0;i < 16;i++){
- if(manage_judgepool[i]->use_flag == false){
- manage_judgepool[i]->use_flag = true;
- manage_judgepool[i]->sub_info = sub_info;
- manage_tp->add(manage_judge_thfn,manage_judgepool[i],manage_judge_cbfn,manage_judgepool[i]);
- break;
- }
- }
-
- return 0;
-}
-static void manage_judge_th(void *data){
- manage_judgeth_info *th_info;
- judge_submit_info *sub_info;
- judge_pro_info *pro_info;
- char pro_path[PATH_MAX + 1];
- char code_path[PATH_MAX + 1];
- char *set_data;
-
- th_info = (manage_judgeth_info*)data;
- sub_info = th_info->sub_info;
- pro_info = sub_info->pro_info;
-
- snprintf(pro_path,sizeof(pro_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
- snprintf(code_path,sizeof(code_path),"tmp/code/%d",sub_info->subid);
- manage_judge(sub_info->subid,pro_path,code_path,th_info->run_path,sub_info->lang,sub_info->set_data,th_info->res_data,th_info->res_len);
-}
-static void manage_judge_cb(void *data){
- manage_judgeth_info *th_info;
- judge_submit_info *sub_info;
- std::vector<std::pair<int,int> > pro_list;
-
- th_info = (manage_judgeth_info*)data;
- sub_info = th_info->sub_info;
-
- judge_server_result(sub_info->subid,th_info->res_data,th_info->res_len);
- judge_manage_putpro(sub_info->pro_info);
-
- th_info->use_flag = false;
- th_info->sub_info = NULL;
- delete sub_info;
-}
-static int manage_judge(int subid,char *pro_path,char *code_path,char *run_path,int lang,char *set_data,char *res_data,size_t &res_len){
- judgm_line_info *line_info;
- int pid;
-
- char tpath[PATH_MAX + 1];
- FILE *set_file;
- char cwd_path[PATH_MAX + 1];
- char jmod_name[NAME_MAX + 1];
- char line_path[PATH_MAX + 1];
- char check_name[NAME_MAX + 1];
- char check_path[PATH_MAX + 1];
- char lchr;
- char tchr;
-
- void *line_dll;
- void *check_dll;
- judgm_line_run_fn run_fn;
-
- snprintf(tpath,sizeof(tpath),"%s/setting",pro_path);
- set_file = fopen(tpath,"r");
-
- getcwd(cwd_path,sizeof(cwd_path));
- fscanf(set_file,"%s",jmod_name);
- snprintf(line_path,sizeof(line_path),"%s/tmp/jmod/%s/%s_line.so",cwd_path,jmod_name,jmod_name);
- fscanf(set_file,"%s",check_name);
- if(check_name[0] == '/'){
- snprintf(check_path,sizeof(check_path),"%s/%s/private%s.so",cwd_path,pro_path,check_name);
- }else{
- snprintf(check_path,sizeof(check_path),"%s/tmp/jmod/%s/%s.so",cwd_path,jmod_name,check_name);
- }
-
- lchr = '\n';
- while((tchr = fgetc(set_file)) != EOF){
- if(lchr == '\n' && tchr == '='){
- while(fgetc(set_file) != '\n');
- break;
- }
- lchr = tchr;
- }
-
- line_dll = dlopen(line_path,RTLD_NOW);
- check_dll = dlopen(check_path,RTLD_NOW);
-
- line_info = (judgm_line_info*)mmap(NULL,sizeof(struct judgm_line_info),PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS,-1,0);
- line_info->subid = subid;
- line_info->pro_path = pro_path;
- line_info->code_path = code_path;
- line_info->run_path = run_path;
-
- line_info->judgk_modfd = manage_judgk_modfd;
- line_info->line_dll = line_dll;
- line_info->check_dll = check_dll;
-
- line_info->lang = lang;
- line_info->set_file = set_file;
- line_info->set_data = set_data;
-
- tool_cleardir(line_info->run_path);
-
- run_fn = (judgm_line_run_fn)dlsym(line_dll,"run");
- if((pid = fork()) == 0){
- run_fn(line_info);
- exit(0);
- }
- waitpid(pid,NULL,0);
-
- memcpy(res_data,line_info->res_data,line_info->res_len);
- res_len = line_info->res_len;
-
- munmap(line_info,sizeof(judgm_line_info));
- fclose(set_file);
- return 0;
-}
diff --git a/toj/center/src/judge_manage.h b/toj/center/src/judge_manage.h
deleted file mode 100644
index 594ea71..0000000
--- a/toj/center/src/judge_manage.h
+++ /dev/null
@@ -1,60 +0,0 @@
-class manage_judgeth_info{
-public:
- bool use_flag;
- int thid;
- char run_path[PATH_MAX + 1];
- judge_submit_info *sub_info;
- char res_data[JUDGE_RES_DATAMAX];
- size_t res_len;
-
- manage_judgeth_info(int thid){
- this->use_flag = false;
- this->thid = thid;
- snprintf(this->run_path,sizeof(this->run_path),"tmp/run/%d",thid);
- mkdir(this->run_path,0775);
- this->sub_info = NULL;
- this->res_len = 0;
- }
-};
-
-static void manage_updatepro_th(void *data);
-static void manage_updatepro_cb(void *data);
-static void manage_unpackcode_th(void *data);
-static void manage_unpackcode_cb(void *data);
-static void manage_judge_th(void *data);
-static void manage_judge_cb(void *data);
-static int manage_queuejudge(judge_submit_info *sub_info);
-static int manage_judge(int subid,char *pro_path,char *code_path,char *run_path,int lang,char *set_data,char *res_data,size_t &res_len);
-
-static tpool *manage_tp;
-static int manage_judgk_modfd;
-static manage_judgeth_info *manage_judgepool[16];
-static tpool_static_fn *manage_updatepro_thfn;
-static tpool_static_fn *manage_updatepro_cbfn;
-static tpool_static_fn *manage_unpackcode_thfn;
-static tpool_static_fn *manage_unpackcode_cbfn;
-static tpool_static_fn *manage_judge_thfn;
-static tpool_static_fn *manage_judge_cbfn;
-static std::multimap<int,judge_submit_info*> manage_submap;
-
-int judge_manage_init();
-int judge_manage_updatedata();
-judge_pro_info* judge_manage_getprobyid(int proid);
-int judge_manage_getpro(judge_pro_info *pro_info);
-int judge_manage_putpro(judge_pro_info *pro_info);
-int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info);
-int judge_manage_done_updatepro(judge_pro_info *pro_info);
-int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len);
-int judge_manage_done_code(int subid);
-
-std::map<int,judge_pro_info*> judge_manage_promap;
-
-extern int tool_pack(char *pack_path,char *dir_path);
-extern int tool_unpack(char *pack_path,char *dir_path);
-extern int tool_cleardir(char *path);
-
-extern int judge_server_addtpool(tpool *tpinfo);
-extern int judge_server_setpro(std::vector<std::pair<int,int> > &pro_list);
-extern int judge_server_reqpro(int subid);
-extern int judge_server_reqcode(int subid);
-extern int judge_server_result(int subid,char *res_data,int res_len);
diff --git a/toj/center/src/judge_server.cpp b/toj/center/src/judge_server.cpp
deleted file mode 100755
index 66b4d01..0000000
--- a/toj/center/src/judge_server.cpp
+++ /dev/null
@@ -1,515 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<unistd.h>
-#include<fcntl.h>
-#include<dlfcn.h>
-#include<signal.h>
-#include<limits.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<errno.h>
-#include<sys/types.h>
-#include<sys/socket.h>
-#include<sys/epoll.h>
-#include<sys/eventfd.h>
-#include<sys/sendfile.h>
-#include<sys/mman.h>
-#include<netinet/in.h>
-#include<arpa/inet.h>
-#include<map>
-#include<queue>
-
-#include"netio.h"
-#include"tpool.h"
-#include"judge_def.h"
-#include"judge.h"
-#include"center_com.h"
-#include"judgm_line.h"
-#include"judgm_lib.h"
-#include"judge_server.h"
-
-server_epevdata::server_epevdata(int fd,int type,void *data){
- this->fd = fd;
- this->type = type;
- this->data = data;
-}
-
-
-server_conn::server_conn(int fd):netio(fd){
- this->recv_dispatch_fn = new netio_iofn<server_conn>(this,&server_conn::recv_dispatch);
- this->recv_setid_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setid);
- this->recv_submit_fn = new netio_iofn<server_conn>(this,&server_conn::recv_submit);
- this->recv_setpro_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setpro);
- this->recv_sendpro_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendpro);
- this->done_sendpro_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendpro);
- this->recv_setjmod_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setjmod);
- this->recv_sendjmod_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendjmod);
- this->done_sendjmod_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendjmod);
- this->recv_sendcode_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendcode);
- this->done_sendcode_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendcode);
- this->tp_unpackjmod_thfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackjmod_th);
- this->tp_unpackjmod_cbfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackjmod_cb);
-
- send_setid();
-}
-char* server_conn::create_combuf(int code,int size,int &len,void **data){
- char *buf;
- center_com_header *header;
-
- buf = new char[sizeof(center_com_header) + size];
- header = (center_com_header*)buf;
- header->code = code;
- header->size = size;
- len = sizeof(center_com_header) + size;
- *data = (void*)(buf + sizeof(center_com_header));
-
- return buf;
-}
-int server_conn::send_setid(){
- char *write_buf;
- int write_len;
- center_com_setid *setid;
-
- write_buf = create_combuf(CENTER_COMCODE_SETID,sizeof(center_com_setid),write_len,(void**)&setid);
- setid->id = server_id;
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int server_conn::send_setinfo(){
- char *write_buf;
- int write_len;
- center_com_setinfo *setinfo;
-
- write_buf = create_combuf(CENTER_COMCODE_SETINFO,sizeof(center_com_setinfo),write_len,(void**)&setinfo);
- setinfo->avail = server_avail;
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int server_conn::send_result(int subid,char *res_data,size_t res_len){
- char *write_buf;
- int write_len;
- center_com_result *result;
-
- if(res_len > JUDGE_RES_DATAMAX){
- return -1;
- }
-
- write_buf = create_combuf(CENTER_COMCODE_RESULT,sizeof(center_com_result) + res_len,write_len,(void**)&result);
- result->subid = subid;
- memcpy((void*)(write_buf + sizeof(center_com_header) + sizeof(center_com_result)),res_data,res_len);
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int server_conn::send_reqpro(int proid,int cacheid){
- char *write_buf;
- int write_len;
- center_com_reqpro *reqpro;
-
- write_buf = create_combuf(CENTER_COMCODE_REQPRO,sizeof(center_com_reqpro),write_len,(void**)&reqpro);
- reqpro->proid = proid;
- reqpro->cacheid = cacheid;
- writebytes(write_buf,write_len,NULL,NULL);
-}
-int server_conn::send_setpro(std::vector<std::pair<int,int> > &pro_list,int type){
- int i;
- int count;
- char *write_buf;
- int write_len;
- center_com_setpro *setpro;
- judge_pro_info *pro_info;
-
- count = pro_list.size();
- write_buf = create_combuf(CENTER_COMCODE_SETPRO,sizeof(center_com_setpro) * count,write_len,(void**)&setpro);
-
- for(i = 0;i < count;i++){
- setpro[i].proid = pro_list[i].first;
- setpro[i].cacheid = pro_list[i].second;
- setpro[i].type = type;
- }
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int server_conn::send_setjmod(char **jmod_name,int *cacheid,int type,int count){
- int i;
-
- char *write_buf;
- int write_len;
- center_com_setjmod *setjmod;
-
- write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod);
- for(i = 0;i < count;i++){
- setjmod[i].jmod_name[0] = '\0';
- strncat(setjmod[i].jmod_name,jmod_name[i],sizeof(setjmod[i].jmod_name));
- setjmod[i].cacheid = cacheid[i];
- setjmod[i].type = type;
- }
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int server_conn::send_reqcode(int subid){
- char *write_buf;
- int write_len;
- center_com_reqcode *reqcode;
-
- write_buf = create_combuf(CENTER_COMCODE_REQCODE,sizeof(center_com_reqcode),write_len,(void**)&reqcode);
- reqcode->subid = subid;
- writebytes(write_buf,write_len,NULL,NULL);
-
- return 0;
-}
-int server_conn::readidle(){
- readbytes(new center_com_header,sizeof(center_com_header),recv_dispatch_fn,NULL);
- return 0;
-}
-void server_conn::recv_dispatch(void *buf,size_t len,void *data){
- center_com_header *header;
- char *readbuf;
-
- header = (center_com_header*)buf;
- readbuf = new char[header->size];
- printf("code:%d size:%d\n",header->code,header->size);
- switch(header->code){
- case CENTER_COMCODE_SETID:
- readbytes(readbuf,header->size,recv_setid_fn,NULL);
- break;
- case CENTER_COMCODE_SUBMIT:
- readbytes(readbuf,header->size,recv_submit_fn,NULL);
- break;
- case CENTER_COMCODE_SETPRO:
- readbytes(readbuf,header->size,recv_setpro_fn,NULL);
- break;
- case CENTER_COMCODE_SENDPRO:
- readbytes(readbuf,header->size,recv_sendpro_fn,NULL);
- break;
- case CENTER_COMCODE_SETJMOD:
- readbytes(readbuf,header->size,recv_setjmod_fn,NULL);
- break;
- case CENTER_COMCODE_SENDJMOD:
- readbytes(readbuf,header->size,recv_sendjmod_fn,NULL);
- break;
- case CENTER_COMCODE_SENDCODE:
- readbytes(readbuf,header->size,recv_sendcode_fn,NULL);
- break;
- }
-
- delete header;
-}
-void server_conn::recv_setid(void *buf,size_t len,void *data){
- center_com_setid *setid;
-
- setid = (center_com_setid*)buf;
- server_id = setid->id;
- printf("server_id:%d\n",server_id);
-
- //judge server init
- send_setinfo();
-
- delete setid;
-}
-void server_conn::recv_submit(void *buf,size_t len,void *data){
- center_com_submit *sub;
-
- sub = (center_com_submit*)buf;
- judge_manage_submit(sub->subid,sub->proid,sub->lang,(char*)((char*)buf + sizeof(center_com_submit)),len - sizeof(center_com_submit));
-
- delete sub;
-}
-void server_conn::recv_setpro(void *buf,size_t len,void *data){
- int ret;
- int i;
- int count;
- center_com_setpro *setpro;
-
- char tpath[PATH_MAX + 1];
- FILE *f;
- int cacheid;
- std::vector<std::pair<int,int> > pro_list;
-
- count = len / sizeof(center_com_setpro);
- setpro = (center_com_setpro*)buf;
- for(i = 0;i < count;i++){
- if(setpro[i].type == 0){
- ret = judge_manage_updatepro(setpro[i].proid,setpro[i].cacheid,true,NULL);
- if(ret == 0){
- if(server_fileconn == NULL){
- server_fileconn = server_connect();
- }
- server_fileconn->send_reqpro(setpro[i].proid,setpro[i].cacheid);
- }else if(ret == 1){
- pro_list.push_back(std::make_pair(setpro[i].proid,setpro[i].cacheid));
- }
- }else if(setpro[i].type == 1){
-
- }
- }
-
- if(!pro_list.empty()){
- this->send_setpro(pro_list,0);
- }
-
- delete setpro;
-}
-void server_conn::recv_sendpro(void *buf,size_t len,void *data){
- center_com_sendpro *sendpro;
- judge_pro_info *pro_info;
- char tpath[PATH_MAX + 1];
- int fd;
-
- sendpro = (center_com_sendpro*)buf;
-
- if(judge_manage_updatepro(sendpro->proid,sendpro->cacheid,false,&pro_info) == 0){
- snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",sendpro->proid,sendpro->cacheid);
- fd = open(tpath,O_WRONLY | O_CREAT,0644);
- readfile(fd,sendpro->filesize,done_sendpro_fn,pro_info);
- }
-
- delete sendpro;
-}
-void server_conn::done_sendpro(void *buf,size_t len,void *data){
- judge_pro_info *pro_info;
-
- close(*(int*)buf);
-
- pro_info = (judge_pro_info*)data;
- judge_manage_done_updatepro(pro_info);
-}
-void server_conn::recv_setjmod(void *buf,size_t len,void *data){
- int i;
- int count;
- center_com_setjmod *setjmod;
-
- char tpath[PATH_MAX + 1];
- FILE *f;
- int cacheid;
- std::vector<char*> sl_jmod_name;
- std::vector<int> sl_cacheid;
-
- char *write_buf;
- int write_len;
- center_com_reqjmod *reqjmod;
-
- count = len / sizeof(center_com_setjmod);
- setjmod = (center_com_setjmod*)buf;
- for(i = 0;i < count;i++){
- if(setjmod[i].type == 0){
- snprintf(tpath,sizeof(tpath),"tmp/jmod/%s/cacheinfo",setjmod[i].jmod_name);
- f = fopen(tpath,"r");
- if(f != NULL){
- fscanf(f,"%d",&cacheid);
- fclose(f);
-
- if(cacheid == setjmod[i].cacheid){
- sl_jmod_name.push_back(setjmod[i].jmod_name);
- sl_cacheid.push_back(setjmod[i].cacheid);
- continue;
- }
- }
-
- if(server_fileconn == NULL){
- server_fileconn = server_connect();
- }
-
- write_buf = create_combuf(CENTER_COMCODE_REQJMOD,sizeof(center_com_reqjmod),write_len,(void**)&reqjmod);
- reqjmod->jmod_name[0] = '\0';
- strncat(reqjmod->jmod_name,setjmod[i].jmod_name,sizeof(reqjmod->jmod_name));
- server_fileconn->writebytes(write_buf,write_len,NULL,NULL);
- }else if(setjmod[i].type == 1){
-
- }
- }
-
- if(!sl_jmod_name.empty()){
- this->send_setjmod(&sl_jmod_name[0],&sl_cacheid[0],0,sl_jmod_name.size());
- }
-
- delete setjmod;
-}
-void server_conn::recv_sendjmod(void *buf,size_t len,void *data){
- center_com_sendjmod *sendjmod;
- char tpath[PATH_MAX + 1];
- int fd;
-
- sendjmod = (center_com_sendjmod*)buf;
- snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s.tar.bz2",sendjmod->jmod_name);
- fd = open(tpath,O_WRONLY | O_CREAT,0644);
- readfile(fd,sendjmod->filesize,done_sendjmod_fn,sendjmod);
-}
-void server_conn::done_sendjmod(void *buf,size_t len,void *data){
- center_com_sendjmod *sendjmod;
-
- close(*(int*)buf);
-
- sendjmod = (center_com_sendjmod*)data;
- server_packtp->add(tp_unpackjmod_thfn,sendjmod,tp_unpackjmod_cbfn,sendjmod);
-}
-void server_conn::recv_sendcode(void *buf,size_t len,void *data){
- center_com_sendcode *sendcode;
- char tpath[PATH_MAX + 1];
- int fd;
-
- sendcode = (center_com_sendcode*)buf;
- snprintf(tpath,sizeof(tpath),"tmp/codepack/%d.tar.bz2",sendcode->subid);
- fd = open(tpath,O_WRONLY | O_CREAT,0644);
- readfile(fd,sendcode->filesize,done_sendcode_fn,sendcode);
-}
-void server_conn::done_sendcode(void *buf,size_t len,void *data){
- center_com_sendcode *sendcode;
-
- close(*(int*)buf);
-
- sendcode = (center_com_sendcode*)data;
- judge_manage_done_code(sendcode->subid);
-
- delete sendcode;
-}
-void server_conn::tp_unpackjmod_th(void *data){
- center_com_sendjmod *sendjmod;
- char pack_path[PATH_MAX + 1];
- char dir_path[PATH_MAX + 1];
- char tpath[PATH_MAX + 1];
- FILE *f;
-
- sendjmod = (center_com_sendjmod*)data;
-
- snprintf(pack_path,sizeof(pack_path),"tmp/jmodpack/%s.tar.bz2",sendjmod->jmod_name);
- snprintf(dir_path,sizeof(dir_path),"tmp/jmod/%s",sendjmod->jmod_name);
- mkdir(dir_path,0755);
- tool_cleardir(dir_path);
- tool_unpack(pack_path,dir_path);
-
- snprintf(tpath,sizeof(tpath),"tmp/jmod/%s/cacheinfo",sendjmod->jmod_name);
- f = fopen(tpath,"w");
- fprintf(f,"%d",sendjmod->cacheid);
- fclose(f);
-}
-void server_conn::tp_unpackjmod_cb(void *data){
- center_com_sendjmod *sendjmod;
- char *jmod_name;
-
- sendjmod = (center_com_sendjmod*)data;
- jmod_name = sendjmod->jmod_name;
- send_setjmod(&jmod_name,&sendjmod->cacheid,0,1);
-
- delete sendjmod;
-}
-
-
-
-int judge_server_addtpool(tpool *tpinfo){
- server_addepev(tpinfo->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,tpinfo);
- return 0;
-}
-int judge_server_setpro(std::vector<std::pair<int,int> > &pro_list){
- server_mainconn->send_setpro(pro_list,0);
- return 0;
-}
-int judge_server_reqcode(int subid){
- if(server_codeconn == NULL){
- server_codeconn = server_connect();
- }
- server_codeconn->send_reqcode(subid);
-
- return 0;
-}
-int judge_server_result(int subid,char *res_data,int res_len){
- server_mainconn->send_result(subid,res_data,res_len);
- return 0;
-}
-
-static int server_addepev(int fd,unsigned int flag,int type,void *data){
- server_epevdata *epevdata;
- epoll_event epev;
-
- epevdata = new server_epevdata(fd,type,data);
- epev.events = flag;
- epev.data.ptr = epevdata;
- epoll_ctl(server_epfd,EPOLL_CTL_ADD,fd,&epev);
-
- return 0;
-}
-static int server_delepev(server_epevdata *epevdata){
- epoll_ctl(server_epfd,EPOLL_CTL_DEL,epevdata->fd,NULL);
- delete epevdata;
- return 0;
-}
-static server_conn* server_connect(){
- int cfd;
- sockaddr_in caddr;
- epoll_event epev;
- server_conn *cinfo;
-
- cfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6);
- caddr.sin_family = AF_INET;
- caddr.sin_port = htons(SERVER_JUDGE_PORT);
- //caddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- caddr.sin_addr.s_addr = inet_addr("10.8.0.2");
-
- cinfo = new server_conn(cfd);
- server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,cinfo);
- connect(cfd,(sockaddr*)&caddr,sizeof(caddr));
-
- return cinfo;
-}
-int main(){
- int i;
-
- epoll_event epev;
- epoll_event epevs[SERVER_EPOLL_MAXEVENT];
- int nevs;
-
- int ev_flag;
- server_epevdata *epevdata;
- server_conn *cinfo;
- tpool *tpinfo;
-
- signal(SIGPIPE,SIG_IGN);
- server_epfd = epoll_create1(0);
-
- server_id = 0;
- server_avail = JUDGE_THREAD_JUDGEMAX;
- server_mainconn = server_connect();
- server_fileconn = NULL;
- server_codeconn = NULL;
-
- judge_manage_init();
-
- server_packtp = new tpool(4);
- judge_server_addtpool(server_packtp);
- server_packtp->start();
-
-
- while(true){
- nevs = epoll_wait(server_epfd,epevs,SERVER_EPOLL_MAXEVENT,-1);
- for(i = 0;i < nevs;i++){
- ev_flag = epevs[i].events;
- epevdata = (server_epevdata*)epevs[i].data.ptr;
-
- if(epevdata->type == SERVER_EPEV_JUDGECLIENT){
- cinfo = (server_conn*)epevdata->data;
- if(ev_flag & EPOLLIN){
- cinfo->readio();
- }
- if(ev_flag & EPOLLOUT){
- cinfo->writeio();
- }
-
- server_packtp->done();
- }else if(epevdata->type = SERVER_EPEV_TPOOL){
- tpinfo = (tpool*)epevdata->data;
- if(ev_flag & EPOLLIN){
- tpinfo->done();
- }
- }
- }
- }
-
- close(server_epfd);
-
- return 0;
-}
diff --git a/toj/center/src/judge_server.h b/toj/center/src/judge_server.h
deleted file mode 100755
index 90a4e7c..0000000
--- a/toj/center/src/judge_server.h
+++ /dev/null
@@ -1,87 +0,0 @@
-#define SERVER_JUDGE_PORT 2573
-#define SERVER_EPOLL_MAXEVENT 4096
-
-#define SERVER_EPEV_JUDGECLIENT 0
-#define SERVER_EPEV_TPOOL 1
-class server_epevdata{
-public:
- int fd;
- int type;
- void *data;
-
- server_epevdata(int fd,int type,void *data);
-};
-
-class server_conn : public netio{
-private:
- netio_iofn<server_conn> *recv_dispatch_fn;
- netio_iofn<server_conn> *recv_setid_fn;
- netio_iofn<server_conn> *recv_submit_fn;
- netio_iofn<server_conn> *recv_setpro_fn;
- netio_iofn<server_conn> *recv_sendpro_fn;
- netio_iofn<server_conn> *done_sendpro_fn;
- netio_iofn<server_conn> *recv_setjmod_fn;
- netio_iofn<server_conn> *recv_sendjmod_fn;
- netio_iofn<server_conn> *done_sendjmod_fn;
- netio_iofn<server_conn> *recv_sendcode_fn;
- netio_iofn<server_conn> *done_sendcode_fn;
- tpool_fn<server_conn> *tp_unpackjmod_thfn;
- tpool_fn<server_conn> *tp_unpackjmod_cbfn;
-
- char* create_combuf(int code,int size,int &len,void **data);
- void recv_dispatch(void *buf,size_t len,void *data);
- void recv_setid(void *buf,size_t len,void *data);
- void recv_submit(void *buf,size_t len,void *data);
- void recv_setpro(void *buf,size_t len,void *data);
- void recv_sendpro(void *buf,size_t len,void *data);
- void done_sendpro(void *buf,size_t len,void *data);
- void recv_setjmod(void *buf,size_t len,void *data);
- void recv_sendjmod(void *buf,size_t len,void *data);
- void done_sendjmod(void *buf,size_t len,void *data);
- void recv_sendcode(void *buf,size_t len,void *data);
- void done_sendcode(void *buf,size_t len,void *data);
- void tp_unpackjmod_th(void *data);
- void tp_unpackjmod_cb(void *data);
-
-public:
- server_conn(int fd);
- int send_setid();
- int send_setinfo();
- int send_result(int subid,char *res_data,size_t res_len);
- int send_reqpro(int proid,int cacheid);
- int send_setpro(std::vector<std::pair<int,int> > &pro_list,int type);
- int send_setjmod(char **jmod_name,int *cacheid,int type,int count);
- int send_reqcode(int subid);
- virtual int readidle();
-};
-
-static int server_addepev(int fd,unsigned int flag,int type,void *data);
-static int server_delepev(server_epevdata *epevdata);
-static server_conn* server_connect();
-
-static int server_id;
-static int server_avail;
-static int server_epfd;
-static server_conn *server_mainconn;
-static server_conn *server_fileconn;
-static server_conn *server_codeconn;
-static tpool *server_packtp;
-
-int judge_server_addtpool(tpool *tpinfo);
-int judge_server_setpro(std::vector<std::pair<int,int> > &pro_list);
-int judge_server_reqcode(int subid);
-int judge_server_result(int subid,char *res_data,int res_len);
-
-extern int tool_pack(char *pack_path,char *dir_path);
-extern int tool_unpack(char *pack_path,char *dir_path);
-extern int tool_cleardir(char *path);
-
-extern int judge_manage_init();
-extern judge_pro_info* judge_manage_getprobyid(int proid);
-extern int judge_manage_getpro(judge_pro_info *pro_info);
-extern int judge_manage_putpro(judge_pro_info *pro_info);
-extern int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info);
-extern int judge_manage_done_updatepro(judge_pro_info *pro_info);
-extern int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len);
-extern int judge_manage_done_code(int subid);
-
diff --git a/toj/center/src/judgk.h b/toj/center/src/judgk.h
deleted file mode 100755
index 18f9a6c..0000000
--- a/toj/center/src/judgk.h
+++ /dev/null
@@ -1,16 +0,0 @@
-struct judgk_proc_info{
- struct hlist_node node;
- struct list_head list;
-
- struct task_struct *task;
- struct file *std_in;
- struct file *std_out;
- char run_path[PATH_MAX + 1];
- int status;
- unsigned long timelimit;
- unsigned long jiff_start;
- unsigned long jiff_end;
- unsigned long memlimit;
- unsigned long runtime;
- unsigned long memory;
-};
diff --git a/toj/center/src/judgk_com.h b/toj/center/src/judgk_com.h
deleted file mode 100755
index 842c69c..0000000
--- a/toj/center/src/judgk_com.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#define IOCTL_PROC_ADD _IOWR('x',0x0,int)
-#define IOCTL_PROC_GET _IOWR('x',0x1,int)
-#define IOCTL_PROC_DEL _IOR('x',0x3,int)
-
-#define IOCTL_HYPERIO_ADD _IOWR('x',0x10,int)
-#define IOCTL_HYPERIO_READ _IOWR('x',0x11,int)
-#define IOCTL_HYPERIO_WRITE _IOWR('x',0x12,int)
-#define IOCTL_HYPERIO_DEL _IOWR('x',0x13,int)
-
-#define JUDGK_COM_HYPERIO_BUFSIZE 4194304
-
-struct judgk_com_proc_add{
- char run_path[PATH_MAX + 1];
- pid_t pid;
- unsigned long kern_task;
- unsigned long timelimit;
- unsigned long hardtimelimit;
- unsigned long memlimit;
-};
-struct judgk_com_proc_get{
- unsigned long kern_task;
- int status;
- unsigned long runtime;
- unsigned long memory;
-};
diff --git a/toj/center/src/judgk_hyperio.c b/toj/center/src/judgk_hyperio.c
deleted file mode 100755
index b37feb7..0000000
--- a/toj/center/src/judgk_hyperio.c
+++ /dev/null
@@ -1,413 +0,0 @@
-#include<linux/fs.h>
-#include<linux/tty.h>
-#include<linux/slab.h>
-#include<linux/mm.h>
-#include<linux/wait.h>
-#include<linux/sched.h>
-#include<asm/atomic.h>
-#include<asm/mman.h>
-
-#include"judgk.h"
-#include"judgk_com.h"
-#include"judgk_hyperio.h"
-
-int judgk_hyperio_init(){
- int i;
- struct hyperio_info *info;
-
- hyperio_filp_ht = (struct hlist_head*)kmalloc(sizeof(struct hlist_head) * HYPERIO_FILP_HTSIZE,GFP_KERNEL);
- for(i = 0;i < HYPERIO_FILP_HTSIZE;i++){
- INIT_HLIST_HEAD(&hyperio_filp_ht[i]);
- }
-
- hyperio_table = (struct hyperio_info*)kmalloc(sizeof(struct hyperio_info) * HYPERIO_MAXNUM,GFP_KERNEL);
- for(i = 0;i < HYPERIO_MAXNUM;i++){
- info = &hyperio_table[i];
-
- atomic_set(&info->ref_count,0);
- info->filp = NULL;
- info->create_flag = false;
- info->end_flag = false;
- info->hook_fops = NULL;
- info->old_fops = NULL;
-
- atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE);
- info->read_off = 0;
- info->read_buf = NULL;
- init_completion(&info->read_rwait);
- init_completion(&info->read_wwait);
-
- atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE);
- info->write_off = 0;
- info->write_buf = NULL;
- init_completion(&info->write_rwait);
- init_completion(&info->write_wwait);
- }
-
- hyperio_tty_drv = tty_alloc_driver(HYPERIO_MAXNUM,TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
- hyperio_tty_drv->owner = THIS_MODULE;
- hyperio_tty_drv->driver_name = "judgk_tty";
- hyperio_tty_drv->name = "jtty";
- hyperio_tty_drv->type = TTY_DRIVER_TYPE_SYSTEM;
- hyperio_tty_drv->subtype = SYSTEM_TYPE_TTY;
- hyperio_tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
- hyperio_tty_drv->init_termios = tty_std_termios;
- hyperio_tty_drv->init_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
- hyperio_tty_drv->init_termios.c_oflag &= ~OPOST;
- hyperio_tty_drv->init_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
- hyperio_tty_drv->init_termios.c_cflag &= ~(CSIZE | PARENB);
- hyperio_tty_drv->init_termios.c_cflag |= CS8;
- tty_set_operations(hyperio_tty_drv,&hyperio_tops);
-
- tty_register_driver(hyperio_tty_drv);
-
- return 0;
-}
-int judgk_hyperio_exit(){
- int i;
-
- for(i = 0;i < HYPERIO_MAXNUM;i++){
- if(hyperio_table[i].create_flag == true){
- tty_unregister_device(hyperio_tty_drv,i);
- hyperio_table[i].create_flag = false;
- }
- }
- tty_unregister_driver(hyperio_tty_drv);
-
- return 0;
-}
-int judgk_hyperio_add(struct file *filp){
- int idx;
- struct hyperio_info *info;
-
- info = NULL;
- for(idx = 0;idx < HYPERIO_MAXNUM;idx++){
- if(atomic_cmpxchg(&hyperio_table[idx].ref_count,0,1) == 0){
- info = &hyperio_table[idx];
- break;
- }
- }
- if(info == NULL){
- return -1;
- }
-
- filp->private_data = info;
-
- info->filp = NULL;
- if(info->create_flag == false){
- tty_port_init(&info->port);
- tty_port_register_device(&info->port,hyperio_tty_drv,idx,NULL);
- info->create_flag = true;
- }
- info->end_flag = false;
- if(info->hook_fops == NULL){
- info->hook_fops = (struct file_operations*)kmalloc(sizeof(struct file_operations),GFP_KERNEL);
- }
-
- atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE);
- info->read_off = 0;
- if(info->read_buf == NULL){
- info->read_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL);
- }
- memset(info->read_buf,0,JUDGK_COM_HYPERIO_BUFSIZE);
- init_completion(&info->read_rwait);
- init_completion(&info->read_wwait);
-
- atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE);
- info->write_off = 0;
- if(info->write_buf == NULL){
- info->write_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL);
- }
- memset(info->write_buf,0,JUDGK_COM_HYPERIO_BUFSIZE);
- init_completion(&info->write_rwait);
- init_completion(&info->write_wwait);
-
- return idx;
-}
-int judgk_hyperio_read(struct file *filp,size_t len){
- struct hyperio_info *info;
- bool wait_flag;
- size_t remain;
-
- if((long)len >= 0){
- wait_flag = true;
- }else{
- wait_flag = false;
- len = -(long)len;
- }
-
- info = (struct hyperio_info*)filp->private_data;
-
- remain = atomic64_read(&info->write_remain);
- if(unlikely(len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){
- return -EINVAL;
- }
-
- if(unlikely(len > 0 && (remain = atomic64_add_return(len,&info->write_remain)) == len)){
- complete(&info->write_wwait);
- }
- if(wait_flag == true){
- while(unlikely(remain == JUDGK_COM_HYPERIO_BUFSIZE)){
- if(info->end_flag == true){
- remain = atomic64_read(&info->write_remain);
- break;
- }
- wait_for_completion_interruptible(&info->write_rwait);
- remain = atomic64_read(&info->write_remain);
- }
- }
-
- return JUDGK_COM_HYPERIO_BUFSIZE - remain;
-}
-int judgk_hyperio_write(struct file *filp,size_t len){
- struct hyperio_info *info;
- bool wait_flag;
- size_t remain;
-
- if((long)len >= 0){
- wait_flag = true;
- }else{
- wait_flag = false;
- len = -(long)len;
- }
-
- info = (struct hyperio_info*)filp->private_data;
-
- remain = atomic64_read(&info->read_remain);
- if(unlikely(len > remain)){
- return -EINVAL;
- }
-
- if(unlikely(len > 0 && (remain = atomic64_sub_return(len,&info->read_remain)) == (JUDGK_COM_HYPERIO_BUFSIZE - len))){
- complete(&info->read_rwait);
- }
- if(wait_flag == true){
- while(unlikely(remain == 0)){
- if(info->end_flag == true){
- remain = atomic64_read(&info->read_remain);
- break;
- }
- wait_for_completion_interruptible(&info->read_wwait);
- remain = atomic64_read(&info->read_remain);
- }
- }
-
- return remain;
-}
-int judgk_hyperio_del(struct file *filp){
- struct hyperio_info *info;
-
- info = (struct hyperio_info*)filp->private_data;
- info->end_flag = true;
- complete(&info->read_rwait);
- complete(&info->read_wwait);
- complete(&info->write_rwait);
- complete(&info->write_wwait);
-
- atomic_dec(&info->ref_count);
- return 0;
-}
-int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma){
- unsigned long size;
- unsigned long off;
- void *buf;
-
- size = vma->vm_end - vma->vm_start;
- off = vma->vm_pgoff << PAGE_SHIFT;
- if((size + off) > JUDGK_COM_HYPERIO_BUFSIZE){
- return -EINVAL;
- }
- if((vma->vm_flags & VM_READ) != 0 && (vma->vm_flags & VM_WRITE) != 0){
- return -EINVAL;
- }
- if((vma->vm_flags & VM_READ) == 0 && (vma->vm_flags & VM_WRITE) == 0){
- return -EINVAL;
- }
-
- if((vma->vm_flags & VM_READ) != 0){
- buf = ((struct hyperio_info*)filp->private_data)->write_buf;
- }else{
- buf = ((struct hyperio_info*)filp->private_data)->read_buf;
- }
- remap_pfn_range(vma,
- vma->vm_start,
- virt_to_phys(buf + off) >> PAGE_SHIFT,
- size,
- vma->vm_page_prot);
-
- return 0;
-}
-
-static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp){
- struct hyperio_info *info;
-
- rcu_read_lock();
-
- info = NULL;
- hlist_for_each_entry_rcu(info,&hyperio_filp_ht[(unsigned long)filp % HYPERIO_FILP_HTSIZE],node){
- if((unsigned long)info->filp == (unsigned long)filp){
- break;
- }
- }
-
- rcu_read_unlock();
-
- return info;
-}
-static int hyperio_tty_open(struct tty_struct *tty, struct file *filp){
- struct hyperio_info *info;
- struct file_operations *hook_fops;
-
- info = &hyperio_table[tty->index];
- atomic_inc(&info->ref_count);
- info->filp = filp;
-
- hook_fops = info->hook_fops;
- info->old_fops = filp->f_op;
- memcpy(hook_fops,filp->f_op,sizeof(struct file_operations));
-
- hook_fops->read = hyperio_tty_filpread;
- hook_fops->write = hyperio_tty_filpwrite;
-
- filp->f_op = hook_fops;
-
- spin_lock(&hyperio_filp_htlock);
-
- hlist_add_head_rcu(&info->node,&hyperio_filp_ht[(unsigned long)info->filp % HYPERIO_FILP_HTSIZE]);
-
- spin_unlock(&hyperio_filp_htlock);
-
- return 0;
-}
-static void hyperio_tty_close(struct tty_struct *tty, struct file *filp){
- struct hyperio_info *info;
-
- info = &hyperio_table[tty->index];
-
- spin_lock(&hyperio_filp_htlock);
-
- hlist_del_rcu(&info->node);
-
- spin_unlock(&hyperio_filp_htlock);
-
- filp->f_op = info->old_fops;
-
- info->end_flag = true;
- complete(&info->read_rwait);
- complete(&info->read_wwait);
- complete(&info->write_rwait);
- complete(&info->write_wwait);
-
- atomic_dec(&info->ref_count);
-}
-static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count){
- return count;
-}
-static int hyperio_tty_write_room(struct tty_struct *tty){
- return JUDGK_COM_HYPERIO_BUFSIZE;
-}
-static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off){
- struct hyperio_info *info;
- size_t buf_len;
- off_t buf_off;
- size_t remain;
- size_t read_len;
- off_t read_off;
-
- if(unlikely(count < 0)){
- return -EINVAL;
- }
-
- info = hyperio_filp_lookup(filp);
- if(unlikely(info == NULL)){
- return -EIO;
- }
-
- buf_len = count;
- buf_off = 0;
- while(likely(buf_len > 0)){
- while(unlikely((remain = atomic64_read(&info->read_remain)) == JUDGK_COM_HYPERIO_BUFSIZE)){
- if(unlikely(info->end_flag == true)){
- return -EIO;
- }
- if(likely(buf_off > 0)){
- return buf_off;
- }
- wait_for_completion_interruptible(&info->read_rwait);
- }
- if(unlikely(buf_len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){
- read_len = JUDGK_COM_HYPERIO_BUFSIZE - remain;
- }else{
- read_len = buf_len;
- }
-
- read_off = info->read_off;
- if(likely((read_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE)){
- copy_to_user(buf + buf_off,info->read_buf + read_off,read_len);
- info->read_off = read_len + read_off;
- }else{
- copy_to_user(buf + buf_off,info->read_buf + read_off,JUDGK_COM_HYPERIO_BUFSIZE - read_off);
- copy_to_user(buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),info->read_buf,(read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE);
- info->read_off = (read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE;
- }
-
- if(unlikely(atomic64_add_return(read_len,&info->read_remain) == read_len)){
- complete(&info->read_wwait);
- }
- buf_len -= read_len;
- buf_off += read_len;
- }
-
- return count;
-}
-static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off){
- struct hyperio_info *info;
- size_t buf_len;
- off_t buf_off;
- size_t remain;
- size_t write_len;
- off_t write_off;
-
- if(unlikely(count < 0)){
- return -EINVAL;
- }
-
- info = hyperio_filp_lookup(filp);
- if(unlikely(info == NULL)){
- return -EIO;
- }
-
- buf_len = count;
- buf_off = 0;
- while(likely(buf_len > 0)){
- while(unlikely((remain = atomic64_read(&info->write_remain)) == 0)){
- if(unlikely(info->end_flag == true)){
- return -EIO;
- }
- wait_for_completion_interruptible(&info->write_wwait);
- }
- if(unlikely(buf_len > remain)){
- write_len = remain;
- }else{
- write_len = buf_len;
- }
-
- write_off = info->write_off;
- if(unlikely((write_len + write_off) >= JUDGK_COM_HYPERIO_BUFSIZE)){
- copy_from_user(info->write_buf + write_off,buf + buf_off,JUDGK_COM_HYPERIO_BUFSIZE - write_off);
- copy_from_user(info->write_buf,buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - write_off),(write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE);
- info->write_off = (write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE;
- }else{
- copy_from_user(info->write_buf + write_off,buf + buf_off,write_len);
- info->write_off = write_len + write_off;
- }
-
- if(unlikely(atomic64_sub_return(write_len,&info->write_remain) == (JUDGK_COM_HYPERIO_BUFSIZE - write_len))){
- complete(&info->write_rwait);
- }
- buf_len -= write_len;
- buf_off += write_len;
- }
-
- return count;
-}
diff --git a/toj/center/src/judgk_hyperio.h b/toj/center/src/judgk_hyperio.h
deleted file mode 100755
index ccc1449..0000000
--- a/toj/center/src/judgk_hyperio.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#define HYPERIO_MAXNUM 256
-#define HYPERIO_FILP_HTSIZE 1009
-
-struct hyperio_info{
- atomic_t ref_count;
- struct hlist_node node;
- struct file *filp;
- struct tty_port port;
-
- bool create_flag;
- bool end_flag;
- struct file_operations *hook_fops;
- const struct file_operations *old_fops;
-
- atomic64_t read_remain;
- off_t read_off;
- char *read_buf;
- struct completion read_rwait;
- struct completion read_wwait;
-
- atomic64_t write_remain;
- off_t write_off;
- char *write_buf;
- struct completion write_rwait;
- struct completion write_wwait;
-};
-
-static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp);
-static int hyperio_tty_open(struct tty_struct * tty, struct file * filp);
-static void hyperio_tty_close(struct tty_struct * tty, struct file * filp);
-static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count);
-static int hyperio_tty_write_room(struct tty_struct *tty);
-static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off);
-static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off);
-
-static struct tty_driver *hyperio_tty_drv;
-static struct tty_operations hyperio_tops = {
- .open = hyperio_tty_open,
- .close = hyperio_tty_close,
- .write = hyperio_tty_write,
- .write_room = hyperio_tty_write_room
-};
-static struct hyperio_info *hyperio_table;
-static struct hlist_head *hyperio_filp_ht;
-static DEFINE_SPINLOCK(hyperio_filp_htlock);
-
-int judgk_hyperio_init(void);
-int judgk_hyperio_exit(void);
-int judgk_hyperio_add(struct file *filp);
-int judgk_hyperio_read(struct file *filp,size_t len);
-int judgk_hyperio_write(struct file *filp,size_t len);
-int judgk_hyperio_del(struct file *filp);
-int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
diff --git a/toj/center/src/judgk_mod.c b/toj/center/src/judgk_mod.c
deleted file mode 100755
index ca2f533..0000000
--- a/toj/center/src/judgk_mod.c
+++ /dev/null
@@ -1,75 +0,0 @@
-#include<linux/module.h>
-#include<linux/kernel.h>
-#include<linux/kdev_t.h>
-#include<linux/device.h>
-#include<linux/cdev.h>
-#include<linux/fs.h>
-#include<linux/sched.h>
-
-#include"judgk.h"
-#include"judgk_com.h"
-#include"judgk_mod.h"
-
-static int __init mod_init(){
- alloc_chrdev_region(&mod_dev,0,1,"judgk");
- mod_class = class_create(THIS_MODULE,"chardev");
- device_create(mod_class,NULL,mod_dev,NULL,"judgk");
- cdev_init(&mod_cdev,&mod_fops);
- cdev_add(&mod_cdev,mod_dev,1);
-
- judgk_proc_init();
- judgk_security_hook();
- judgk_syscall_hook();
- judgk_hyperio_init();
-
- pr_alert("judgk:Init\n");
- return 0;
-}
-static void __exit mod_exit(){
- cdev_del(&mod_cdev);
- device_destroy(mod_class,mod_dev);
- class_destroy(mod_class);
- unregister_chrdev_region(mod_dev,1);
-
- judgk_proc_exit();
- judgk_syscall_unhook();
- judgk_security_unhook();
- judgk_hyperio_exit();
-
- schedule_timeout_interruptible(3 * HZ);
- pr_alert("judgk:Exit\n");
-}
-module_init(mod_init);
-module_exit(mod_exit);
-MODULE_LICENSE("Dual MIT/GPL");
-
-static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg){
- int ret;
-
- ret = -1;
- switch(cmd){
- case IOCTL_PROC_ADD:
- ret = judgk_proc_add(arg);
- break;
- case IOCTL_PROC_GET:
- ret = judgk_proc_get(arg);
- break;
- case IOCTL_PROC_DEL:
- ret = judgk_proc_del(arg);
- break;
- case IOCTL_HYPERIO_ADD:
- ret = judgk_hyperio_add(filp);
- break;
- case IOCTL_HYPERIO_READ:
- ret = judgk_hyperio_read(filp,arg);
- break;
- case IOCTL_HYPERIO_WRITE:
- ret = judgk_hyperio_write(filp,arg);
- break;
- case IOCTL_HYPERIO_DEL:
- ret = judgk_hyperio_del(filp);
- break;
- }
-
- return ret;
-}
diff --git a/toj/center/src/judgk_mod.h b/toj/center/src/judgk_mod.h
deleted file mode 100755
index 58bc76b..0000000
--- a/toj/center/src/judgk_mod.h
+++ /dev/null
@@ -1,31 +0,0 @@
-static int __init mod_init(void);
-static void __exit mod_exit(void);
-static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg);
-
-static dev_t mod_dev;
-static struct cdev mod_cdev;
-static struct class *mod_class;
-
-extern int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
-static struct file_operations mod_fops = {
- .owner = THIS_MODULE,
- .unlocked_ioctl = mod_ioctl,
- .mmap = judgk_hyperio_mmap
-};
-
-extern int judgk_proc_init(void);
-extern int judgk_proc_exit(void);
-extern int judgk_proc_add(unsigned long arg);
-extern int judgk_proc_get(unsigned long arg);
-extern int judgk_proc_del(unsigned long arg);
-extern int judgk_syscall_hook(void);
-extern int judgk_syscall_unhook(void);
-extern int judgk_security_hook(void);
-extern int judgk_security_unhook(void);
-
-extern int judgk_hyperio_init(void);
-extern int judgk_hyperio_exit(void);
-extern int judgk_hyperio_add(struct file *filp);
-extern int judgk_hyperio_read(struct file *filp,size_t len);
-extern int judgk_hyperio_write(struct file *filp,size_t len);
-extern int judgk_hyperio_del(struct file *filp);
diff --git a/toj/center/src/judgk_proc.c b/toj/center/src/judgk_proc.c
deleted file mode 100755
index f3ed130..0000000
--- a/toj/center/src/judgk_proc.c
+++ /dev/null
@@ -1,248 +0,0 @@
-#include<linux/fs.h>
-#include<linux/slab.h>
-#include<linux/fdtable.h>
-#include<linux/sched.h>
-#include<linux/kthread.h>
-#include<asm/uaccess.h>
-
-#include"judge_def.h"
-#include"judgk.h"
-#include"judgk_com.h"
-#include"judgk_proc.h"
-
-int judgk_proc_init(){
- int i;
-
- proc_task_ht = kmalloc(sizeof(struct hlist_head) * PROC_TASK_HTSIZE,GFP_KERNEL);
- for(i = 0;i < PROC_TASK_HTSIZE;i++){
- INIT_HLIST_HEAD(&proc_task_ht[i]);
- }
- proc_info_cachep = kmem_cache_create("proc_info_cachep",sizeof(struct judgk_proc_info),0,0,NULL);
-
- proc_watcher_task = kthread_run(proc_watcher,NULL,"judgk_proc");
-
- return 0;
-}
-int judgk_proc_exit(){
- kthread_stop(proc_watcher_task);
- return 0;
-}
-
-int judgk_proc_add(unsigned long arg){
- int ret;
-
- struct task_struct *task;
- struct judgk_proc_info *info;
- struct judgk_com_proc_add *com_proc_add;
-
- ret = 0;
- com_proc_add = kmalloc(sizeof(struct judgk_com_proc_add),GFP_KERNEL);
- copy_from_user(com_proc_add,(void* __user)arg,sizeof(struct judgk_com_proc_add));
-
- if((task = get_pid_task(find_vpid(com_proc_add->pid),PIDTYPE_PID)) == NULL){
- ret = -1;
- goto end;
- }
- if(judgk_proc_task_lookup(task) != NULL){
- put_task_struct(task);
- ret = -1;
- goto end;
- }
-
- info = kmem_cache_alloc(proc_info_cachep,GFP_KERNEL);
- info->task = task;
- info->std_in = fcheck_files(task->files,0);
- info->std_out = fcheck_files(task->files,1);
- info->status = JUDGE_AC;
- info->timelimit = com_proc_add->timelimit;
- info->jiff_start = jiffies;
- info->jiff_end = info->jiff_start + usecs_to_jiffies(com_proc_add->hardtimelimit);
- info->memlimit = com_proc_add->memlimit;
- info->runtime = 0L;
- info->memory = 0L;
-
- if(proc_get_path(com_proc_add->run_path,info->run_path)){
- put_task_struct(task);
- kmem_cache_free(proc_info_cachep,info);
-
- ret = -1;
- goto end;
- }
- proc_close_fd(task);
-
- spin_lock(&proc_task_htlock);
-
- list_add_rcu(&info->list,&proc_task_list);
- hlist_add_head_rcu(&info->node,&proc_task_ht[(unsigned long)info->task % PROC_TASK_HTSIZE]);
-
- spin_unlock(&proc_task_htlock);
-
- com_proc_add->kern_task = (unsigned long)task;
- copy_to_user((void* __user)arg,com_proc_add,sizeof(struct judgk_com_proc_add));
-
-end:
-
- kfree(com_proc_add);
-
- return ret;
-}
-int judgk_proc_get(unsigned long arg){
- struct task_struct *task;
- struct judgk_proc_info *info;
- struct judgk_com_proc_get *com_proc_get;
-
- com_proc_get = kmalloc(sizeof(struct judgk_com_proc_get),GFP_KERNEL);
- copy_from_user(com_proc_get,(void* __user)arg,sizeof(struct judgk_com_proc_get));
- task = (struct task_struct*)com_proc_get->kern_task;
- if((info = judgk_proc_task_lookup(task)) == NULL){
- kfree(com_proc_get);
- return -1;
- }
-
- com_proc_get->status = info->status;
- if(info->runtime > 0L){
- com_proc_get->runtime = info->runtime;
- }else{
- com_proc_get->runtime = cputime_to_usecs(task->utime);
- info->runtime = com_proc_get->runtime;
- }
- com_proc_get->memory = info->memory;
-
- copy_to_user((void* __user)arg,com_proc_get,sizeof(struct judgk_com_proc_get));
- kfree(com_proc_get);
-
- spin_lock(&proc_task_htlock);
-
- list_del_rcu(&info->list);
- hlist_del_rcu(&info->node);
-
- spin_unlock(&proc_task_htlock);
-
- synchronize_rcu();
-
- put_task_struct(info->task);
- kmem_cache_free(proc_info_cachep,info);
-
- return 0;
-}
-int judgk_proc_del(unsigned long arg){
- struct task_struct *task;
- struct judgk_proc_info *info;
-
- task = (struct task_struct*)arg;
- if((info = judgk_proc_task_lookup(task)) == NULL){
- return -1;
- }
-
- spin_lock(&proc_task_htlock);
-
- list_del_rcu(&info->list);
- hlist_del_rcu(&info->node);
-
- spin_unlock(&proc_task_htlock);
-
- synchronize_rcu();
-
- put_task_struct(info->task);
- kmem_cache_free(proc_info_cachep,info);
-
- return 0;
-}
-struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task){
- struct judgk_proc_info *info;
-
- rcu_read_lock();
-
- info = NULL;
- hlist_for_each_entry_rcu(info,&proc_task_ht[(unsigned long)task % PROC_TASK_HTSIZE],node){
- if((unsigned long)info->task == (unsigned long)task){
- break;
- }
- }
-
- rcu_read_unlock();
-
- return info;
-}
-
-static int proc_watcher(void *data){
- struct judgk_proc_info *info;
-
- while(!kthread_should_stop()){
-
- rcu_read_lock();
-
- list_for_each_entry_rcu(info,&proc_task_list,list){
- if(cputime_to_usecs(info->task->utime) > info->timelimit){
- info->status = JUDGE_TLE;
- send_sig(SIGKILL,info->task,0);
- }else if(time_after(jiffies,info->jiff_end)){
- info->runtime = jiffies_to_usecs((unsigned long)(-((long)info->jiff_start - (long)jiffies)));
- info->status = JUDGE_TLE;
- send_sig(SIGKILL,info->task,0);
- }
- }
-
- rcu_read_unlock();
-
- schedule_timeout_interruptible(HZ / 2);
- }
-
- return 0;
-}
-static int proc_get_path(char *in_path,char *real_path){
- struct file *f;
- char *buf_path;
-
- if(IS_ERR(f = filp_open(in_path,O_RDONLY,0))){
- return -1;
- }
-
- buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL);
- real_path[0] = '\0';
- strncat(real_path,d_path(&f->f_path,buf_path,PATH_MAX + 1),PATH_MAX + 1);
- kfree(buf_path);
- filp_close(f,NULL);
-
- return 0;
-}
-//Watch out kernel update
-static int proc_close_fd(struct task_struct *task){
- struct file *f;
- struct files_struct *files;
- struct fdtable *fdt;
- int fd;
-
- files = task->files;
-
- spin_lock(&files->file_lock);
-
- fdt = files_fdtable(files);
- for(fd = 3;fd < fdt->max_fds;fd++){
- if((fd = find_next_bit(fdt->open_fds,fdt->max_fds,fd)) >= fdt->max_fds){
- break;
- }
- f = fdt->fd[fd];
- if(f == NULL){
- continue;
- }
-
- rcu_assign_pointer(fdt->fd[fd],NULL);
- __clear_bit(fd,fdt->close_on_exec);
- __clear_bit(fd,fdt->open_fds);
- if(fd < files->next_fd){
- files->next_fd = fd;
- }
-
- spin_unlock(&files->file_lock);
-
- filp_close(f,files);
-
- spin_lock(&files->file_lock);
-
- }
-
- spin_unlock(&files->file_lock);
-
- return 0;
-}
diff --git a/toj/center/src/judgk_proc.h b/toj/center/src/judgk_proc.h
deleted file mode 100755
index fd60d30..0000000
--- a/toj/center/src/judgk_proc.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#define PROC_TASK_HTSIZE 1009
-
-static int proc_watcher(void *data);
-static int proc_get_path(char *in_path,char *real_path);
-static int proc_close_fd(struct task_struct *task);
-
-static struct task_struct *proc_watcher_task;
-static LIST_HEAD(proc_task_list);
-static struct hlist_head *proc_task_ht;
-static DEFINE_SPINLOCK(proc_task_htlock);
-static struct kmem_cache *proc_info_cachep;
-
-int judgk_proc_init(void);
-int judgk_proc_exit(void);
-int judgk_proc_add(unsigned long arg);
-int judgk_proc_get(unsigned long arg);
-int judgk_proc_del(unsigned long arg);
-struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task);
diff --git a/toj/center/src/judgk_security.c b/toj/center/src/judgk_security.c
deleted file mode 100755
index d998223..0000000
--- a/toj/center/src/judgk_security.c
+++ /dev/null
@@ -1,309 +0,0 @@
-#include<linux/fs.h>
-#include<linux/security.h>
-#include<linux/sched.h>
-#include<linux/hardirq.h>
-#include<linux/vmalloc.h>
-#include<asm/uaccess.h>
-
-#include"judge_def.h"
-#include"judgk.h"
-#include"judgk_security.h"
-
-int judgk_security_hook(){
- int i;
-
- int count;
- size_t len;
- unsigned long *ori_array;
- unsigned long *hook_array;
- void *addr;
-
- security_init_hook();
-
- ori_sops = (struct security_operations*)*security_hook_addr;
- memcpy(&hook_sops,ori_sops,sizeof(struct security_operations));
-
- judgk_security_checkaddr = (unsigned long)security_check;
-
- count = (sizeof(hook_sops) - sizeof(hook_sops.name)) / sizeof(unsigned long);
- len = (judgk_security_blockend - judgk_security_block) + sizeof(unsigned long);
- security_block_code = __vmalloc(((((len * count - 1) >> PAGE_SHIFT) + 1) << PAGE_SHIFT),GFP_KERNEL | GFP_ATOMIC,PAGE_KERNEL_EXEC);
-
- ori_array = (unsigned long*)(((char*)ori_sops) + offsetof(struct security_operations,ptrace_access_check));
- hook_array = (unsigned long*)(((char*)&hook_sops) + offsetof(struct security_operations,ptrace_access_check));
- for(i = 0;i < count;i++){
- addr = (((char*)security_block_code) + len * i);
- memcpy(addr,&ori_array[i],sizeof(unsigned long));
- memcpy(((char*)addr + sizeof(unsigned long)),judgk_security_block,len - sizeof(unsigned long));
- hook_array[i] = (unsigned long)addr + sizeof(unsigned long);
- }
-
- hook_sops.capable = ori_sops->capable;
- hook_sops.bprm_set_creds = ori_sops->bprm_set_creds;
- hook_sops.bprm_check_security = ori_sops->bprm_check_security;
- hook_sops.bprm_secureexec = ori_sops->bprm_secureexec;
- hook_sops.bprm_committing_creds = ori_sops->bprm_committing_creds;
- hook_sops.bprm_committed_creds = ori_sops->bprm_committed_creds;
- hook_sops.inode_alloc_security = ori_sops->inode_alloc_security;
- hook_sops.inode_free_security = ori_sops->inode_free_security;
- hook_sops.inode_follow_link = ori_sops->inode_follow_link;
- hook_sops.inode_getattr = ori_sops->inode_getattr;
- hook_sops.file_alloc_security = ori_sops->file_alloc_security;
- hook_sops.file_free_security = ori_sops->file_free_security;
- hook_sops.mmap_addr = ori_sops->mmap_addr;
- hook_sops.mmap_file = ori_sops->mmap_file;
- hook_sops.file_mprotect = ori_sops->file_mprotect;
- hook_sops.task_free = ori_sops->task_free;
- hook_sops.cred_free = ori_sops->cred_free;
- hook_sops.cred_prepare = ori_sops->cred_prepare;
-
- hook_sops.inode_permission = hook_inode_permission;
- hook_sops.file_permission = hook_file_permission;
- hook_sops.file_open = hook_file_open;
- hook_sops.file_ioctl = hook_file_ioctl;
- hook_sops.d_instantiate = hook_d_instantiate;
- hook_sops.vm_enough_memory = hook_vm_enough_memory;
-
- *security_hook_addr = (unsigned long)&hook_sops;
-
- return 0;
-}
-int judgk_security_unhook(){
- *security_hook_addr = (unsigned long)ori_sops;
- return 0;
-}
-
-static int security_init_hook(){
- ssize_t ret;
- int i;
- int j;
-
- struct file *f;
- char line[128];
- unsigned char code[3] = {0x48,0xc7,0x05};
- unsigned long addr;
-
- f = filp_open("/proc/meminfo",O_RDONLY,0);
- security_meminfo_ino = f->f_dentry->d_inode->i_ino;
- filp_close(f,NULL);
-
- f = filp_open("/proc/kallsyms",O_RDONLY,0);
- set_fs(KERNEL_DS);
-
- i = 0;
- addr = 0;
- while(true){
- ret = f->f_op->read(f,&line[i],1,&f->f_pos);
-
- if(line[i] == '\n' || ret <= 0){
- line[i] = '\0';
-
- addr = 0;
- for(j = 0;j < i;j++){
- if(line[j] == ' '){
- j++;
- break;
- }
-
- addr *= 16UL;
- if(line[j] >= '0' && line[j] <= '9'){
- addr += (unsigned long)(line[j] - '0');
- }else{
- addr += (unsigned long)(line[j] - 'a' + 10);
- }
- }
- for(;j < i;j++){
- if(line[j] == ' '){
- j++;
- break;
- }
- }
- if(j < i){
- if(strcmp("reset_security_ops",line + j) == 0){
- break;
- }
- }
-
- i = 0;
- }else{
- i++;
- }
-
- if(ret <= 0){
- break;
- }
- }
-
- set_fs(USER_DS);
- filp_close(f,NULL);
-
- i = 0;
- while(i < 3){
- if(*(unsigned char*)addr != code[i]){
- i = 0;
- }else{
- i++;
- }
- addr++;
- }
-
- security_hook_addr = (unsigned long*)(addr + (unsigned long)*(unsigned int*)addr + 8UL);
-
- return 0;
-}
-static inline void security_kill(void){
- send_sig(SIGKILL,current,0);
-}
-static long security_check(void){
- struct judgk_proc_info *info;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL || in_interrupt())){
- return 0;
- }
-
- pr_alert("judgk:PID %d RF\n",current->tgid);
-
- info->status = JUDGE_RF;
- security_kill();
-
- return -EACCES;
-}
-
-static int hook_inode_permission(struct inode *inode,int mask){
- struct judgk_proc_info *info;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL || in_interrupt())){
- return ori_sops->inode_permission(inode,mask);
- }
-
- if((mask & ~(MAY_EXEC | MAY_READ | MAY_OPEN | MAY_CHDIR | MAY_NOT_BLOCK)) != 0){
- pr_alert("judgk:PID %d RF inode_permission %08x\n",current->tgid,mask);
-
- info->status = JUDGE_RF;
- security_kill();
-
- return -EACCES;
- }
- return ori_sops->inode_permission(inode,mask);
-}
-static int hook_file_permission(struct file *file,int mask){
- struct judgk_proc_info *info;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL || in_interrupt())){
- return ori_sops->file_permission(file,mask);
- }
-
- if((mask & ~(MAY_READ | MAY_WRITE)) != 0){
- info->status = JUDGE_RF;
- security_kill();
-
- return -EACCES;
- }else if((mask & MAY_WRITE) != 0 && file != info->std_out){
- info->status = JUDGE_RF;
- security_kill();
-
- return -EACCES;
- }
- return ori_sops->file_permission(file,mask);
-}
-static int hook_file_open(struct file *file, const struct cred *cred){
- int ret;
- int i;
-
- struct judgk_proc_info *info;
- char *buf_path,*path;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL || in_interrupt())){
- return ori_sops->file_open(file,cred);
- }
-
- ret = 0;
- buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL);
- path = d_path(&file->f_path,buf_path,PATH_MAX + 1);
-
- if((file->f_mode & !(FMODE_READ | FMODE_LSEEK | FMODE_PREAD | FMODE_EXEC)) != 0){
- ret = -EACCES;
- }else if(file->f_dentry->d_inode == NULL || file->f_dentry->d_inode->i_ino != security_meminfo_ino){
- i = 0;
- while(info->run_path[i] != '\0'){
- if(path[i] != info->run_path[i]){
- ret = -EACCES;
- break;
- }
- i++;
- }
- if(path[i] == info->run_path[i]){
- ret = -EACCES;
- }
- }
-
- kfree(buf_path);
-
- if(ret != 0){
- pr_alert("judgk:PID %d RF file_open %s %08x\n",current->tgid,path,file->f_mode);
-
- info->status = JUDGE_RF;
- security_kill();
-
- return ret;
- }
- return ori_sops->file_open(file,cred);
-}
-static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg){
- struct judgk_proc_info *info;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL || in_interrupt())){
- return ori_sops->file_ioctl(file,cmd,arg);
- }
-
- if(file != info->std_in && file != info->std_out){
- pr_alert("judgk:PID %d file_ioctl\n",current->tgid);
-
- info->status = JUDGE_RF;
- security_kill();
-
- return -EACCES;
- }
- return ori_sops->file_ioctl(file,cmd,arg);
-}
-static void hook_d_instantiate(struct dentry *dentry,struct inode *inode){
- struct judgk_proc_info *info;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL || in_interrupt())){
- return ori_sops->d_instantiate(dentry,inode);
- }
-
- if(inode == NULL || inode->i_ino != security_meminfo_ino){
- pr_alert("judgk:PID %d d_instantiate\n",current->tgid);
-
- info->status = JUDGE_RF;
- security_kill();
- }
- return ori_sops->d_instantiate(dentry,inode);
-}
-static int hook_vm_enough_memory(struct mm_struct *mm,long pages){
- struct judgk_proc_info *info;
-
- info = judgk_proc_task_lookup(current);
- if(likely(info == NULL)){
- return ori_sops->vm_enough_memory(mm,pages);
- }
-
- info->memory = (mm->total_vm + pages) << PAGE_SHIFT;
-
- if(info->memory > info->memlimit){
- pr_alert("judgk:PID %d vm_enough_memory %lu\n",current->tgid,info->memory);
-
- info->status = JUDGE_MLE;
- security_kill();
-
- return -EACCES;
- }
- return ori_sops->vm_enough_memory(mm,pages);
-}
diff --git a/toj/center/src/judgk_security.h b/toj/center/src/judgk_security.h
deleted file mode 100755
index 3855d7b..0000000
--- a/toj/center/src/judgk_security.h
+++ /dev/null
@@ -1,25 +0,0 @@
-static int security_init_hook(void);
-static inline void security_kill(void);
-static long security_check(void);
-
-static unsigned long security_meminfo_ino;
-static unsigned long* security_hook_addr;
-static struct security_operations *ori_sops;
-static struct security_operations hook_sops;
-static void *security_block_code;
-
-int judgk_security_hook(void);
-int judgk_security_unhook(void);
-
-unsigned long judgk_security_checkaddr;
-
-extern struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task);
-extern void judgk_security_block(void);
-extern void judgk_security_blockend(void);
-
-static int hook_inode_permission(struct inode *inode,int mask);
-static int hook_file_permission(struct file *file,int mask);
-static int hook_file_open(struct file *file, const struct cred *cred);
-static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg);
-static void hook_d_instantiate(struct dentry *dentry,struct inode *inode);
-static int hook_vm_enough_memory(struct mm_struct *mm,long pages);
diff --git a/toj/center/src/judgk_security_asm.S b/toj/center/src/judgk_security_asm.S
deleted file mode 100644
index 80edf37..0000000
--- a/toj/center/src/judgk_security_asm.S
+++ /dev/null
@@ -1,57 +0,0 @@
-.code64
-.section .data //Don't run these code, just data for copy
-.global judgk_security_block
-.global judgk_security_blockend
-.extern judgk_security_checkaddr
-
-//First 8 bytes is original function address
-judgk_security_block:
- push %rbx
- push %rcx
- push %rdx
- push %rsi
- push %rdi
- push %rbp
- push %r8
- push %r9
- push %r10
- push %r11
- push %r12
- push %r13
- push %r14
- push %r15
- pushfq
-
- callq *(judgk_security_checkaddr)
-
- popfq
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %r11
- pop %r10
- pop %r9
- pop %r8
- pop %rbp
- pop %rdi
- pop %rsi
- pop %rdx
- pop %rcx
- pop %rbx
-
- test %rax,%rax
- jnz .block
-
- call .getrip
-.offset:
- sub $(.offset - judgk_security_block + 8),%rax
- jmp *(%rax)
-
-.block:
- ret
-
-.getrip:
- mov (%rsp),%rax
- ret
-judgk_security_blockend:
diff --git a/toj/center/src/judgk_syscall.c b/toj/center/src/judgk_syscall.c
deleted file mode 100755
index c876283..0000000
--- a/toj/center/src/judgk_syscall.c
+++ /dev/null
@@ -1,235 +0,0 @@
-#include<linux/fs.h>
-#include<linux/slab.h>
-#include<linux/sched.h>
-#include<linux/sort.h>
-#include<asm/msr.h>
-#include<asm/unistd.h>
-#include<asm/uaccess.h>
-
-#include"judge_def.h"
-#include"judgk.h"
-#include"judgk_com.h"
-#include"judgk_syscall.h"
-
-int judgk_syscall_hook(){
- int i;
- int j;
-
- unsigned int size;
- unsigned int restore;
-
- syscall_init_hook();
-
- syscall_addr_write((unsigned long)syscall_table,&size,&restore);
- for(i = 0,j = 0;i < syscall_max;i++){
- if(size == 0){
- syscall_addr_restore((unsigned long)(syscall_table + i - 1),restore);
- syscall_addr_write((unsigned long)(syscall_table + i),&size,&restore);
- }
- size -= sizeof(unsigned long);
-
- if(i == syscall_whitelist[j]){
- j++;
- continue;
- }
- syscall_table[i] = (unsigned long)judgk_syscall_block;
- }
- syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore);
-
- return 0;
-}
-int judgk_syscall_unhook(){
- int i;
-
- unsigned int size;
- unsigned int restore;
-
- syscall_addr_write((unsigned long)syscall_table,&size,&restore);
- for(i = 0;i < syscall_max;i++){
- if(size == 0){
- syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore);
- syscall_addr_write((unsigned long)(&syscall_table[i]),&size,&restore);
- }
- size -= sizeof(unsigned long);
-
- syscall_table[i] = (unsigned long)judgk_syscall_ori_table[i];
- }
- syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore);
-
- kfree(judgk_syscall_ori_table);
- return 0;
-}
-static int syscall_init_hook(){
- ssize_t ret;
- int i;
- int j;
-
- struct file *f;
- char line[128];
- unsigned char code[3] = {0xff,0x14,0xc5};
- unsigned long addr;
-
- f = filp_open("/proc/kallsyms",O_RDONLY,0);
- set_fs(KERNEL_DS);
-
- i = 0;
- addr = 0;
- while(true){
- ret = f->f_op->read(f,&line[i],1,&f->f_pos);
-
- if(line[i] == '\n' || ret <= 0){
- line[i] = '\0';
-
- addr = 0;
- for(j = 0;j < i;j++){
- if(line[j] == ' '){
- j++;
- break;
- }
-
- addr *= 16UL;
- if(line[j] >= '0' && line[j] <= '9'){
- addr += (unsigned long)(line[j] - '0');
- }else{
- addr += (unsigned long)(line[j] - 'a' + 10);
- }
- }
- for(;j < i;j++){
- if(line[j] == ' '){
- j++;
- break;
- }
- }
- if(j < i){
- if(strcmp("system_call",line + j) == 0){
- break;
- }
- }
-
- i = 0;
- }else{
- i++;
- }
-
- if(ret <= 0){
- break;
- }
- }
-
- set_fs(USER_DS);
- filp_close(f,NULL);
-
- while(true){
- for(i = 0;i < 3;i++){
- if(*(unsigned char*)addr != code[i]){
- addr++;
- break;
- }
- addr++;
- }
- if(i == 3){
- break;
- }
- }
- syscall_table = (unsigned long*)(0xffffffff00000000 + *((unsigned int*)addr));
-
- addr -= 4L;
- while(true){
- if(*(unsigned char*)addr == 0x3d){
- addr++;
- break;
- }
- addr--;
- }
- syscall_max = *(unsigned int*)addr;
-
- judgk_syscall_ori_table = kmalloc(sizeof(unsigned long) * (syscall_max + 1),GFP_KERNEL);
- memcpy(judgk_syscall_ori_table,syscall_table,sizeof(unsigned long) * syscall_max);
-
- sort(syscall_whitelist,SYSCALL_WHITELIST_SIZE,sizeof(unsigned int),syscall_whitelist_cmp,NULL);
-
- return 0;
-}
-static int syscall_whitelist_cmp(const void *a,const void *b){
- if(*(unsigned int*)a < *(unsigned int*)b){
- return -1;
- }else if(*(unsigned int*)a == *(unsigned int*)b){
- return 0;
- }else{
- return 1;
- }
-}
-static int syscall_addr_write(unsigned long addr,unsigned int *size,int *restore){
- unsigned int level;
- pte_t *pte;
-
- pte = lookup_address(addr,&level);
- if(pte->pte & _PAGE_RW){
- *restore = 0;
- }else{
- pte->pte |= _PAGE_RW;
- *restore = 1;
- }
-
- switch(level){
- case PG_LEVEL_4K:
- *size = 4096;
- break;
- case PG_LEVEL_2M:
- *size = 2097152;
- break;
- case PG_LEVEL_1G:
- *size = 1073741824;
- break;
- }
- *size -= (((unsigned int)addr) & (*size - 1));
-
- return 0;
-}
-static int syscall_addr_restore(unsigned long addr,int restore){
- unsigned int level;
- pte_t *pte;
-
- if(restore){
- pte = lookup_address(addr,&level);
- pte->pte ^= _PAGE_RW;
- }
-
- return 0;
-}
-
-long judgk_syscall_check(){
- struct judgk_proc_info *info;
-
- if((info = judgk_proc_task_lookup(current)) == NULL){
- return 0;
- }
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
-
- return -EACCES;
-}
-
-/*asmlinkage long hook_sys_nanosleep(struct timespec __user *rqtp,struct timespec __user *rmtp){
- long ret;
-
- struct judgm_proc_info *info;
-
- atomic64_inc(&syscall_pending);
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- ret = ori_sys_nanosleep(rqtp,rmtp);
- atomic64_dec(&syscall_pending);
- return ret;
- }
-
- pr_alert("judgm:PID %d nanosleep\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
-
- atomic64_dec(&syscall_pending);
- return -EACCES;
-}*/
diff --git a/toj/center/src/judgk_syscall.h b/toj/center/src/judgk_syscall.h
deleted file mode 100755
index 143a2db..0000000
--- a/toj/center/src/judgk_syscall.h
+++ /dev/null
@@ -1,69 +0,0 @@
-#define SYSCALL_WHITELIST_SIZE 45
-
-static int syscall_init_hook(void);
-static int syscall_whitelist_cmp(const void *a,const void *b);
-static int syscall_addr_write(unsigned long addr,unsigned int *size,int *restore);
-static int syscall_addr_restore(unsigned long addr,int restore);
-
-static unsigned long* syscall_table;
-static unsigned int syscall_max;
-static unsigned int syscall_whitelist[SYSCALL_WHITELIST_SIZE] = {
- __NR_execve,
- __NR_open,
- __NR_creat,
- __NR_unlink,
- __NR_access,
- __NR_truncate,
- __NR_stat,
- __NR_lstat,
- __NR_readlink,
- __NR_exit,
- __NR_read,
- __NR_write,
- __NR_close,
- __NR_lseek,
- __NR_getpid,
- __NR_getuid,
- __NR_dup,
- __NR_brk,
- __NR_getgid,
- __NR_geteuid,
- __NR_getegid,
- __NR_dup2,
- __NR_ftruncate,
- __NR_fstat,
- __NR_personality,
- __NR_readv,
- __NR_writev,
- __NR_getresuid,
- __NR_pread64,
- __NR_pwrite64,
- __NR_fcntl,
- __NR_mmap,
- __NR_munmap,
- __NR_ioctl,
- __NR_uname,
- __NR_gettid,
- __NR_set_thread_area,
- __NR_get_thread_area,
- __NR_set_tid_address,
- __NR_exit_group,
- __NR_arch_prctl,
- __NR_times,
- __NR_time,
- __NR_clock_gettime,
- __NR_dup3
-};
-
-int judgk_syscall_hook(void);
-int judgk_syscall_unhook(void);
-long judgk_syscall_check(void);
-
-unsigned long *judgk_syscall_ori_table;
-
-extern struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task);
-extern long judgk_syscall_block(void);
-
-//typedef asmlinkage long (*func_sys_nanosleep)(struct timespec __user *rqtp,struct timespec __user *rmtp);
-//func_sys_nanosleep ori_sys_nanosleep;
-//asmlinkage long hook_sys_nanosleep(struct timespec __user *rqtp,struct timespec __user *rmtp);
diff --git a/toj/center/src/judgk_syscall_asm.S b/toj/center/src/judgk_syscall_asm.S
deleted file mode 100755
index 03ff960..0000000
--- a/toj/center/src/judgk_syscall_asm.S
+++ /dev/null
@@ -1,54 +0,0 @@
-.code64
-.section .text
-.global judgk_syscall_block
-.extern judgk_syscall_check
-
-judgk_syscall_block:
- push %rax
- push %rbx
- push %rcx
- push %rdx
- push %rsi
- push %rdi
- push %rbp
- push %r8
- push %r9
- push %r10
- push %r11
- push %r12
- push %r13
- push %r14
- push %r15
- pushfq
-
- call judgk_syscall_check
-
- popfq
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %r11
- pop %r10
- pop %r9
- pop %r8
- pop %rbp
- pop %rdi
- pop %rsi
- pop %rdx
- pop %rcx
- pop %rbx
-
- test %rax,%rax
- pop %rax
- jnz .block
-
- push %rdx //use rdx, because mul rax => rdx:rax, kill two birds with one stone
- mov $8,%rdx
- mul %rdx
- pop %rdx
- add judgk_syscall_ori_table,%rax
- jmp *(%rax)
-
-.block:
- ret
diff --git a/toj/center/src/judgm_lib.h b/toj/center/src/judgm_lib.h
deleted file mode 100755
index 2007763..0000000
--- a/toj/center/src/judgm_lib.h
+++ /dev/null
@@ -1,419 +0,0 @@
-#include<string.h>
-#include<limits.h>
-#include<unistd.h>
-#include<signal.h>
-#include<limits.h>
-#include<errno.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<fcntl.h>
-#include<sys/ioctl.h>
-#include<sys/resource.h>
-#include<sys/stat.h>
-#include<sys/types.h>
-#include<sys/wait.h>
-#include<sys/mman.h>
-#include<map>
-#include<utility>
-
-#include"judge.h"
-#include"judgk_com.h"
-
-typedef int (*judgm_proc_check_fn)();
-
-class judgm_proc{
-private:
- int init(){
- int i;
- int j;
- struct stat st;
-
- if(stat(exe_path,&st)){
- return -1;
- }
- if(!S_ISREG(st.st_mode)){
- return -1;
- }
-
- exe_name[NAME_MAX] = '\0';
- for(i = 0,j = 0;exe_path[i] != '\0' && j < NAME_MAX;i++){
- if(exe_path[i] == '/'){
- j = 0;
- }else{
- exe_name[j] = exe_path[i];
- j++;
- }
- }
- exe_name[j] = '\0';
-
- pid = 0;
- kern_task = 0;
- status = JUDGE_WAIT;
- runtime = 0;
- memory = 0;
-
- return 0;
- }
- int protect(){
- rlimit limit;
- judgk_com_proc_add com_proc_add;
-
- limit.rlim_cur = 1;
- limit.rlim_max = limit.rlim_cur;
- prlimit(pid,RLIMIT_NPROC,&limit,NULL);
-
- limit.rlim_cur = 8L;
- limit.rlim_max = limit.rlim_cur;
- prlimit(pid,RLIMIT_NOFILE,&limit,NULL);
-
- limit.rlim_cur = 70368744177664L;
- limit.rlim_max = limit.rlim_cur;
- prlimit(pid,RLIMIT_STACK,&limit,NULL);
-
- com_proc_add.run_path[0] = '\0';
- strncat(com_proc_add.run_path,run_path,sizeof(com_proc_add.run_path));
- com_proc_add.pid = pid;
- com_proc_add.timelimit = timelimit * 1000L;
- com_proc_add.hardtimelimit = hardtimelimit * 1000L;
- com_proc_add.memlimit = memlimit * 1024L + 4096L * 128L;
- if(ioctl(judgk_modfd,IOCTL_PROC_ADD,&com_proc_add)){
- return -1;
- }
- kern_task = com_proc_add.kern_task;
-
- return 0;
- }
-
-public:
- int judgk_modfd;
- char run_path[PATH_MAX + 1];
- char exe_path[PATH_MAX + 1];
- char exe_name[NAME_MAX + 1];
- unsigned long timelimit;
- unsigned long hardtimelimit;
- unsigned long memlimit;
- judgm_proc_check_fn check_fn;
-
- pid_t pid;
- unsigned long kern_task;
- int status;
- unsigned long runtime;
- unsigned long memory;
-
- judgm_proc(int judgk_modfd,char *runpath,char *exe_path,unsigned long timelimit,unsigned long hardtimelimit,unsigned long memlimit,judgm_proc_check_fn check_fn){
- this->judgk_modfd = judgk_modfd;
- this->run_path[0] = '\0';
- strncat(this->run_path,runpath,sizeof(this->run_path));
- this->exe_path[0] = '\0';
- strncat(this->exe_path,exe_path,sizeof(this->exe_path));
-
- this->timelimit = timelimit;
- this->hardtimelimit = hardtimelimit;
- this->memlimit = memlimit;
- this->check_fn = check_fn;
- }
-
- int proc_run(){
- char abspath[PATH_MAX + 1];
-
- if(init()){
- return -1;
- }
-
- realpath(exe_path,abspath);
- if((pid = fork()) == 0){
- char *argv[] = {NULL,NULL};
- char *envp[] = {NULL};
-
- chdir(run_path);
- check_fn();
-
- setgid(99);
- setuid(99);
- kill(getpid(),SIGSTOP);
-
- argv[0] = exe_name;
- execve(abspath,argv,envp);
- exit(0);
- }
-
- if(pid == -1){
- return -1;
- }
- waitpid(pid,NULL,WUNTRACED);
-
- if(protect()){
- kill(pid,SIGKILL);
- return -1;
- }
- status = JUDGE_RUN;
- kill(pid,SIGCONT);
-
- return 0;
- }
- int proc_wait(bool blockflag){
- int wstatus;
- struct judgk_com_proc_get com_proc_get;
-
- if(blockflag == true){
- if(waitpid(pid,&wstatus,WUNTRACED) == -1){
- return -1;
- }
- }else{
- if(waitpid(pid,&wstatus,WUNTRACED | WNOHANG) <= 0){
- return -1;
- }
- }
-
- com_proc_get.kern_task = kern_task;
- if(ioctl(judgk_modfd,IOCTL_PROC_GET,&com_proc_get)){
- return -1;
- }
-
- runtime = com_proc_get.runtime / 1000L;
- memory = com_proc_get.memory;
-
- printf("runtime:%lu memory:%lu\n",runtime,memory);
-
- if(com_proc_get.status != JUDGE_AC){
- status = com_proc_get.status;
- }else if(memory > (memlimit * 1024L)){
- status = JUDGE_MLE;
- }else if(runtime > timelimit){
- status = JUDGE_TLE;
- }else if(WIFEXITED(wstatus) || (WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGKILL)){
- status = JUDGE_AC;
- }else{
- status = JUDGE_RE;
- }
-
- return 0;
- }
- int proc_kill(){
- if(kill(pid,SIGKILL)){
- return -1;
- }
- return 0;
- }
-};
-
-class judgm_hyperio{
-private:
- int judgk_modfd;
- char *read_buf;
- off_t read_off;
-
-public:
- int tty_idx;
-
- judgm_hyperio(int judgk_modfd){
- this->judgk_modfd = judgk_modfd;
- this->tty_idx = ioctl(this->judgk_modfd,IOCTL_HYPERIO_ADD,0);
- this->read_buf = (char*)mmap(NULL,JUDGK_COM_HYPERIO_BUFSIZE,PROT_READ,MAP_SHARED,judgk_modfd,0);
- this->read_off = 0;
- }
- ~judgm_hyperio(){
- munmap(read_buf,JUDGK_COM_HYPERIO_BUFSIZE);
- ioctl(judgk_modfd,IOCTL_HYPERIO_DEL,0);
- }
-
- static int get_ttyfd(int idx){
- char tpath[PATH_MAX + 1];
-
- snprintf(tpath,sizeof(tpath),"/dev/jtty%d",idx);
- return open(tpath,O_RDWR);
- }
- size_t wait(){
- return ioctl(judgk_modfd,IOCTL_HYPERIO_READ,0);
- }
- int compare(char *buf,size_t len){
- int flag;
- size_t remain;
- off_t off;
- size_t data_len;
- size_t cmp_len;
-
- flag = 0;
- remain = len;
- off = 0;
- data_len = 0;
- cmp_len = 0;
- while(remain > 0 && flag == 0){
- if(data_len == 0){
- if((data_len = ioctl(judgk_modfd,IOCTL_HYPERIO_READ,cmp_len)) <= 0){
- return -1;
- }
- }
- if(remain < data_len){
- cmp_len = remain;
- }else{
- cmp_len = data_len;
- }
-
- if((cmp_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE){
- flag |= memcmp(read_buf + read_off,buf + off,cmp_len);
- read_off += cmp_len;
- }else{
- flag |= memcmp(read_buf + read_off,buf + off,JUDGK_COM_HYPERIO_BUFSIZE - read_off);
- flag |= memcmp(read_buf,buf + off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),(cmp_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE);
- read_off = (cmp_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE;
- }
- remain -= cmp_len;
- off += cmp_len;
- data_len -= cmp_len;
- }
- if(cmp_len > 0){
- ioctl(judgk_modfd,IOCTL_HYPERIO_READ,-(long)cmp_len);
- }
-
- if(flag == 0){
- return 0;
- }else{
- return -1;
- }
- }
-};
-
-static int judgm_compile(int subid,char *code_path,char *exe_path,int lang,bool force_flag,char *err_msg,size_t err_len){
- int ret;
- int i;
-
- char log_path[PATH_MAX + 1];
- char main_path[PATH_MAX + 1];
- char sem_path[PATH_MAX + 1];
- struct stat st;
- sem_t *wait_sem;
- bool ce_flag;
- char dir_path[PATH_MAX + 1];
- char *out_path;
- int io[2];
- int pid;
- int wstatus;
- char buf[64];
- off_t err_off;
- FILE *f_log;
-
- if(force_flag == true){
- force_flag = true;
- out_path = exe_path;
- }else{
- snprintf(log_path,sizeof(log_path),"tmp/exe/%d/log",subid);
- snprintf(main_path,sizeof(main_path),"tmp/exe/%d/main",subid);
- snprintf(sem_path,sizeof(sem_path),"/judgm_compile_wait_%d",subid);
- if((wait_sem = sem_open(sem_path,0)) == SEM_FAILED){
- if(stat(main_path,&st)){
- if((wait_sem = sem_open(sem_path,O_CREAT | O_EXCL,0644,0)) != SEM_FAILED){
- out_path = main_path;
- goto compile;
- }else if((wait_sem = sem_open(sem_path,0)) != SEM_FAILED){
-
- sem_wait(wait_sem);
-
- sem_close(wait_sem);
- }
- }
- }else{
-
- sem_wait(wait_sem);
-
- sem_close(wait_sem);
- }
-
- if((f_log = fopen(log_path,"r")) != NULL){
- err_off = fread(err_msg,1,err_len - 1,f_log);
- fclose(f_log);
- err_msg[err_off] = '\0';
-
- if(!link(main_path,exe_path)){
- return 0;
- }else{
- return -1;
- }
- }
- }
-
-compile:
-
- if(force_flag == false){
- snprintf(dir_path,sizeof(dir_path),"tmp/exe/%d",subid);
- mkdir(dir_path,0755);
- }
- ce_flag = false;
- err_off = 0;
-
- if(lang == JUDGE_CPP){
- pipe(io);
-
- if((pid = fork()) == 0){
- char arg_compiler[16];
- char arg_static[16];
- char arg_o[16];
- char arg_std[16];
- char arg_output[16];
- char *argv[8];
-
- arg_compiler[0] = '\0';
- strncat(arg_compiler,"g++",sizeof(arg_compiler));
- arg_static[0] = '\0';
- strncat(arg_static,"-static",sizeof(arg_static));
- arg_o[0] = '\0';
- strncat(arg_o,"-O2",sizeof(arg_o));
- arg_std[0] = '\0';
- strncat(arg_std,"-std=c++0x",sizeof(arg_std));
- arg_output[0] = '\0';
- strncat(arg_output,"-o",sizeof(arg_output));
-
- argv[0] = arg_compiler;
- argv[1] = arg_static;
- argv[2] = arg_o;
- argv[3] = code_path;
- argv[4] = arg_std;
- argv[5] = arg_output;
- argv[6] = out_path;
- argv[7] = NULL;
-
- dup2(io[1],1);
- dup2(io[1],2);
- execvp("g++",argv);
- }
-
- close(io[1]);
- while((ret = read(io[0],err_msg + err_off,err_len - err_off - 1)) > 0){
- err_off += ret;
- }
- err_msg[err_off] = '\0';
-
- while(read(io[0],buf,64) > 0);
- close(io[0]);
-
- if(err_off > (err_len - 4)){
- err_msg[err_len - 4] = '\0';
- strncat(err_msg + err_len - 4,"...",4);
- err_off = err_len - 1;
- }
-
- waitpid(pid,&wstatus,0);
- if(wstatus != 0){
- ce_flag = true;
- }
- }
-
- if(force_flag == false){
- f_log = fopen(log_path,"w");
- fwrite(err_msg,err_off,1,f_log);
- fclose(f_log);
-
- for(i = 0;i < JUDGE_THREAD_MAX;i++){
- sem_post(wait_sem);
- }
- sem_close(wait_sem);
- sem_unlink(sem_path);
- }
- if(ce_flag == true){
- return -1;
- }
-
- link(main_path,exe_path);
-
- return 0;
-}
diff --git a/toj/center/src/judgm_line.h b/toj/center/src/judgm_line.h
deleted file mode 100755
index 1b36c74..0000000
--- a/toj/center/src/judgm_line.h
+++ /dev/null
@@ -1,19 +0,0 @@
-struct judgm_line_info{
- int subid;
-
- char *pro_path;
- char *code_path;
- char *run_path;
-
- int judgk_modfd;
- void *line_dll;
- void *check_dll;
-
- int lang;
- FILE *set_file;
- char *set_data;
-
- char res_data[JUDGE_RES_DATAMAX];
- size_t res_len;
-};
-typedef int (*judgm_line_run_fn)(judgm_line_info *info);
diff --git a/toj/center/src/judgm_manage.h b/toj/center/src/judgm_manage.h
deleted file mode 100755
index 2795ec7..0000000
--- a/toj/center/src/judgm_manage.h
+++ /dev/null
@@ -1,29 +0,0 @@
-typedef int (*judgm_manage_queuesubmit_fn)(int subid,int proid,int lang,char *set_data,size_t set_len);
-
-class judgm_manage_info{
-public:
- int subid;
- int uid;
- int proid;
- int lang;
- char *param;
- char pro_path[PATH_MAX + 1];
- char res_path[PATH_MAX + 1];
-
- int result;
- double score;
- unsigned long runtime;
- unsigned long memory;
-
- void *private_data;
-
- judgm_manage_info(int subid,int uid,int proid,int lang,char *param){
- this->subid = subid;
- this->uid = uid;
- this->proid = proid;
- this->lang = lang;
- this->param = param;
- }
-};
-typedef int (*judgm_manage_submit_fn)(judgm_manage_info *info,FILE *set_file);
-typedef int (*judgm_manage_result_fn)(judgm_manage_info *info,char *res_data);
diff --git a/toj/center/src/netio.h b/toj/center/src/netio.h
deleted file mode 100755
index db54b23..0000000
--- a/toj/center/src/netio.h
+++ /dev/null
@@ -1,192 +0,0 @@
-class netio_protoiofn{
-public:
- virtual void operator()(void *buf,size_t len,void *data) = 0;
-};
-
-template<typename C>
-class netio_iofn : public netio_protoiofn{
-private:
- typedef void (C::*netio_iofn_type)(void *buf,size_t len,void *data);
- C *obj;
- netio_iofn_type fn;
-
-public:
- netio_iofn(C *obj,netio_iofn_type fn){
- this->obj = obj;
- this->fn = fn;
- }
- void operator()(void *buf,size_t len,void *data){
- (obj->*fn)(buf,len,data);
- }
-};
-
-#define NETIO_IOTYPE_PLAIN 0
-#define NETIO_IOTYPE_FILE 1
-class netio_iocb{
-public:
- int type;
-
- void *buf;
- int fd;
- off_t off;
- size_t len;
- netio_protoiofn *cb_fn;
- void *cb_data;
-
- netio_iocb(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){
- this->type = NETIO_IOTYPE_PLAIN;
- this->buf = buf;
- this->off = 0;
- this->len = len;
- this->cb_fn = cb_fn;
- this->cb_data = cb_data;
- }
- netio_iocb(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){
- this->type = NETIO_IOTYPE_FILE;
- this->buf = &this->fd;
- this->fd = fd;
- this->off = 0;
- this->len = len;
- this->cb_fn = cb_fn;
- this->cb_data = cb_data;
- }
-};
-
-#define NETIO_IOSIZE 65536
-class netio{
-private:
- netio_iocb *read_iocb;
- std::queue<netio_iocb*> write_queue;
- bool readio_reen;
- char readio_buf[NETIO_IOSIZE];
-
-public:
- int fd;
- virtual int readidle() = 0;
-
- netio(int fd){
- this->fd = fd;
- this->read_iocb = NULL;
- this->readio_reen = false;
- }
- ~netio(){
- close(this->fd);
- }
- int readio(){
- int ret;
- size_t len;
- netio_iocb *iocb;
-
- if(readio_reen == true){
- return -1;
- }
- readio_reen = true;
-
- while(true){
- if(read_iocb == NULL){
- readidle();
- }
-
- iocb = read_iocb;
- if(iocb->type == NETIO_IOTYPE_PLAIN){
- while((ret = read(fd,(char*)iocb->buf + iocb->off,iocb->len - iocb->off)) > 0){
- iocb->off += ret;
- }
- }else if(iocb->type == NETIO_IOTYPE_FILE){
- while(true){
- len = iocb->len - iocb->off;
- if(len >= NETIO_IOSIZE){
- len = NETIO_IOSIZE;
- }
- if((ret = read(fd,readio_buf,len)) <= 0){
- break;
- }
-
- write(iocb->fd,readio_buf,ret);
- iocb->off += ret;
- }
- }
- if(iocb->off == iocb->len){
- read_iocb = NULL;
-
- if(iocb->cb_fn != NULL){
- (*iocb->cb_fn)(iocb->buf,iocb->len,iocb->cb_data);
- }else{
- if(iocb->type == NETIO_IOTYPE_PLAIN){
- delete (char*)iocb->buf;
- }else if(iocb->type == NETIO_IOTYPE_FILE){
- close(iocb->fd);
- }
- }
-
- delete iocb;
- }else{
- break;
- }
- }
-
- readio_reen = false;
- return 0;
- }
- int readbytes(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){
- read_iocb = new netio_iocb(buf,len,cb_fn,cb_data);
- readio();
- return 0;
- }
- int readfile(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){
- read_iocb = new netio_iocb(fd,len,cb_fn,cb_data);
- readio();
- return 0;
- }
- int writeio(){
- int ret;
- size_t len;
- netio_iocb *iocb;
-
- while(!write_queue.empty()){
- iocb = write_queue.front();
- if(iocb->type == NETIO_IOTYPE_PLAIN){
- while((ret = write(fd,(char*)iocb->buf + iocb->off,iocb->len - iocb->off)) > 0){
- iocb->off += ret;
- }
- }else if(iocb->type == NETIO_IOTYPE_FILE){
- len = iocb->len - iocb->off;
- if(len >= NETIO_IOSIZE){
- len = NETIO_IOSIZE;
- }
- while((ret = sendfile(fd,iocb->fd,NULL,len)) > 0){
- iocb->off += ret;
- }
- }
- if(iocb->off == iocb->len){
- write_queue.pop();
-
- if(iocb->cb_fn != NULL){
- (*iocb->cb_fn)(iocb->buf,iocb->len,iocb->cb_data);
- }else{
- if(iocb->type == NETIO_IOTYPE_PLAIN){
- delete (char*)iocb->buf;
- }else if(iocb->type == NETIO_IOTYPE_FILE){
- close(iocb->fd);
- }
- }
-
- delete iocb;
- }else{
- break;
- }
- }
-
- return 0;
- }
- int writebytes(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){
- write_queue.push(new netio_iocb(buf,len,cb_fn,cb_data));
- writeio();
- return 0;
- }
- int writefile(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){
- write_queue.push(new netio_iocb(fd,len,cb_fn,cb_data));
- writeio();
- return 0;
- }
-};
diff --git a/toj/center/src/tool.cpp b/toj/center/src/tool.cpp
deleted file mode 100644
index 1502007..0000000
--- a/toj/center/src/tool.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-#include<string.h>
-#include<dirent.h>
-#include<unistd.h>
-#include<fcntl.h>
-#include<limits.h>
-#include<ftw.h>
-#include<libtar.h>
-#include<bzlib.h>
-#include<sys/stat.h>
-#include<sys/sendfile.h>
-#include<map>
-#include<vector>
-#include<string>
-
-#include"tool.h"
-
-static int pack_copenfn(const char *pathname,int flags,...){
- int fd;
- pack_bzinfo *bzinfo;
-
- if((fd = open(pathname,flags,0644)) == -1){
- return -1;
- }
-
- bzinfo = new pack_bzinfo;
- bzinfo->len = 0;
- bzinfo->off = 0;
- bzinfo->endflag = false;
- bzinfo->bzs.bzalloc = NULL;
- bzinfo->bzs.bzfree = NULL;
- bzinfo->bzs.opaque = NULL;
- BZ2_bzCompressInit(&bzinfo->bzs,9,0,0);
-
- pack_fdmap.insert(std::pair<int,pack_bzinfo*>(fd,bzinfo));
-
- return fd;
-}
-static int pack_cclosefn(long fd){
- int ret;
- pack_bzinfo *bzinfo;
-
- bzinfo = pack_fdmap.find(fd)->second;
- pack_fdmap.erase(fd);
-
- bzinfo->bzs.next_in = NULL;
- bzinfo->bzs.avail_in = 0;
- while(true){
- bzinfo->bzs.next_out = bzinfo->buf;
- bzinfo->bzs.avail_out = PACK_BUFSIZE;
- ret = BZ2_bzCompress(&bzinfo->bzs,BZ_FINISH);
-
- if(bzinfo->bzs.avail_out != PACK_BUFSIZE){
- write(fd,bzinfo->buf,PACK_BUFSIZE - bzinfo->bzs.avail_out);
- }
- if(ret == BZ_STREAM_END){
- break;
- }
- }
-
- BZ2_bzCompressEnd(&bzinfo->bzs);
- delete bzinfo;
- return close(fd);
-}
-static ssize_t pack_cwritefn(long fd,const void *buf,size_t count){
- pack_bzinfo *bzinfo;
-
- bzinfo = pack_fdmap.find(fd)->second;
-
- bzinfo->bzs.next_in = (char*)buf;
- bzinfo->bzs.avail_in = count;
- while(bzinfo->bzs.avail_in > 0){
- bzinfo->bzs.next_out = bzinfo->buf;
- bzinfo->bzs.avail_out = PACK_BUFSIZE;
- BZ2_bzCompress(&bzinfo->bzs,BZ_RUN);
- if(bzinfo->bzs.avail_out != PACK_BUFSIZE){
- write(fd,bzinfo->buf,PACK_BUFSIZE - bzinfo->bzs.avail_out);
- }
- }
-
- return count;
-}
-static int pack_xopenfn(const char *pathname,int flags,...){
- int fd;
- pack_bzinfo *bzinfo;
-
- if((fd = open(pathname,flags)) == -1){
- return -1;
- }
-
- bzinfo = new pack_bzinfo;
- bzinfo->len = 0;
- bzinfo->off = 0;
- bzinfo->endflag = false;
- bzinfo->bzs.bzalloc = NULL;
- bzinfo->bzs.bzfree = NULL;
- bzinfo->bzs.opaque = NULL;
- BZ2_bzDecompressInit(&bzinfo->bzs,0,0);
-
- printf(" %d\n",fd);
- pack_fdmap.insert(std::pair<int,pack_bzinfo*>(fd,bzinfo));
-
- return fd;
-}
-static int pack_xclosefn(long fd){
- int ret;
- pack_bzinfo *bzinfo;
-
- bzinfo = pack_fdmap.find(fd)->second;
- pack_fdmap.erase(fd);
- BZ2_bzDecompressEnd(&bzinfo->bzs);
- delete bzinfo;
-
- return close(fd);
-}
-static ssize_t pack_xreadfn(long fd,void *buf,size_t count){
- int ret;
- pack_bzinfo *bzinfo;
-
- printf(" %d\n",fd);
- bzinfo = pack_fdmap.find(fd)->second;
-
- bzinfo->bzs.next_out = (char*)buf;
- bzinfo->bzs.avail_out = count;
- while(bzinfo->endflag == false){
- if(bzinfo->len == 0){
- ret = read(fd,bzinfo->buf,PACK_BUFSIZE);
- bzinfo->len = ret;
- bzinfo->off = 0;
- }
- if(bzinfo->len == 0){
- break;
- }
-
- bzinfo->bzs.next_in = bzinfo->buf + bzinfo->off;
- bzinfo->bzs.avail_in = bzinfo->len;
- while(bzinfo->bzs.avail_in > 0 && bzinfo->bzs.avail_out > 0){
- if(BZ2_bzDecompress(&bzinfo->bzs) != BZ_OK){
- bzinfo->endflag = true;
- break;
- }
- }
- bzinfo->off += bzinfo->len - bzinfo->bzs.avail_in;
- bzinfo->len = bzinfo->bzs.avail_in;
-
- if(bzinfo->bzs.avail_out == 0){
- break;
- }
- }
-
- return count - bzinfo->bzs.avail_out;
-}
-
-int tool_pack(char *pack_path,char *dir_path){
- tartype_t tar_type;
- TAR *tarp;
- char tpath[2] = {'.','\0'};
-
- tar_type.openfunc = pack_copenfn;
- tar_type.closefunc = pack_cclosefn;
- tar_type.readfunc = (readfunc_t)read;
- tar_type.writefunc = pack_cwritefn;
- tar_open(&tarp,pack_path,&tar_type,O_WRONLY | O_CREAT,0644,TAR_GNU);
-
- tar_append_tree(tarp,dir_path,tpath);
- tar_close(tarp);
-
- return 0;
-}
-int tool_unpack(char *pack_path,char *dir_path){
- tartype_t tar_type;
- TAR *tarp;
-
- tool_cleardir(dir_path);
- mkdir(dir_path,0775);
-
- tar_type.openfunc = pack_xopenfn;
- tar_type.closefunc = pack_xclosefn;
- tar_type.readfunc = pack_xreadfn;
- tar_type.writefunc = (writefunc_t)write;
- tar_open(&tarp,pack_path,&tar_type,O_RDONLY,0644,TAR_GNU);
-
- tar_extract_all(tarp,dir_path);
- tar_close(tarp);
-
- return 0;
-}
-
-static int cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftw_buf){
- if(ftw_buf->level == 0){
- return 0;
- }
-
- if(S_ISDIR(st->st_mode)){
- rmdir(path);
- }else{
- unlink(path);
- }
- return 0;
-}
-int tool_cleardir(char *path){
- nftw(path,cleardir_callback,64,FTW_DEPTH | FTW_PHYS);
- return 0;
-}
-static int copydir_travel(char *old_path,int old_len,char *new_path,int new_len){
- int i;
- int j;
- int len;
-
- DIR *dirp;
- char *buf;
- dirent *entry;
- std::vector<std::string> wait_list;
- const char *tname;
-
- int infd;
- int outfd;
- struct stat st;
-
- if((dirp = opendir(old_path)) == NULL){
- return -1;
- }
- buf = new char[sizeof(dirent) + NAME_MAX + 1];
-
- while(true){
- readdir_r(dirp,(dirent*)buf,&entry);
- if(entry == NULL){
- break;
- }
- if(strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0){
- continue;
- }
-
- if(entry->d_type == DT_DIR){
- wait_list.push_back(entry->d_name);
- }else{
- old_path[old_len] = '/';
- new_path[new_len] = '/';
- len = strlen(entry->d_name);
- for(i = 0;i <= len;i++){
- old_path[old_len + i + 1] = entry->d_name[i];
- new_path[new_len + i + 1] = entry->d_name[i];
- }
-
- infd = open(old_path,O_RDONLY);
- outfd = open(new_path,O_WRONLY | O_CREAT,0644);
- fstat(infd,&st);
- sendfile(outfd,infd,NULL,st.st_size);
- close(infd);
- close(outfd);
-
- old_path[old_len] = '\0';
- new_path[new_len] = '\0';
- }
- }
-
- delete buf;
- closedir(dirp);
-
- while(!wait_list.empty()){
- tname = wait_list.back().c_str();
- wait_list.pop_back();
-
- old_path[old_len] = '/';
- new_path[new_len] = '/';
- len = strlen(tname);
- for(i = 0;i <= len;i++){
- old_path[old_len + i + 1] = tname[i];
- new_path[new_len + i + 1] = tname[i];
- }
-
- mkdir(new_path,0775);
-
- copydir_travel(old_path,old_len + len + 1,new_path,new_len + len + 1);
-
- old_path[old_len] = '\0';
- new_path[new_len] = '\0';
- }
-
- return 0;
-}
-int tool_copydir(char *old_path,char *new_path){
- char old_buf[PATH_MAX + 1];
- char new_buf[PATH_MAX + 1];
-
- tool_cleardir(new_path);
- mkdir(new_path,0775);
-
- old_buf[0] = '\0';
- strncat(old_buf,old_path,sizeof(old_buf));
- new_buf[0] = '\0';
- strncat(new_buf,new_path,sizeof(new_buf));
-
- copydir_travel(old_buf,strlen(old_buf),new_buf,strlen(new_buf));
-
- return 0;
-}
diff --git a/toj/center/src/tool.h b/toj/center/src/tool.h
deleted file mode 100644
index f876c29..0000000
--- a/toj/center/src/tool.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#define PACK_BUFSIZE 65536
-struct pack_bzinfo{
- bz_stream bzs;
- char buf[PACK_BUFSIZE];
- int len;
- int off;
- bool endflag;
-};
-
-static int pack_copenfn(const char *pathname,int flags,...);
-static int pack_cclosefn(long fd);
-static ssize_t cpack_writefn(long fd,const void *buf,size_t count);
-static int pack_xopenfn(const char *pathname,int flags,...);
-static int pack_xclosefn(long fd);
-static ssize_t pack_xreadfn(long fd,void *buf,size_t count);
-
-static std::map<int,pack_bzinfo*> pack_fdmap;
-
-int tool_pack(char *pack_path,char *dir_path);
-int tool_unpack(char *pack_path,char *dir_path);
-
-static int cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftw_buf);
-static int copydir_travel(char *old_path,int old_len,char *new_path,int new_len);
-
-int tool_cleardir(char *path);
-int tool_copydir(char *old_path,char *new_path);
diff --git a/toj/center/src/tpool.h b/toj/center/src/tpool.h
deleted file mode 100755
index c06efc1..0000000
--- a/toj/center/src/tpool.h
+++ /dev/null
@@ -1,175 +0,0 @@
-#include<pthread.h>
-#include<semaphore.h>
-#include<sys/eventfd.h>
-#include<queue>
-#include<vector>
-
-class tpool_protofn{
-public:
- virtual void operator()(void *data) = 0;
-};
-
-template<typename C>
-class tpool_fn : public tpool_protofn{
-private:
- typedef void (C::*tpool_fn_type)(void *data);
- C *obj;
- tpool_fn_type fn;
-
-public:
- tpool_fn(C *obj,tpool_fn_type fn){
- this->obj = obj;
- this->fn = fn;
- }
- void operator()(void *data){
- (obj->*fn)(data);
- }
-};
-class tpool_static_fn : public tpool_protofn{
-private:
- typedef void (*tpool_static_fn_type)(void *data);
- tpool_static_fn_type fn;
-
-public:
- tpool_static_fn(tpool_static_fn_type fn){
- this->fn = fn;
- }
- void operator()(void *data){
- fn(data);
- }
-};
-
-class tpool_thcb{
-public:
- tpool_protofn *th_fn;
- void *th_data;
- tpool_protofn *cb_fn;
- void *cb_data;
-
- tpool_thcb(tpool_protofn *th_fn,void *th_data,tpool_protofn *cb_fn,void *cb_data){
- this->th_fn = th_fn;
- this->th_data = th_data;
- this->cb_fn = cb_fn;
- this->cb_data = cb_data;
- }
- int run(){
- (*th_fn)(th_data);
- return 0;
- }
- int done(){
- if(cb_fn != NULL){
- (*cb_fn)(cb_data);
- }
- return 0;
- }
-};
-
-#define TPOOL_THREAD_MAXNUM 64
-class tpool{
-private:
- std::queue<tpool_thcb*> wait_queue;
- std::vector<tpool_thcb*> done_list;
- pthread_t pt[TPOOL_THREAD_MAXNUM];
- int pt_num;
- sem_t pt_sem;
- pthread_mutex_t pt_mutex;
-
- static void* pt_runfn(void *arg){
- tpool *that;
- tpool_thcb *thcb;
- long long int sig;
-
- that = (tpool*)arg;
-
- while(true){
-
- sem_wait(&that->pt_sem);
-
- pthread_mutex_lock(&that->pt_mutex);
-
- if(!that->wait_queue.empty()){
- thcb = that->wait_queue.front();
- that->wait_queue.pop();
- }else{
- thcb = NULL;
- }
-
- pthread_mutex_unlock(&that->pt_mutex);
-
- if(thcb == NULL){
- continue;
- }
-
- thcb->run();
-
- pthread_mutex_lock(&that->pt_mutex);
-
- that->done_list.push_back(thcb);
-
- pthread_mutex_unlock(&that->pt_mutex);
-
- sig = 1;
- write(that->fd,&sig,sizeof(sig)),that->done_list.size();
- }
- return NULL;
- }
-
-public:
- int fd;
-
- tpool(int pt_num){
- if((this->pt_num = pt_num) > TPOOL_THREAD_MAXNUM){
- this->pt_num = TPOOL_THREAD_MAXNUM;
- }
- fd = eventfd(0,EFD_NONBLOCK);
- sem_init(&pt_sem,0,0);
- pthread_mutex_init(&pt_mutex,NULL);
- }
- ~tpool(){
- close(fd);
- sem_destroy(&pt_sem);
- pthread_mutex_destroy(&pt_mutex);
- }
- int start(){
- int i;
-
- for(i = 0;i < pt_num;i++){
- pthread_create(&pt[pt_num],NULL,pt_runfn,this);
- }
-
- return 0;
- }
- int done(){
- int i;
- std::vector<tpool_thcb*> l;
- long long int sig;
-
- pthread_mutex_lock(&pt_mutex);
-
- l.swap(done_list);
-
- pthread_mutex_unlock(&pt_mutex);
-
- for(i = l.size() - 1;i >= 0;i--){
- l[i]->done();
- delete l[i];
- }
-
- read(fd,&sig,sizeof(sig));
- }
- int add(tpool_protofn *th_fn,void *th_data,tpool_protofn *cb_fn,void *cb_data){
- tpool_thcb *thcb;
-
- thcb = new tpool_thcb(th_fn,th_data,cb_fn,cb_data);
-
- pthread_mutex_lock(&pt_mutex);
-
- wait_queue.push(thcb);
-
- pthread_mutex_unlock(&pt_mutex);
-
- sem_post(&pt_sem);
-
- return 0;
- }
-};