diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/BM_money.c | 6 | ||||
-rw-r--r-- | util/Makefile | 15 | ||||
-rw-r--r-- | util/account.c | 11 | ||||
-rw-r--r-- | util/antispam.c | 4 | ||||
-rw-r--r-- | util/birth.c | 1 | ||||
-rw-r--r-- | util/buildAnnounce.c | 3 | ||||
-rw-r--r-- | util/expire.c | 4 | ||||
-rw-r--r-- | util/horoscope.c | 3 | ||||
-rw-r--r-- | util/indexuser.c | 5 | ||||
-rw-r--r-- | util/inndBM.c | 4 | ||||
-rw-r--r-- | util/jungo.c | 3 | ||||
-rw-r--r-- | util/mandex.c | 12 | ||||
-rw-r--r-- | util/openticket.c | 20 | ||||
-rw-r--r-- | util/openvice.c | 11 | ||||
-rw-r--r-- | util/parse_news.c | 5 | ||||
-rw-r--r-- | util/post.c | 9 | ||||
-rw-r--r-- | util/poststat.c | 3 | ||||
-rw-r--r-- | util/reaper.c | 8 | ||||
-rw-r--r-- | util/rmuid.c | 5 | ||||
-rw-r--r-- | util/shmctl.c | 94 | ||||
-rw-r--r-- | util/toplazyBBM.c | 3 | ||||
-rw-r--r-- | util/toplazyBM.c | 3 | ||||
-rw-r--r-- | util/topusr.c | 21 | ||||
-rw-r--r-- | util/util_cache.c | 565 | ||||
-rw-r--r-- | util/xchatd.c | 22 | ||||
-rw-r--r-- | util/yearsold.c | 5 |
26 files changed, 169 insertions, 676 deletions
diff --git a/util/BM_money.c b/util/BM_money.c index e2ed960f..075f53ae 100644 --- a/util/BM_money.c +++ b/util/BM_money.c @@ -1,4 +1,4 @@ -/* $Id: BM_money.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: BM_money.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ /* 給板主錢的程式 */ @@ -27,12 +27,14 @@ int Link(char *src, char *dst) { } -int main() { +int main(int argc, char **argv) +{ FILE *fp = fopen(BBSHOME "/etc/topboardman", "r"); char buf[201], bname[20], BM[90], *ch; boardheader_t *bptr = NULL; int nBM; + attach_SHM(); resolve_boards(); if(passwd_mmap()) exit(1); diff --git a/util/Makefile b/util/Makefile index 2f11c9ea..a62ee3a8 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,9 +1,9 @@ -# $Id: Makefile,v 1.35 2003/07/19 09:33:34 in2 Exp $ +# $Id: Makefile,v 1.36 2003/07/20 00:55:34 in2 Exp $ .include "../pttbbs.mk" UTIL_OBJS= \ - util_cache.o util_record.o util_passwd.o + util_cache.o util_record.o util_passwd.o util_var.o util_stuff.o # 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ @@ -33,9 +33,18 @@ all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} bbsmail .for fn in ${CPROG_WITH_UTIL} ${fn}: ${fn}.c ${UTIL_OBJS} - ${CC} ${CFLAGS} -o ${fn} ${fn}.c ${UTIL_OBJS} + ${CC} ${CFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c .endfor +util_var.o: ../mbbsd/var.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_var.o ../mbbsd/var.c + +util_stuff.o: ../mbbsd/stuff.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_stuff.o ../mbbsd/stuff.c + +util_cache.o: ../mbbsd/cache.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_cache.o ../mbbsd/cache.c + bbsmail: bbsmail.c ${CPROG_WITH_UTIL} ../mbbsd/osdep.o ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o ${LDFLAGS} diff --git a/util/account.c b/util/account.c index bbc84244..827eefb4 100644 --- a/util/account.c +++ b/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.8 2003/07/05 07:58:09 in2 Exp $ */ +/* $Id: account.c,v 1.9 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define MAX_LINE 16 @@ -55,8 +55,9 @@ keeplog(fpath, board, title) strcpy(fhdr.owner, "[歷史老師]"); sprintf(genbuf, "boards/%c/%s/.DIR", board[0], board); append_record(genbuf, &fhdr, sizeof(fhdr)); - if((bid = getbnum(board)) > 0)touchbtotal(bid); - + /* XXX: bid of cache.c's getbnum starts from 1 */ + if((bid = getbnum(board)) > 0) + touchbtotal(bid); } @@ -86,7 +87,8 @@ void gzip(source, target, stamp) system(buf); } -int main() { +int main(int argc, char **argv) +{ int hour, max, item, total, i, j, mo, da, max_user = 0, max_login = 0, max_reg = 0, mahour = 0, k; char *act_file = ".act"; @@ -97,6 +99,7 @@ int main() { time_t now; struct tm *ptime; + attach_SHM(); nice(10); chdir(BBSHOME); now = time(NULL) - ADJUST_M * 60; /* back to ancent */ diff --git a/util/antispam.c b/util/antispam.c index f7b77569..e29549aa 100644 --- a/util/antispam.c +++ b/util/antispam.c @@ -1,4 +1,4 @@ -/* $Id: antispam.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: antispam.c,v 1.2 2003/07/20 00:55:34 in2 Exp $ */ /* 抓廣告信的程式 */ #include <stdio.h> #include <string.h> @@ -22,7 +22,7 @@ typedef struct sendinfo sendinfo; int - main() +main(int argc, char **argv) { char buf[200], *from, *userid; int num = -1, numb = -1, n, nb; diff --git a/util/birth.c b/util/birth.c index 23272d6f..b7f65761 100644 --- a/util/birth.c +++ b/util/birth.c @@ -45,6 +45,7 @@ int main(argc, argv) struct tm *ptime; int j; + attach_SHM(); now = time(NULL); /* back to ancent */ ptime = localtime(&now); diff --git a/util/buildAnnounce.c b/util/buildAnnounce.c index 1db151f9..0bfbefbd 100644 --- a/util/buildAnnounce.c +++ b/util/buildAnnounce.c @@ -62,13 +62,14 @@ void buildchilds(int level,char *path,int gid) } -int main() +int main(int argc, char **argv) { char path[512]; setsid(); strcpy(path,GROUPROOT); system("rm -rf "GROUPROOT); mkdir(GROUPROOT,0766); + attach_SHM(); resolve_boards(); buildchilds(0,path,1); return 0; diff --git a/util/expire.c b/util/expire.c index 30e9ab2f..b75c85b8 100644 --- a/util/expire.c +++ b/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.6 2002/11/11 03:06:03 in2 Exp $ */ +/* $Id: expire.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ /* 自動砍信工具程式 */ #include "bbs.h" @@ -36,6 +36,7 @@ life *brd; int duetime, ftime; printf("%s\n", brd->bname); + /* XXX: bid of cache.c's getbnum starts from 1 */ if((bid = getbnum(brd->bname)) == 0 || strcmp(brd->bname, bcache[bid-1].brdname)) { @@ -144,6 +145,7 @@ char *argv[]; 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', NULL}; + attach_SHM(); resolve_boards(); db.days = ((argc > 1) && (number = atoi(argv[1])) > 0) ? number : DEF_DAYS; db.maxp = ((argc > 2) && (number = atoi(argv[2])) > 0) ? number : DEF_MAXP; diff --git a/util/horoscope.c b/util/horoscope.c index 53d69e31..b47634aa 100644 --- a/util/horoscope.c +++ b/util/horoscope.c @@ -1,4 +1,4 @@ -/* $Id: horoscope.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: horoscope.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -32,6 +32,7 @@ int main() { "▋", "▊", "▉", "█", "█", }; + attach_SHM(); memset(act, 0, sizeof(act)); if(passwd_mmap()) exit(1); diff --git a/util/indexuser.c b/util/indexuser.c index 8b39fdd0..e0975130 100644 --- a/util/indexuser.c +++ b/util/indexuser.c @@ -1,4 +1,4 @@ -/* $Id: indexuser.c,v 1.5 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: indexuser.c,v 1.6 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" #define INDEXPATH BBSHOME"/index" @@ -15,12 +15,13 @@ unsigned string_hash(unsigned char *s) } -int main() +int main(int argc, char **argv) { int j; userec_t u; char buf[256]; + attach_SHM(); if(passwd_mmap()) { printf("Sorry, the data is not ready.\n"); diff --git a/util/inndBM.c b/util/inndBM.c index 8f1a69a0..363220f5 100644 --- a/util/inndBM.c +++ b/util/inndBM.c @@ -90,6 +90,7 @@ int load_newsfeeds() sscanf(str,"%s %s %s", feedline[feedcount].group,feedline[feedcount].board, feedline[feedcount].server); + /* XXX: bid of cache.c's getbnum starts from 1 */ bid=getbnum(feedline[feedcount].board); if(!bid) { fprintf(fo,"%s %s\n", feedline[feedcount].board, feedline[feedcount].group ); @@ -129,12 +130,13 @@ int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) fprintf(fpscript, buf); return 0; } -int main() +int main(int argc, char **argv) { int i,serverid=0; FILE *fp=NULL,*fpscript=fopen(INND_SCRIPT,"w"); char buf[256],serverstr[30]=""; chdir(BBSHOME "/innd"); + attach_SHM(); resolve_boards(); memset(istran,0,sizeof(int)*MAX_BOARD); load_server(); diff --git a/util/jungo.c b/util/jungo.c index 4c7c2d94..4f038efe 100644 --- a/util/jungo.c +++ b/util/jungo.c @@ -1,4 +1,4 @@ -/* $Id: jungo.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: jungo.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -47,6 +47,7 @@ int main(int argc, char *argv[]) int bmid, i, j=0; FILE *inf, *firef; + attach_SHM(); resolve_boards(); if(passwd_mmap()) diff --git a/util/mandex.c b/util/mandex.c index 6088bc75..f1059f68 100644 --- a/util/mandex.c +++ b/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.9 2003/05/15 08:27:23 in2 Exp $ */ +/* $Id: mandex.c,v 1.10 2003/07/20 00:55:34 in2 Exp $ */ /* 'mandex -h' to help */ @@ -36,15 +36,6 @@ int k_cmp(b, a) return ((a->k / 100 + a->ndir + a->nfile) - (b->k / 100 + b->ndir + b->nfile)); } -int dashd(fname) - char *fname; -{ - struct stat st; - - return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); -} - - /* visit the hierarchy recursively */ void @@ -189,6 +180,7 @@ int main(int argc, char* argv[]) argc -= optind; argv += optind; + attach_SHM(); resolve_boards(); /* if( argc == 0 ){ diff --git a/util/openticket.c b/util/openticket.c index 55e04b0e..5d7584bc 100644 --- a/util/openticket.c +++ b/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.9 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: openticket.c,v 1.10 2003/07/20 00:55:34 in2 Exp $ */ /* 開獎的 utility */ #define _UTIL_C_ #include "bbs.h" @@ -21,19 +21,7 @@ int Link(char *src, char *dst) return system(cmd); } -char * - Cdatelite(clock) -time_t *clock; -{ - static char foo[18]; - struct tm *mytm = localtime(clock); - - strftime(foo, 18, "%D %T", mytm); - return (foo); -} - - -int main() +int main(int argc, char **argv) { int money, bet, n, total = 0, ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -43,6 +31,7 @@ int main() {"", "", "", ""}; nice(10); + attach_SHM(); if(passwd_mmap()) exit(1); @@ -93,7 +82,8 @@ int main() bet=random() % 8; - resolve_utmp(); + //XXX: resolve_utmp(); + attach_SHM(); bet = SHM->UTMPnumber % 8; /* diff --git a/util/openvice.c b/util/openvice.c index b622eb55..41c146ab 100644 --- a/util/openvice.c +++ b/util/openvice.c @@ -1,4 +1,4 @@ -/* $Id: openvice.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: openvice.c,v 1.3 2003/07/20 00:55:34 in2 Exp $ */ /* 發票開獎小程式 */ #include "bbs.h" @@ -9,17 +9,16 @@ #define VICE_DATA "vice.data" #define MAX_BINGO 99999999 -int main() +int main(int argc, char **argv) { - char TABLE[5][3] = - {"一", "二", "三", "四", "五"}; - + char *TABLE[5] = {"一", "二", "三", "四", "五"}; int i = 0, bingo, base = 0; FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w"); - resolve_utmp(); + // XXX: resolve_utmp(); + attach_SHM(); srand(SHM->number); diff --git a/util/parse_news.c b/util/parse_news.c index 042cf107..b1f0ad25 100644 --- a/util/parse_news.c +++ b/util/parse_news.c @@ -1,10 +1,11 @@ -/* $Id: parse_news.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: parse_news.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define NEWSDIRECT BBSHOME "/boards/n/newspaper" #define MOVIEDIRECT BBSHOME "/etc/NEWS" -int main() { +int main(int argc, char **argv) +{ int fd; fileheader_t fh, news; struct stat st; diff --git a/util/post.c b/util/post.c index 0d93e0a0..ba6ee1d7 100644 --- a/util/post.c +++ b/util/post.c @@ -1,4 +1,4 @@ -/* $Id: post.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: post.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { @@ -27,14 +27,17 @@ void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { strcpy(fhdr.owner, owner); sprintf(genbuf, BBSHOME "/boards/%c/%s/.DIR", board[0], board); append_record(genbuf, &fhdr, sizeof(fhdr)); + /* XXX: bid of cache.c's getbnum starts from 1 */ if((bid = getbnum(board)) > 0) touchbtotal(bid); } -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ FILE *fp; - + + attach_SHM(); resolve_boards(); if(argc != 5) { printf("usage: %s <board name> <title> <owner> <file>\n", argv[0]); diff --git a/util/poststat.c b/util/poststat.c index acd4aed4..37bcc399 100644 --- a/util/poststat.c +++ b/util/poststat.c @@ -1,4 +1,4 @@ -/* $Id: poststat.c,v 1.4 2002/06/30 16:06:19 in2 Exp $ */ +/* $Id: poststat.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ /* 統計今日、週、月、年熱門話題 */ #include "bbs.h" @@ -184,6 +184,7 @@ filter(board) boardheader_t bh; int bid; + /* XXX: bid of cache.c's getbnum starts from 1 */ bid = getbnum(board); if (get_record(".BRD", &bh, sizeof(bh), bid) == -1) return 1; diff --git a/util/reaper.c b/util/reaper.c index 9ed1b11f..633a4c78 100644 --- a/util/reaper.c +++ b/util/reaper.c @@ -1,4 +1,4 @@ -/* $Id: reaper.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: reaper.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -46,11 +46,13 @@ int check(int n, userec_t *u) { return 0; } -int main() { +int main(int argc, char **argv) +{ now = time(NULL); openlog("reaper", LOG_PID | LOG_PERROR, SYSLOG_FACILITY); chdir(BBSHOME); - + + attach_SHM(); if(passwd_mmap()) exit(1); passwd_apply2(check); diff --git a/util/rmuid.c b/util/rmuid.c index 901a31c8..2bd1017a 100644 --- a/util/rmuid.c +++ b/util/rmuid.c @@ -1,4 +1,4 @@ -/* $Id: rmuid.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: rmuid.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" extern int numboards; @@ -23,7 +23,8 @@ int main(int argc, char* argv[]) int n; boardheader_t bh; //char pathname[1024]; - + + attach_SHM(); resolve_boards(); for (n=0;n<numboards;n++){ memcpy( &bh, &bcache[n], sizeof(bh)); diff --git a/util/shmctl.c b/util/shmctl.c index 66c9888e..382a823b 100644 --- a/util/shmctl.c +++ b/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.44 2003/07/04 02:31:58 in2 Exp $ */ +/* $Id: shmctl.c,v 1.45 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -272,6 +272,7 @@ int utmpsortd(int argc, char **argv) return 0; } + setproctitle("shmctl utmpsortd"); if( argc != 2 || (interval = atoi(argv[1])) < 500000 ) interval = 1000000; // default to 1 sec @@ -439,6 +440,7 @@ int timed(int argc, char **argv) perror("fork()"); if( pid != 0 ) return 0; + setproctitle("shmctl timed"); while( 1 ){ SHM->GV2.e.now = time(NULL); sleep(1); @@ -446,6 +448,79 @@ int timed(int argc, char **argv) } #endif +#if 0 +void buildclass(int bid, int level) +{ + boardheader_t *bptr; + if( level == 20 ){ /* for safty */ + printf("is there something wrong? class level: %d\n", level); + return; + } + bptr = &bcache[bid]; + if (bptr->firstchild[0] == NULL || bptr->childcount <= 0) + load_uidofgid(bid + 1, 1); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ + if (bptr->firstchild[1] == NULL || bptr->childcount <= 0) + load_uidofgid(bid + 1, 1); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ + + for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; + bptr = bptr->next[0]) { + if( bptr->brdattr & BRD_GROUPBOARD ) + buildclass(bptr - bcache, level + 1); + } +} +#endif + +int bBMC(int argc, char **argv) +{ + int i; + for( i = 0 ; i < MAX_BOARD ; ++i ) + if( bcache[i].brdname[0] ) + buildBMcache(i + 1); /* XXXbid */ + return 0; +} + +int SHMinit(int argc, char **argv) +{ + int ch; + int no_uhash_loader = 0; + while( (ch = getopt(argc, argv, "n")) != -1 ) + switch( ch ){ + case 'n': + no_uhash_loader = 1; + break; + default: + printf("usage:\tshmctl\tSHMinit\n"); + return 0; + } + + puts("loading uhash..."); + system("bin/uhash_loader"); + + attach_SHM(); + + puts("loading bcache..."); + reload_bcache(); + + puts("building BMcache..."); + bBMC(1, NULL); + +#if 0 + puts("building class..."); + buildclass(0, 0); +#endif + + if( !no_uhash_loader ){ + puts("utmpsortd..."); + utmpsortd(1, NULL); + } + +#ifdef OUTTA_TIMER + puts("timed..."); + timed(1, NULL); +#endif + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; @@ -463,22 +538,23 @@ struct { #ifdef OUTTA_TIMER {timed, "timed", "time daemon for OUTTA_TIMER"}, #endif + {bBMC, "bBMC", "build BM cache"}, + {SHMinit, "SHMinit", "initialize SHM (including uhash_loader)"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) { int i = 0; + chdir(BBSHOME); if( argc >= 2 ){ - /* shmctl shouldn't create shm itself */ - int shmid = shmget(SHM_KEY, sizeof(SHM_t), 0); - if( shmid < 0 ){ - printf("%d\n", errno); - perror("attach utmpshm"); - return 1; + if( strcmp(argv[1], "init") == 0 ){ + /* in this case, do NOT run attach_SHM here. + because uhash_loader is not run yet. */ + return SHMinit(argc - 1, &argv[1]); } - chdir(BBSHOME); - resolve_utmp(); + + attach_SHM(); /* shmctl doesn't need resolve_boards() first */ //resolve_boards(); resolve_garbage(); diff --git a/util/toplazyBBM.c b/util/toplazyBBM.c index 1b12eab9..0e5b078b 100644 --- a/util/toplazyBBM.c +++ b/util/toplazyBBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBBM.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: toplazyBBM.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -48,6 +48,7 @@ int main(int argc, char *argv[]) int bmid, i, j=0; FILE *inf, *firef; + attach_SHM(); resolve_boards(); if(passwd_mmap()) diff --git a/util/toplazyBM.c b/util/toplazyBM.c index fc656817..5dc9a3df 100644 --- a/util/toplazyBM.c +++ b/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.17 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: toplazyBM.c,v 1.18 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) int bmid, i, j=0; FILE *inf, *firef; time_t now=time(NULL); + attach_SHM(); resolve_boards(); if(passwd_mmap()) diff --git a/util/topusr.c b/util/topusr.c index 3b90a7e2..37b051d9 100644 --- a/util/topusr.c +++ b/util/topusr.c @@ -1,4 +1,4 @@ -/* $Id: topusr.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: topusr.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ /* 使用者 上站記錄/文章篇數 排行榜 */ #define _UTIL_C_ #include "bbs.h" @@ -90,20 +90,6 @@ int } } #endif /* HAVE_TIN */ -int - not_alpha(ch) -register char ch; -{ - return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); -} - -int - not_alnum(ch) -register char ch; -{ - return (ch < '0' || (ch > '9' && ch < 'A') || - (ch > 'Z' && ch < 'a') || ch > 'z'); -} int bad_user_id(userid) @@ -122,9 +108,7 @@ char *userid; return 0; } -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i, j; @@ -138,6 +122,7 @@ char **argv; if (num == 0) num = 30; + attach_SHM(); if(passwd_mmap()) { printf("Sorry, the data is not ready.\n"); diff --git a/util/util_cache.c b/util/util_cache.c deleted file mode 100644 index a8dd6b71..00000000 --- a/util/util_cache.c +++ /dev/null @@ -1,565 +0,0 @@ -/* $Id: util_cache.c,v 1.11 2003/05/16 18:58:49 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <fcntl.h> -#include <ctype.h> -#include <errno.h> -#include <time.h> -#include <sys/types.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/sem.h> - -#ifdef __FreeBSD__ -#include <machine/param.h> -#endif - -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" - -/* the reason for "safe_sleep" is that we may call sleep during - SIGALRM handler routine, while SIGALRM is blocked. - if we use the original sleep, we'll never wake up. */ -unsigned int safe_sleep(unsigned int seconds) { - /* jochang sleep有問題時用*/ - sigset_t set,oldset; - - sigemptyset(&set); - sigprocmask(SIG_BLOCK, &set, &oldset); - if(sigismember(&oldset, SIGALRM)) { - unsigned long retv; - sigemptyset(&set); - sigaddset(&set,SIGALRM); - sigprocmask(SIG_UNBLOCK,&set,NULL); - retv=sleep(seconds); - sigprocmask(SIG_BLOCK,&set,NULL); - return retv; - } - return sleep(seconds); -} - -void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); -} - -static char *str_dotdir = ".DIR"; - -void setadir(char *buf, char *path) { - sprintf(buf, "%s/%s", path, str_dotdir); -} - -static void attach_err(int shmkey, char *name) { - fprintf(stderr, "[%s error] key = %x\n", name, shmkey); - fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); - exit(1); -} - -void *attach_shm(int shmkey, int shmsize) { - void *shmptr; - int shmid; - - char *empty_addr; - /* set up one page in-accessible -- jochang */ - { - int fd = open("/dev/zero",O_RDONLY); - int size = ((shmsize + 4095) / 4096) * 4096; - - munmap( - (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 - ,size); - - close(fd); - } - - shmid = shmget(shmkey, shmsize, 0); - if(shmid < 0) { - shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if(shmid < 0) - attach_err(shmkey, "shmget"); - shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) - attach_err(shmkey, "shmat"); - } else { - shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) - attach_err(shmkey, "shmat"); - } - - /* unmap the page -- jochang */ - { - munmap(empty_addr,4096); - } - return shmptr; -} - -#ifndef __FreeBSD__ -/* according to X/OPEN we have to define it ourselves */ -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short int *array; /* array for GETALL, SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; -#endif - -#define SEM_FLG 0600 /* semaphore mode */ - -/* ----------------------------------------------------- */ -/* semaphore : for critical section */ -/* ----------------------------------------------------- */ -void sem_init(int semkey,int *semid) { - union semun s; - - s.val=1; - *semid = semget(semkey, 1, 0); - if(*semid == -1) { - *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); - if(*semid == -1) - attach_err(semkey, "semget"); - semctl(*semid, 0, SETVAL, s); - } -} - -void sem_lock(int op,int semid) { - struct sembuf sops; - - sops.sem_num = 0; - sops.sem_flg = SEM_UNDO; - sops.sem_op = op; - semop(semid, &sops, 1); -} - -SHM_t *SHM; -int *GLOBALVAR; -boardheader_t *bcache; -int numboards = -1; - -void attach_SHM(void) -{ - SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); - if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ - exit(1); - if( SHM->Btouchtime == 0 ) - SHM->Btouchtime = 1; - bcache = SHM->bcache; - - GLOBALVAR = SHM->GLOBALVAR; - if( SHM->Ptouchtime == 0 ) - SHM->Ptouchtime = 1; - - if( SHM->Ftouchtime == 0 ) - SHM->Ftouchtime = 1; - - bcache = SHM->bcache; - numboards = SHM->Bnumber; -} - -int setumoney(int uid, int money) { - SHM->money[uid-1]=money; - passwd_update_money(uid); - return SHM->money[uid-1]; -} - -int deumoney(int uid, int money) { - if(money<0 && SHM->money[uid-1]<-money) - return setumoney(uid,0); - else - return setumoney(uid,SHM->money[uid-1]+money); -} -int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return SHM->money[uid-1]; -} - -static unsigned string_hash(unsigned char *s) { - unsigned int v=0; - while(*s) { - v = (v << 8) | (v >> 24); - v ^= toupper(*s++); /* note this is case insensitive */ - } - return (v * 2654435769UL) >> (32 - HASH_BITS); -} - -void add_to_uhash(int n, char *id) { - int *p, h = string_hash(id); - strcpy(SHM->userid[n], id); - - p = &(SHM->hash_head[h]); - - while(*p != -1) - p = &(SHM->next_in_hash[*p]); - - SHM->next_in_hash[*p = n] = -1; -} - -/* note: after remove_from_uhash(), you should add_to_uhash() - (likely with a different name) */ -void remove_from_uhash(int n) { - int h = string_hash(SHM->userid[n]); - int *p = &(SHM->hash_head[h]); - - while(*p != -1 && *p != n) - p = &(SHM->next_in_hash[*p]); - if(*p == n) - *p = SHM->next_in_hash[n]; -} - -int searchuser(char *userid) { - int h,p; - - if(SHM == NULL) - attach_SHM(); /* for sloopy util programs */ - - h = string_hash(userid); - p = SHM->hash_head[h]; - - while(p != -1) { - if(strcasecmp(SHM->userid[p],userid) == 0) { - strcpy(userid,SHM->userid[p]); - return p + 1; - } - p = SHM->next_in_hash[p]; - } - return 0; -} -userec_t xuser; - -int getuser(char *userid) { - int uid; - if((uid = searchuser(userid))) - passwd_query(uid, &xuser); - return uid; -} - -void setuserid(int num, char *userid) { - if(num > 0 && num <= MAX_USERS) { - if(num > SHM->number) - SHM->number = num; - else - remove_from_uhash(num-1); - add_to_uhash(num-1,userid); - } -} - -/*-------------------------------------------------------*/ -/* .UTMP cache */ -/*-------------------------------------------------------*/ -void resolve_utmp() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->UTMPuptime == 0) - SHM->UTMPuptime = SHM->UTMPnumber = 1; - } -} - -userinfo_t *currutmp = NULL; - -void getnewutmpent(userinfo_t *up) { - extern int errno; - register int i; - register userinfo_t *uentp; - - resolve_utmp(); - - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(!(uentp->pid)) { - memcpy(uentp, up, sizeof(userinfo_t)); - currutmp = uentp; - SHM->number++; - return; - } - } - exit(1); -} - -int apply_ulist(int (*fptr)(userinfo_t *)) { - register userinfo_t *uentp; - register int i, state; - - resolve_utmp(); - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) - if((state = (*fptr) (uentp))) - return state; - } - return 0; -} - -userinfo_t *search_ulist(int uid) { - register int i; - register userinfo_t *uentp; - - resolve_utmp(); - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(uid==uentp->uid) - return uentp; - } - return 0; -} - -/*-------------------------------------------------------*/ -/* .BOARDS cache */ -/*-------------------------------------------------------*/ -char *fn_board=BBSHOME"/"FN_BOARD; -static int -cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) -{ - return strcasecmp((*brd)->brdname, (*tmp)->brdname); -} - -static int -cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) -{ - return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + - strcasecmp((*brd)->brdname, (*tmp)->brdname); -} -static void -sort_bcache() -{ - int i; - /* critical section \xa4\xa3\xaf\xe0\xb3\xe6\xbfW\xa9I\xa5s \xa9I\xa5sreload -_bcache or reset_board */ - for (i = 0; i < SHM->Bnumber; i++) { - SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; - } - qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST) cmpboardname); - qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST) cmpboardclass); -} - - -static void -reload_bcache() -{ - if (SHM->Bbusystate) { - safe_sleep(1); - } - else { - int fd, i; - - SHM->Bbusystate = 1; - if ((fd = open(fn_board, O_RDONLY)) > 0) { - SHM->Bnumber = - read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / - sizeof(boardheader_t); - close(fd); - } - memset(SHM->lastposttime, 0, MAX_BOARD * sizeof(time_t)); - SHM->Buptime = SHM->Btouchtime; - sort_bcache(); - for (i = 0; i < SHM->Bnumber; ++i) { - bcache[i].firstchild[0] = NULL; - bcache[i].firstchild[1] = NULL; - } - SHM->Bbusystate = 0; - } -} - -void resolve_boards() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->Btouchtime == 0) - SHM->Btouchtime = 1; - } - - if(SHM->Buptime < SHM->Btouchtime) - reload_bcache(); - numboards = SHM->Bnumber; -} - -void touch_boards() { - time(&(SHM->Btouchtime)); - numboards = -1; - resolve_boards(); -} -void reset_board(int bid) -{ - int fd; - boardheader_t bh; - if(--bid<0)return; - if(SHM->Bbusystate==0) - { - SHM->Bbusystate = 1; - if((fd = open(fn_board, O_RDONLY)) > 0) { - lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); - read(fd, &bh , sizeof(boardheader_t)); - close(fd); - if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) - memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); - } - SHM->Bbusystate = 0; - } -} -boardheader_t *getbcache(int bid) { /* Ptt改寫 */ - return bcache + bid - 1; -} - -void touchbtotal(int bid) { - SHM->total[bid - 1] = 0; - SHM->lastposttime[bid - 1] = 0; -} - - -int getbnum(char *bname) { - register int i; - register boardheader_t *bhdr; - - for(i = 0, bhdr = bcache; i++ < numboards; bhdr++) - if( - !strcasecmp(bname, bhdr->brdname)) - return i; - return 0; -} - -/*-------------------------------------------------------*/ -/* PTT cache */ -/*-------------------------------------------------------*/ -/* cachefor 動態看版 */ -void reload_pttcache(void) -{ - if(SHM->Pbusystate) - safe_sleep(1); - else { /* jochang: temporary workaround */ - fileheader_t item, subitem; - char pbuf[256], buf[256], *chr; - FILE *fp, *fp1, *fp2; - int id, section = 0; - - SHM->Pbusystate = 1; - SHM->max_film = 0; - bzero(SHM->notes, sizeof SHM->notes); - setapath(pbuf, "Note"); - setadir(buf, pbuf); - id = 0; - if((fp = fopen(buf, "r"))) { - while(fread(&item, sizeof(item), 1, fp)) { - if(item.title[3]=='<' && item.title[8]=='>') { - sprintf(buf,"%s/%s", pbuf, item.filename); - setadir(buf, buf); - if(!(fp1 = fopen(buf, "r"))) - continue; - SHM->next_refresh[section] = SHM->n_notes[section] = id; - section ++; - while(fread(&subitem, sizeof(subitem), 1, fp1)) { - sprintf(buf,"%s/%s/%s", pbuf, item.filename , - subitem.filename); - if(!(fp2=fopen(buf,"r"))) - continue; - fread(SHM->notes[id],sizeof(char), 200*11, fp2); - SHM->notes[id][200*11 - 1]=0; - id++; - fclose(fp2); - if(id >= MAX_MOVIE) - break; - } - fclose(fp1); - if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) - break; - } - } - fclose(fp); - } - SHM->next_refresh[section] = -1; - SHM->n_notes[section] = SHM->max_film = id-1; - SHM->max_history = SHM->max_film - 2; - if(SHM->max_history > MAX_HISTORY - 1) - SHM->max_history = MAX_HISTORY - 1; - if(SHM->max_history <0) SHM->max_history=0; - - fp = fopen("etc/today_is","r"); - if(fp) { - fgets(SHM->today_is,15,fp); - if((chr = strchr(SHM->today_is,'\n'))) - *chr = 0; - SHM->today_is[15] = 0; - fclose(fp); - } - - /* 等所有資料更新後再設定 uptime */ - - SHM->Puptime = SHM->Ptouchtime ; - SHM->Pbusystate = 0; - } -} - -void resolve_garbage() { - int count=0; - - if(SHM == NULL) { - attach_SHM(); - if(SHM->Ptouchtime == 0) - SHM->Ptouchtime = 1; - } - while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ - reload_pttcache(); - if(count ++ > 10 && SHM->Pbusystate) { -/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 - 這樣會所有prcosee都會在load 動態看板 會造成load大增 - 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 - 解開 同樣的問題發生在reload passwd -*/ - SHM->Pbusystate = 0; - } - } -} - -/*-------------------------------------------------------*/ -/* PTT's cache */ -/*-------------------------------------------------------*/ -/* cachefor from host 與最多上線人數 */ -static void reload_fcache() { - if(SHM->Fbusystate) - safe_sleep(1); - else { - FILE *fp; - - SHM->Fbusystate = 1; - bzero(SHM->domain, sizeof SHM->domain); - if((fp = fopen("etc/domain_name_query","r"))) { - char buf[101],*po; - - SHM->top=0; - while(fgets(buf,100,fp)) { - if(buf[0] && buf[0] != '#' && buf[0] != ' ' && - buf[0] != '\n') { - sscanf(buf,"%s",SHM->domain[SHM->top]); - po = buf + strlen(SHM->domain[SHM->top]); - while(*po == ' ') - po++; - strncpy(SHM->replace[SHM->top],po,49); - SHM->replace[SHM->top] - [strlen(SHM->replace[SHM->top])-1] = 0; - (SHM->top)++; - } - } - } - - SHM->max_user=0; - - /* 等所有資料更新後再設定 uptime */ - SHM->Fuptime = SHM->Ftouchtime; - SHM->Fbusystate = 0; - } -} - -void resolve_fcache() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->Ftouchtime == 0) - SHM->Ftouchtime = 1; - } - while(SHM->Fuptime < SHM->Ftouchtime) - reload_fcache(); -} diff --git a/util/xchatd.c b/util/xchatd.c index 97cb33fe..b4aef8a6 100644 --- a/util/xchatd.c +++ b/util/xchatd.c @@ -1,4 +1,4 @@ -/* $Id: xchatd.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */ +/* $Id: xchatd.c,v 1.3 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #include "xchatd.h" @@ -158,25 +158,6 @@ acct_load(acct, userid) } } - -/* ----------------------------------------------------- */ -/* str_lower for check acct */ -/* ----------------------------------------------------- */ -void -str_lower(dst, src) - char *dst, *src; -{ - register int ch; - - do - { - ch = *src++; - if (ch >= 'A' && ch <= 'Z') - ch |= 0x20; - *dst++ = ch; - } while (ch); -} - /* * str_ncpy() - similar to strncpy(3) but terminates string always with '\0' * if n != 0, and doesn't do padding @@ -3121,6 +3102,7 @@ start_daemon() setsid(); + attach_SHM(); /* --------------------------------------------------- */ /* adjust the resource limit */ /* --------------------------------------------------- */ diff --git a/util/yearsold.c b/util/yearsold.c index 93cb4a1b..3229b709 100644 --- a/util/yearsold.c +++ b/util/yearsold.c @@ -1,4 +1,4 @@ -/* $Id: yearsold.c,v 1.4 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: yearsold.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ /* 站上年齡統計 */ #define _UTIL_C_ #include "bbs.h" @@ -23,7 +23,7 @@ char buf[], mode; } } -int main() +int main(int argc, char **argv) { int i, j, k; char buf[256]; @@ -37,6 +37,7 @@ int main() now = time(NULL); ptime = localtime(&now); + attach_SHM(); if(passwd_mmap()) exit(1); |