int init_all(ARG_VOID) { int ret=0; chdir(BBSHOME); get_publicshm(); resolve_boards(); ret=resolve_ucache(); resolve_utmp(); #ifndef THREADSAFE init_sessiondata(getSession()); #endif resolve_guest_table(); return ret; }
int main(void){ char path[256]; struct stat st; time_t now; struct tm t; now = time(0); localtime_r( &now, &t); chdir(BBSHOME); if( stat( BONLINE_LOGDIR, &st) < 0 ){ if(mkdir(BONLINE_LOGDIR, 0755) < 0) exit(0); } sprintf(path, "%s/%d", BONLINE_LOGDIR, t.tm_year+1900); if( stat(path, &st) < 0){ if(mkdir(path, 0755) < 0) exit(0); } sprintf(path, "%s/%d/%d", BONLINE_LOGDIR, t.tm_year+1900, t.tm_mon+1); if( stat(path, &st) < 0){ if(mkdir(path, 0755) < 0) exit(0); } sprintf(path,"%s/%d/%d/%d_useronline",BONLINE_LOGDIR,t.tm_year+1900,t.tm_mon+1,t.tm_mday); if((fp=fopen(path, "a"))==NULL){ printf("cannot open log file\n"); exit(0); } sprintf(path, "%s/%d/%d/%d_login", BONLINE_LOGDIR, t.tm_year+1900, t.tm_mon+1, t.tm_mday); if((fp_login=fopen(path, "a"))==NULL){ printf("cannot open log file\n"); exit(0); } sprintf(path, "%s/lastcount", BONLINE_LOGDIR); if((fp_forcount=fopen(path, "w+"))==NULL){ printf("cannot open log file\n"); exit(0); } resolve_utmp(); get_publicshm(); resolve_guest_table(); wwwguestonline = getwwwguestcount(); totalonline = get_utmp_number() + wwwguestonline; apply_ulist_addr((APPLY_UTMP_FUNC)do_userlist, NULL); show_wwwguest(); logincount = get_publicshm()->logincount; logoutcount = get_publicshm()->logoutcount; wwwlogincount = get_publicshm()->wwwlogincount; wwwlogoutcount = get_publicshm()->wwwlogoutcount; wwwguestlogincount = get_publicshm()->wwwguestlogincount; wwwguestlogoutcount = get_publicshm()->wwwguestlogoutcount; staytime = get_publicshm()->staytime; wwwstaytime = get_publicshm()->wwwstaytime; wwwgueststaytime = get_publicshm()->wwwgueststaytime; setpublicshmreadonly(0); get_publicshm()->logincount=0; get_publicshm()->logoutcount=0; get_publicshm()->wwwlogincount=0; get_publicshm()->wwwlogoutcount=0; get_publicshm()->wwwguestlogincount=0; get_publicshm()->wwwguestlogoutcount=0; get_publicshm()->staytime=0; get_publicshm()->wwwstaytime=0; get_publicshm()->wwwgueststaytime=0; setpublicshmreadonly(1); /*格式: 时间 totalonline wwwguestonline wwwnotguestonline telnetonline wwwguestschool wwwnotguestschool telnetschool */ fprintf(fp, "%d.%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", t.tm_hour, t.tm_min/6, totalonline, wwwguestonline, wwwnotguestonline, telnetonline, wwwguestschool, wwwnotguestschool, telnetschool); fprintf(fp_login, "%d.%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", t.tm_hour, t.tm_min/6, logincount, logoutcount, (int)(logoutcount?(staytime/logoutcount)/10:0), wwwlogincount, wwwlogoutcount, wwwguestlogincount, wwwguestlogoutcount, (int)(wwwlogoutcount?(wwwstaytime/wwwlogoutcount)/10:0) , (int)(wwwguestlogoutcount?(wwwgueststaytime/wwwguestlogoutcount)/10:0)); fprintf(fp_forcount, "%d\n%d\n%d\n%d\n%d\n%d\n%d\n", totalonline, wwwguestonline, wwwnotguestonline, telnetonline, wwwguestschool, wwwnotguestschool, telnetschool); fclose(fp); fclose(fp_login); fclose(fp_forcount); return 0; }
static int miscd_dodaemon(char *argv1, char *daemon) { struct sigaction act; char *commandline; char commbuf[10]; char ch; if (!check_file_writable(PASSFILE)) { fprintf(stderr, "Error! File %s is not writable.\n", PASSFILE); exit(-1); } if (!check_file_writable(BOARDS)) { fprintf(stderr, "Error! File %s is not writable.\n", BOARDS); exit(-1); } truncate(BOARDS, MAXBOARD * sizeof(struct boardheader)); if (load_ucache() != 0) { printf("ft,load ucache error!"); exit(-1); } /* init tmpfs */ sprintf(genbuf1,"%s/home",TMPFSROOT); mkdir(genbuf1,0700); sprintf(genbuf1,"%s/boards",TMPFSROOT); mkdir(genbuf1,0700); for (ch='A';ch<='Z';ch++) { sprintf(genbuf1,"%s/home/%c",TMPFSROOT,ch); mkdir(genbuf1,0700); } resolve_boards(); resolve_utmp(); resolve_guest_table(); if (argv1 != NULL) { switch (fork()) { case -1: printf("faint, i can't fork.\n"); exit(0); break; case 0: break; default: exit(0); break; } commandline = argv1; } else { commandline = commbuf; } setsid(); #if defined(FREEBSD) || defined(MACOSX) setpgid(0, 0); #else // by zixia setpgrp(0, 0); setpgrp(); #endif #ifdef AIX act.sa_handler = NULL; act.sa_flags = SA_RESTART | SA_NOCLDWAIT; sigaction(SIGCHLD, &act, NULL); #else act.sa_handler = reaper; act.sa_flags = SA_RESTART; sigaction(SIGCHLD, &act, NULL); #endif if (((daemon == NULL) || (!strcmp(daemon, "timed"))) && ((argv1 == NULL) || fork())) { strcpy(commandline, "timed"); timed(); exit(0); } if (((daemon == NULL) || (!strcmp(daemon, "killd"))) && ((argv1 == NULL) || fork())) { strcpy(commandline, "killd"); char line[20]; const char *path = "var/killd.pid"; int pidfd = open(path, O_RDWR | O_CREAT, 0660); if (write_lock(pidfd, 0, SEEK_SET, 0) < 0) { bbslog("3error", "killd had already been started!"); exit(-1); } snprintf(line, sizeof(line), "%ld\n", (long)getpid()); ftruncate(pidfd, 0); write(pidfd, line, strlen(line)); while (1) { time_t ft; ft = getnextday4am(); do { sleep(ft - time(0)); } while (ft > time(0)); if (argv1 == NULL) { dokilluser(); //doupdategiveupuser(); } else { switch (fork()) { case -1: bbslog("3error", "fork failed\n"); break; case 0: dokilluser(); //doupdategiveupuser(); exit(0); break; default: break; } } switch (fork()) { case -1: bbslog("3error", "fork failed\n"); break; case 0: dokillalldir(); exit(0); break; default: break; } }; exit(0); } if (((daemon == NULL) || (!strcmp(daemon, "userd"))) && ((argv1 == NULL) || fork())) { strcpy(commandline, "userd"); userd(); exit(0); } if ((daemon == NULL) || (!strcmp(daemon, "flushd"))) { strcpy(commandline, "flushd"); flushd(); exit(0); } return 0; }