📄 sys_check.h
字号:
void sys_check(){ /* attach parent's shared memory */ ap=(struct area *)shmat(shmid, 0, 0); /* note: shmid is still set correctly */ time_t timebuf; int len=strlen(ctime(&timebuf)); char state[LEN]={}; char *buf=malloc(sizeof(char)*(len+1)); time(&timebuf); strncpy(buf,ctime(&timebuf),len+1);//save the current time in the buf/*while(1){ if(ap->flag_Sys_check==-1) {break;}else{*/ /* set semaphore */ buf_sem.sem_op=-1; semop(semid, (struct sembuf *) &buf_sem, 1); char info[500]={}; char A_main_server[10]={}; char B_main_server[10]={}; char A_main_port[10]={}; char B_main_port[10]={}; char Asocket_info[800]={}; char Bsocket_info[800]={};//M machine check if(Mstate_check()==0) { ap->Mstate_gl=0; ap->Mhost_name_gl="127.0.0.1"; strcpy(info,"\nMstate=0,Mhost_name=127.0.0.1,Reboot the programme or machine\n"); //change the lpudated_log reboot M //update state_file exit(EXIT_FAILURE); } else { ap->Mstate_gl=1; ap->Mhost_name_gl="192.168.1.1"; strcpy(info,"\n\nInformation explain:\nMhost_name=192.168.1.1,Mstate=1"); }//check A machine //get_state(STATE_FILE); Astate_check(); strcpy(Asocket_info,check_error); strcat(info,"\nAhost_name="); strcat(info,ap->Ahost_name_gl); strcat(info,",Amain_server="); sprintf(A_main_server,"%d",ap->Amain_server_gl); strcat(info,A_main_server); strcat(info,",Amain_port="); sprintf(A_main_port,"%d",ap->Amain_port_gl); strcat(info,A_main_port); //check B machine Bstate_check(); strcpy(Bsocket_info,check_error); strcat(info,"\nBhost_name="); strcat(info,ap->Bhost_name_gl); strcat(info,",Bmain_server="); sprintf(B_main_server,"%d",ap->Bmain_server_gl); strcat(info,B_main_server); strcat(info,",Bmain_port="); sprintf(B_main_port,"%d",ap->Bmain_port_gl); strcat(info,B_main_port);//further check for Main_cpu Main_hub if((ap->Astate_gl==1)&&(ap->Bstate_gl==1)) { ap->Sys_main_cpu_gl=1; ap->Sys_main_hub_gl=1; strcat(info,"\nAstate=1,Bstate=1,Sys_main_cpu=1,Sys_main_hub=1\n"); } else if((ap->Astate_gl==1)&&(ap->Bstate_gl==0)) { ap->Sys_main_cpu_gl=1; ap->Sys_main_hub_gl=1; strcat(info,"\nAstate=1,Bstate=0,Sys_main_cpu=1,Sys_main_hub=1\n"); } else if((ap->Astate_gl==0)&&(ap->Bstate_gl==1)) { ap->Sys_main_cpu_gl=2; ap->Sys_main_hub_gl=1; strcat(info,"\nAstate=0,Bstate=1,Sys_main_cpu=2,Sys_main_hub=1\n"); } else { strcat(info,"\nAstate=0,Bstate=0,Sys_main_cpu=0,Sys_main_hub=2\n"); //Sys_main_hub_gl=2; }/*//further check for host_name if(Sys_main_hub_gl==2) { Ahost_name_gl="192.168.1.4"; Bhost_name_gl="192.168.1.6"; }*///get the check detail infomation strcat(info,"\nThe detail info:\n"); strcat(info,Asocket_info); strcat(info,A_info); strcat(info,Bsocket_info); strcat(info,B_info);//update the state file/* FILE *fp; fp=fopen("/zlm/state.log","w+"); if(fp==NULL) { printf("Error openning! for write_log()\n"); } else fputs(info,fp); fclose(fp);*/ /* clear semaphore */ buf_sem.sem_op=1; semop(semid, (struct sembuf *) &buf_sem, 1); // sleep(1);// }//else//}while(1)//exit(0);//child normally exit}//sys_check
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -