/** * @brief clean up file environment * @param "int condition" : condition * @retval -1: fail ; 0: success */ static int CleanupFileEnv(int condition) { int ret = 0; struct shmid_ds buf; switch (condition) { case NO_ERROR: pthread_join(tProcFileThread, NULL); /* No break */ case FILE_THREAD_FAIL: Sem_kill(); /* No break */ case FILE_SEM_FAIL: FileMngExit(); /* No break */ case FILE_MNG_FAIL: Msg_Kill(qFileId); /* No break */ case MSG_FAIL: /* Share Memory unmap */ shmdt(pFileShareMem); /* Kill Share Memory */ shmctl(mFileId, IPC_RMID, &buf); break; default: ret = - 1; break; } return ret; }
int Exec_Msg(int type, char **result, int key, char *arg, char *menuname) { *result=NULL; switch (type) { case same_direction: if (direction==DIRECTION_NEXT) Msg_Next(last_msg); else Msg_Previous(last_msg); break; case msg_area: Msg_Area(); break; case read_next: Msg_Next(last_msg); break; case read_previous: Msg_Previous(last_msg); break; case read_individual: Msg_Read_Individual(key); break; case msg_current: Msg_Current(); break; case read_original: Msg_Read_Original(); break; case read_reply: Msg_Read_Reply(); break; case msg_kill: Msg_Kill(-1L); break; case forward: Msg_Forward(NULL); break; case enter_message: Msg_Enter(); break; case msg_reply: Msg_Reply(); break; case msg_edit_user: Msg_Edit_User(); break; case read_nonstop: Msg_Nonstop(); break; case msg_list: Msg_List(menuname); break; case msg_scan: Msg_Scan(menuname); break; case msg_checkmail: Msg_Checkmail(menuname); break; case msg_inquir: Msg_Inquire(menuname); break; case msg_hurl: Msg_Hurl(); break; case msg_upload: Msg_Upload(); break; case msg_upload_qwk: QWK_Upload(); break; case xport: Msg_Xport(); break; case msg_change: Msg_Change(); break; case msg_tag: Msg_Tag(); break; case msg_browse: Msg_Browse(0, NULL, menuname); break; case msg_unreceive: Msg_Unreceive(last_msg, NULL); break; case msg_restrict: Msg_Restrict(); break; case msg_toggle_kludges: Msg_Toggle_Kludges(); break; #ifdef MAX_TRACKER case msg_track: TrackMenu(); break; #endif case msg_dload_attach: Msg_Attach_Download(); break; case msg_reply_area: Msg_ReplyArea(arg); break; default: logit(bad_menu_opt, type); return 0; } return 0; }
/** * @brief thread processing message * @param none * @retval 0 */ static int FileMsgThread() { FILE_MSG_BUF msgbuf; int msg_size, e_count = 0; while (IsFileThreadQuit() == 0) { msg_size = msgrcv(qFileId, &msgbuf, sizeof(msgbuf) - sizeof(long), MSG_TYPE_MSG1, 0); DBG("Recieved message:%d from %d\n", msgbuf.cmd, msgbuf.src); if (msg_size < 0) { ERR("Receive msg fail \n"); #if 0 SetFileQuit(); break; #else if (e_count++ >= 3) { /* Kill message queue and init angain */ perror("msgrcv ERROR"); Msg_Kill(qFileId); qFileId = Msg_Init(FILE_MSG_KEY); } #endif } else if (msgbuf.src == MSG_TYPE_MSG1 || msgbuf.src < 0) { ERR("Got Error message\n"); SetFileQuit(); break; } else { e_count = 0; if (ProcFileMsg(&msgbuf) == 1) /* Message has been processed */ { DBG("Message process success\n"); } if (msgbuf.src != 0) { msgbuf.Des = msgbuf.src; msgbuf.src = MSG_TYPE_MSG1; msgsnd(qFileId, &msgbuf, sizeof(msgbuf) - sizeof(long), 0); } } } return 0; }
/** * @brief Main thread of alarm server. * @param arg [I ] Not used. * @return 0 on alarm server normal end. */ void *AlramThread(void *arg) { int qid; int audQid; SemHandl_t hAlarmSem; pthread_t thread; void *ret; qid = Msg_Init(ALARM_KEY); if(qid < 0) return PROC_FAIL; audQid = Msg_Init(AUD_MSG_KEY); if(audQid < 0) return PROC_FAIL; hAlarmSem = MakeSem(); if(hAlarmSem == NULL){ Msg_Kill(qid); return PROC_FAIL; } hAlarmStatusSem = MakeSem(); if(hAlarmStatusSem == NULL){ DestroySem(hAlarmSem); Msg_Kill(qid); return PROC_FAIL; } audioSem = MakeSem(); if(audioSem == NULL){ DestroySem(hAlarmStatusSem); DestroySem(hAlarmSem); Msg_Kill(qid); return PROC_FAIL; } if(pthread_create(&thread, NULL, AlramScheduler, NULL)){ DestroySem(hAlarmStatusSem); DestroySem(audioSem); DestroySem(hAlarmSem); Msg_Kill(qid); return PROC_FAIL; } if(AviMngInit()){ AlarmScheduleExit(); pthread_join(thread, &ret); DestroySem(hAlarmStatusSem); DestroySem(audioSem); DestroySem(hAlarmSem); Msg_Kill(qid); return PROC_FAIL; } if(JpgMngInit()){ AviMngExit(); AlarmScheduleExit(); pthread_join(thread, &ret); DestroySem(hAlarmStatusSem); DestroySem(audioSem); DestroySem(hAlarmSem); Msg_Kill(qid); return PROC_FAIL; } if(FileDispatcherInit()){ JpgMngExit(); AviMngExit(); AlarmScheduleExit(); pthread_join(thread, &ret); DestroySem(hAlarmStatusSem); DestroySem(audioSem); DestroySem(hAlarmSem); Msg_Kill(qid); return PROC_FAIL; } alarm_main_loop(qid, audQid, hAlarmSem); AviMngExit(); JpgMngExit(); FileDispatcherExit(); DestroySem(hAlarmStatusSem); DestroySem(audioSem); DestroySem(hAlarmSem); Msg_Kill(qid); Msg_Kill(audQid); return PROC_SUCESS; }