aboutsummaryrefslogtreecommitdiffstats
path: root/toj
diff options
context:
space:
mode:
authorpzread <netfirewal@gmail.com>2013-03-10 15:46:38 +0800
committerpzread <netfirewal@gmail.com>2013-03-10 15:46:38 +0800
commit5ecfc12aad9e7b6d43273de7aefd514e430fec49 (patch)
tree08f1647b9970ea0eb93068e0fdc309e219589876 /toj
parent3fe2b6cd06b6aaebd4597c2ea55a1a8b1a924f5d (diff)
downloadtaiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.tar
taiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.tar.gz
taiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.tar.bz2
taiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.tar.lz
taiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.tar.xz
taiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.tar.zst
taiwan-online-judge-5ecfc12aad9e7b6d43273de7aefd514e430fec49.zip
jmod_test add return special judge message
Diffstat (limited to 'toj')
-rw-r--r--toj/center/src/center_manage.cpp30
-rw-r--r--toj/center/src/center_manage.h2
-rw-r--r--toj/center/src/center_server.cpp2
-rw-r--r--toj/center/src/jmod_test.h8
-rw-r--r--toj/center/src/jmod_test_check.cpp11
-rw-r--r--toj/center/src/jmod_test_check.h2
-rw-r--r--toj/center/src/jmod_test_line.cpp5
-rw-r--r--toj/center/src/jmod_test_manage.cpp4
-rw-r--r--toj/center/src/judge_server.cpp8
-rw-r--r--toj/center/src/judgm_lib.h6
10 files changed, 54 insertions, 24 deletions
diff --git a/toj/center/src/center_manage.cpp b/toj/center/src/center_manage.cpp
index 887bdff..1155ab0 100644
--- a/toj/center/src/center_manage.cpp
+++ b/toj/center/src/center_manage.cpp
@@ -99,6 +99,8 @@ int center_manage_submit(int subid,char *param){
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;
@@ -111,7 +113,7 @@ int center_manage_submit(int subid,char *param){
snprintf(db_subid,sizeof(db_subid),"%d",subid);
db_param[0] = db_subid;
db_res = PQexecParams(db_conn,
- "SELECT \"uid\",\"proid\",\"lang\" FROM \"submit\" WHERE \"subid\"=$1;",
+ "SELECT \"uid\",\"proid\",\"lang\",\"result\" FROM \"submit\" WHERE \"subid\"=$1;",
1,
NULL,
db_param,
@@ -126,6 +128,7 @@ int center_manage_submit(int subid,char *param){
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);
@@ -139,7 +142,13 @@ int center_manage_submit(int subid,char *param){
}
jmod_info = pro_info->jmod_info;
- sub_info = new center_submit_info(subid,uid,jmod_info,pro_info,lang,param);
+ if(result == JUDGE_WAIT){
+ rejudge_flag = false;
+ }else{
+ rejudge_flag = true;
+ }
+
+ sub_info = new center_submit_info(subid,uid,jmod_info,pro_info,lang,rejudge_flag,param);
center_manage_submap.insert(std::pair<int,center_submit_info*>(sub_info->subid,sub_info));
manage_packtp->add(manage_packcode_thfn,sub_info,manage_packcode_cbfn,sub_info);
@@ -208,7 +217,7 @@ static void manage_packcode_cb(void *data){
fclose(set_file);
}
-static int manage_notice(int subid,int uid,int proid,int result,int runtime,int memory){
+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;
@@ -218,14 +227,16 @@ static int manage_notice(int subid,int uid,int proid,int result,int runtime,int
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);
- printf("%d %d %d\n",uid,proid,event_exec("pzreadtest.php","center_result_event",json_object_get_string(jso_arg)));
+ event_exec("pzreadtest.php","center_result_event",json_object_get_string(jso_arg));
json_object_put(jso_arg);
return 0;
@@ -273,7 +284,7 @@ int center_manage_result(int subid,char *res_data){
}
snprintf(db_result,sizeof(db_result),"%d",res_info.result);
- snprintf(db_score,sizeof(db_score),"%d",(int)res_info.score);
+ snprintf(db_score,sizeof(db_score),"%lld",(int)res_info.score);
snprintf(db_runtime,sizeof(db_runtime),"%lu",res_info.runtime);
snprintf(db_memory,sizeof(db_memory),"%lu",res_info.memory / 1024UL);
snprintf(db_subid,sizeof(db_subid),"%d",subid);
@@ -293,7 +304,14 @@ int center_manage_result(int subid,char *res_data){
PQclear(db_res);
center_manage_closedb(db_conn);
- manage_notice(subid,sub_info->uid,sub_info->pro_info->proid,res_info.result,res_info.runtime,res_info.memory);
+ manage_notice(subid,
+ sub_info->uid,
+ sub_info->pro_info->proid,
+ res_info.result,
+ res_info.score,
+ res_info.runtime,
+ res_info.memory,
+ sub_info->rejudge_flag);
delete sub_info;
}else{
diff --git a/toj/center/src/center_manage.h b/toj/center/src/center_manage.h
index 27e1bc9..887ef77 100644
--- a/toj/center/src/center_manage.h
+++ b/toj/center/src/center_manage.h
@@ -1,6 +1,6 @@
static void manage_packcode_th(void *data);
static void manage_packcode_cb(void *data);
-static int manage_notice(int subid,int uid,int proid,int result,int runtime,int memory);
+static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag);
static tpool *manage_packtp;
static tpool_static_fn *manage_packcode_thfn;
diff --git a/toj/center/src/center_server.cpp b/toj/center/src/center_server.cpp
index 406e0fc..a931822 100644
--- a/toj/center/src/center_server.cpp
+++ b/toj/center/src/center_server.cpp
@@ -118,7 +118,7 @@ int main(){
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");
+ saddr.sin_addr.s_addr = inet_addr("10.8.0.1");
setsockopt(judge_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr));
bind(judge_sfd,(sockaddr*)&saddr,sizeof(saddr));
diff --git a/toj/center/src/jmod_test.h b/toj/center/src/jmod_test.h
index 49381fc..94cc23d 100644
--- a/toj/center/src/jmod_test.h
+++ b/toj/center/src/jmod_test.h
@@ -1,5 +1,7 @@
-typedef int (*check_init_fn)(int judgk_modfd,char *datapath,char *runpath);
-typedef int (*check_run_fn)(int &status);
+#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{
@@ -11,5 +13,5 @@ struct line_result_data{
double score;
unsigned long runtime;
unsigned long memory;
- char errmsg[4096];
+ char err_msg[LINE_ERRMSG_MAXSIZE];
};
diff --git a/toj/center/src/jmod_test_check.cpp b/toj/center/src/jmod_test_check.cpp
index df7368f..ae4d060 100644
--- a/toj/center/src/jmod_test_check.cpp
+++ b/toj/center/src/jmod_test_check.cpp
@@ -38,7 +38,7 @@ DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath){
return 0;
}
-DLL_PUBLIC int run(int &status){
+DLL_PUBLIC int run(int &status,char *err_msg){
int ret;
char *inbuf;
@@ -64,8 +64,9 @@ DLL_PUBLIC int run(int &status){
delete hyperio;*/
close(p[1]);
+ int c_read=-1,pre_status=status;
while((ret = read(p[0],inbuf,65536)) > 0){
- if(read(ansfd,ansbuf,ret) != ret){
+ if((c_read=read(ansfd,ansbuf,ret)) != ret){
status = JUDGE_WA;
break;
}
@@ -74,7 +75,11 @@ DLL_PUBLIC int run(int &status){
break;
}
}
- if(status == JUDGE_AC && read(ansfd,ansbuf,1) > 0){
+// 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;
}
diff --git a/toj/center/src/jmod_test_check.h b/toj/center/src/jmod_test_check.h
index 57bc2c6..20a6286 100644
--- a/toj/center/src/jmod_test_check.h
+++ b/toj/center/src/jmod_test_check.h
@@ -1,4 +1,4 @@
DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath);
-DLL_PUBLIC int run(int &status);
+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
index 85340ad..bd855c8 100644
--- a/toj/center/src/jmod_test_line.cpp
+++ b/toj/center/src/jmod_test_line.cpp
@@ -123,6 +123,7 @@ DLL_PUBLIC int run(judgm_line_info *info){
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->test_id,set_timelimit,set_memlimit,set_score)){
return -1;
@@ -130,7 +131,7 @@ DLL_PUBLIC int run(judgm_line_info *info){
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->errmsg,sizeof(res_data->errmsg))){
+ 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;
}
@@ -155,7 +156,7 @@ DLL_PUBLIC int run(judgm_line_info *info){
delete line_proc;
return -1;
}
- chk_run_fn(chk_status);
+ chk_run_fn(chk_status,res_data->err_msg);
line_sig_block();
if(line_proc->status == JUDGE_RUN){
diff --git a/toj/center/src/jmod_test_manage.cpp b/toj/center/src/jmod_test_manage.cpp
index e4738df..a1e0a33 100644
--- a/toj/center/src/jmod_test_manage.cpp
+++ b/toj/center/src/jmod_test_manage.cpp
@@ -72,8 +72,8 @@ DLL_PUBLIC int result(judgm_manage_resultinfo *info,void *manage_data){
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(res_data->status == JUDGE_CE){
- json_object_object_add(jso_item,"errmsg",json_object_new_string(res_data->errmsg));
+ if(strlen(res_data->err_msg) > 0){
+ 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->test_id - 1,jso_item);
diff --git a/toj/center/src/judge_server.cpp b/toj/center/src/judge_server.cpp
index 2741459..f5e6d6d 100644
--- a/toj/center/src/judge_server.cpp
+++ b/toj/center/src/judge_server.cpp
@@ -536,7 +536,11 @@ static int server_judge(int subid,char *pro_path,char *code_path,char *run_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);
- snprintf(check_path,sizeof(check_path),"%s/tmp/jmod/%s/%s.so",cwd_path,jmod_name,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){
@@ -626,7 +630,7 @@ static server_conn* server_connect(){
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");
+ caddr.sin_addr.s_addr = inet_addr("10.8.0.1");
cinfo = new server_conn(cfd);
server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,cinfo);
diff --git a/toj/center/src/judgm_lib.h b/toj/center/src/judgm_lib.h
index 324147e..4aa02fa 100644
--- a/toj/center/src/judgm_lib.h
+++ b/toj/center/src/judgm_lib.h
@@ -269,7 +269,7 @@ public:
}
};
-static int judgm_compile(int subid,char *code_path,char *exe_path,int lang,bool force_flag,char *errmsg,size_t errsize){
+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;
@@ -336,10 +336,10 @@ compile:
close(io[1]);
off = 0;
- while((ret = read(io[0],errmsg + off,errsize - off - 1)) > 0){
+ while((ret = read(io[0],err_msg + off,err_len - off - 1)) > 0){
off += ret;
}
- errmsg[off] = '\0';
+ err_msg[off] = '\0';
close(io[0]);
waitpid(pid,&wstatus,0);