int main(int argc, char *argv[]) { chdir(BBSHOME); //进入BBS用户主目录 setuid(BBSUID); //将进程的 用户ID setgid(BBSGID); //组ID设置成BBS setreuid(BBSUID, BBSUID); //设置有效用户ID setregid(BBSGID, BBSGID); //有效组ID为BBS if (argc <= 1) { printf("usage: daemon | flushed | reload\n"); exit(0); } if ( !strcasecmp(argv[1], "daemon") ) { // miscd daemon switch (fork()) { //后台程序:需要创建一个子进程,由子进程杀死父进程 case -1: // printf("cannot fork\n"); exit(0); break; case 0: // 子进程 break; default: exit(0); //父进程 break; } if (load_ucache() != 0) { //将用户的数据映射到内存 printf("load ucache error\n"); exit(-1); } if (resolve_boards() < 0) exit(-1); atexit(do_exit); //注册退出前运行的函数.正常退出前须执行此函数 while (1) { //循环 refresh_utmp(); //刷新用户临时数据 b_closepolls(); //关闭投票 flush_ucache(); //将用户在内存中的数据写回.PASSWDS flush_bcache(); sleep(60 * 15); //睡眠十分钟,即每十五分钟同步一次. } } else if ( !strcasecmp(argv[1], "flushed") ) { //miscd flushed if (resolve_ucache() == -1) exit(1); flush_ucache(); flush_bcache(); } else if ( !strcasecmp(argv[1], "reload") ) { //miscd reload if (load_ucache() != 0) { printf("load ucache error\n"); exit(-1); } } else { printf("usage: daemon | flushed | reload\n"); exit(0); } return 0; }
static void start_client() { extern struct commands_t cmdlist[]; int nreg; /* system init */ currmode = 0; signal(SIGHUP, abort_bbs); signal(SIGTERM, abort_bbs); signal(SIGPIPE, abort_bbs); signal(SIGINT, abort_bbs_debug); signal(SIGQUIT, abort_bbs_debug); signal(SIGILL, abort_bbs_debug); signal(SIGABRT, abort_bbs_debug); signal(SIGFPE, abort_bbs_debug); signal(SIGBUS, abort_bbs_debug); signal(SIGSEGV, abort_bbs_debug); signal_restart(SIGUSR1, talk_request); signal_restart(SIGUSR2, write_request); dup2(0, 1); do_term_init(); signal(SIGALRM, abort_bbs); alarm(600); login_query(); /* Ptt 加上login time out */ user_login(); m_init(); #if FORCE_PROCESS_REGISTER_FORM if (HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163) > 100) { char cpu_load[30]; if(cpuload(cpu_load) > MAX_CPULOAD*2/3) /* DickG: 根據目前的 load 來 */ scan_register_form(fn_register, 1, nreg/20); /* 決定要審核的數目 */ else scan_register_form(fn_register, 1, nreg/10); } #endif if(HAVE_PERM(PERM_SYSOP | PERM_BM)) b_closepolls(); if(!(cuser.uflag & COLOR_FLAG)) showansi = 0; #ifdef DOTIMEOUT /* init_alarm();*/ // cause strange logout with saving post. signal(SIGALRM, SIG_IGN); #else signal(SIGALRM, SIG_IGN); #endif if(chkmailbox()) m_read(); domenu(MMENU, "主功\能表", (chkmail(0) ? 'M' : 'C'), cmdlist); }