void init_program(t_shell *ptr, char **env) { ptr->rl.flags = 0; gl_st.tty = 0; ptr->flag |= SH_EXIT; ptr->rl.bind = NULL; ptr->rl.prompt = NULL; ptr->st_tree = NULL; ptr->st_alias = NULL; ptr->my_env = NULL; ptr->st_hist = NULL; ptr->rl.flags |= init_term(ptr); #ifdef __HREACT_ON__ if (!(ptr->st_hreact = xcalloc(1, sizeof(t_hreact)))) ptr->st_hreact = NULL; # else ptr->st_hreact = NULL; #endif /* __HREACT_ON__ */ load_default_conf(ptr, env); load_personalized_conf(ptr); set_env_to_set(); }
/* end by xin.yao: 2011-11-14 */ if(-1 == getOrigDomainConf(fp)) { addInfoLog(2, "getOriginDomainConf error[there are errors in conf file]"); } fclose(fp); } fp = fopen(config.origDomainIPHistoryFileName, "r"); if (NULL == fp) addInfoLog(2, "can not open origin_domain_ip"); else { g_pstOrigDomainHistory_init(); if (-1 == getOrigDomainHistory(fp)) addInfoLog(2, "getOriginDomainHistory error[here are errors in conf file]"); fclose(fp); } return 0; } #ifndef FRAMEWORK int main(int argc, char **argv) #else /* not FRAMEWORK */ int mod_main(int argc, char **argv) #endif /* not FRAMEWORK */ { /* parse command line param */ cmd_parser(argc, argv); /* open log file first, * because of we need write log in the following handled */ open_log(); /* initialize the config variable, * using default configuration or value */ load_default_conf(); detectGlobalInit(); check_conf_file_valid(); /* fork for detect, parent process will wait for child process */ #ifndef FRAMEWORK pid_t pid = fork(); if (pid < 0) { perror("fork()"); kill(0, SIGTERM); exit(1); } if (!pid) #else /* not FRAMEWORK */ { /* 复制自下部分代码,关于fork后主进程的工作 */ struct sigaction sa; struct itimerval itv; sa.sa_handler = alarmTimeoutHandler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGALRM, &sa, NULL); itv.it_interval.tv_sec = 1; itv.it_interval.tv_usec = 0; itv.it_value.tv_sec = custom_cfg.detect_timeout;//g_detect_timeout; //printf("detect_timeout: %ld\n", custom_cfg.detect_timeout); itv.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itv, NULL); } #endif /* not FRAMEWORK */ { int rtn = 0; #ifndef FRAMEWORK int sleep_time; /* set current process resource limit * Limits on resources crontab, and the process is the child process crontab, * inherited this limit, so in order to the stability of the program to modify resource constraints */ if (set_process_rlimit() < 0) { return -1; } /* delayed time: [10, 30)s, * in order to try to spread more FC and upper detection */ if(!delay_start) { srand((unsigned)time(NULL)); //??ʼ???????? sleep_time = rand() % 20 + 10; fprintf(stdout, "sleep %d\n", sleep_time); sleep(sleep_time); } /* core task */ detect_epoll_init(); fd_table_init(); rtn = process_core_task(); if (rtn < 0) { rtn = -1; } fd_table_dest(); eventFreeMemory(); clean_detect_mem(); close_log(); return rtn; #else /* not FRAMEWORK */ if (set_process_rlimit() < 0) { module_enable = 0; return 1; } rtn = process_core_task_before(); if (rtn < 0) { module_enable = 0; return 1; } return 0; #endif /* not FRAMEWORK */ } #ifndef FRAMEWORK else {