diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-07-20 08:55:34 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-07-20 08:55:34 +0800 |
commit | 24ec3204b34c9e6749b9312f2edb84edb2a4cb34 (patch) | |
tree | 4c4bc5443344d91ab20163b0ed491732d2a732ed | |
parent | 047bb28fce410663731f69295cff89ab902a6085 (diff) | |
download | pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.tar pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.tar.gz pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.tar.bz2 pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.tar.lz pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.tar.xz pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.tar.zst pttbbs-24ec3204b34c9e6749b9312f2edb84edb2a4cb34.zip |
merge from MergeCache
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1065 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
44 files changed, 406 insertions, 884 deletions
diff --git a/include/proto.h b/include/proto.h index f02f7c1d..ee59329d 100644 --- a/include/proto.h +++ b/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.45 2003/07/17 03:27:27 victor Exp $ */ +/* $Id: proto.h,v 1.46 2003/07/20 00:55:34 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -130,7 +130,10 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, int recbase, int nlines); void *attach_shm(int shmkey, int shmsize); void attach_SHM(void); -void sort_utmp(); +void sort_utmp(void); +int is_BM_cache(int); +void buildBMcache(int); +void reload_bcache(void); /* cal */ int give_tax(int money); diff --git a/include/pttstruct.h b/include/pttstruct.h index d34e8f3a..2401c26b 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.42 2003/07/17 03:27:27 victor Exp $ */ +/* $Id: pttstruct.h,v 1.43 2003/07/20 00:55:34 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -102,7 +102,7 @@ typedef struct userec_t { typedef struct boardheader_t { char brdname[IDLEN + 1]; /* bid */ char title[BTLEN + 1]; - char BM[IDLEN * 3 + 3]; /* BMs' uid, token '/' */ + char BM[IDLEN * 3 + 3]; /* BMs' userid, token '/' */ unsigned int brdattr; /* board的屬性 */ char pad[3]; /* 沒用到的 */ time_t bupdate; /* note update time */ @@ -298,6 +298,9 @@ typedef struct keeploc_t { #define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ +/* MAX_BMs is dirty hardcode 4 in mbbsd/cache.c:is_BM_cache() */ +#define MAX_BMs 4 /* for BMcache, 一個看板最多幾板主 */ + typedef struct { /* uhash */ char userid[MAX_USERS][IDLEN + 1]; @@ -319,7 +322,7 @@ typedef struct { char UTMPbusystate; /* brdshm */ - int BMcache[MAX_BOARD][4]; + int BMcache[MAX_BOARD][MAX_BMs]; boardheader_t bcache[MAX_BOARD]; boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; diff --git a/innbbsd/Makefile b/innbbsd/Makefile index 56c91213..5fa6c566 100644 --- a/innbbsd/Makefile +++ b/innbbsd/Makefile @@ -24,7 +24,7 @@ OPT= -O -s -pipe -fomit-frame-pointer BBS_DEP = MapleBBS BBS_UTIL = $(BBS_SRC)/util -BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_passwd.o +BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_passwd.o $(BBS_UTIL)/util_stuff.o $(BBS_UTIL)/util_var.o ######################### # diff --git a/innbbsd/antisplam.h b/innbbsd/antisplam.h index 30289da1..f72f5348 100644 --- a/innbbsd/antisplam.h +++ b/innbbsd/antisplam.h @@ -1,18 +1,5 @@ #define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) -/*void -str_lower(t, s) - char *t, *s;*/ -void str_lower(char *t, char *s) -{ - register char ch; - do - { - ch = *s++; - *t++ = char_lower(ch); - } while (ch); -} - #if 0 /* string.h , libc */ int strcasestr(str, tag) diff --git a/innbbsd/inndchannel.c b/innbbsd/inndchannel.c index 439b2af0..b784bde4 100644 --- a/innbbsd/inndchannel.c +++ b/innbbsd/inndchannel.c @@ -578,6 +578,7 @@ woju setgid(BBSGID); setuid(BBSUID); chdir(BBSHOME); + attach_SHM(); resolve_boards(); port = DefaultINNBBSPort; diff --git a/innbbsd/str_decode.c b/innbbsd/str_decode.c index 23a10551..73ad5f64 100644 --- a/innbbsd/str_decode.c +++ b/innbbsd/str_decode.c @@ -164,7 +164,7 @@ int str_iconv( /* Start translation */ while (srclen > 0 && dstlen > 0) { - iconv_ret = iconv(iconv_descriptor, &src, &srclen, + iconv_ret = iconv(iconv_descriptor, (const char* *)&src, &srclen, &dst, &dstlen); if (iconv_ret != 0) { diff --git a/mbbsd/Makefile b/mbbsd/Makefile index 7d16b04f..5762a2d7 100644 --- a/mbbsd/Makefile +++ b/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.28 2003/07/06 03:41:08 in2 Exp $ +# $Id: Makefile,v 1.29 2003/07/20 00:55:34 in2 Exp $ .include "../pttbbs.mk" @@ -14,8 +14,7 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ - voteboard.o syspost.o var.o toolkit.o passwd.o\ - calendar.o + voteboard.o syspost.o var.o passwd.o calendar.o .SUFFIXES: .c .o .c.o: ../include/var.h diff --git a/mbbsd/announce.c b/mbbsd/announce.c index f0db7535..92b89d7f 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.30 2003/07/06 03:41:08 in2 Exp $ */ +/* $Id: announce.c,v 1.31 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define PATHLEN 256 @@ -863,7 +863,8 @@ a_menu(char *maintitle, char *path, int lastlevel) 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b 須等該資料寫入 .DIR 內再 implement才有效率. */ - if( !lastlevel && !HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SYSSUBOP) && !is_BM(bcache[currbid - 1].BM) && + if( !lastlevel && !HAS_PERM(PERM_SYSOP) && + !HAS_PERM(PERM_SYSSUBOP) && is_BM_cache(currbid) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else @@ -961,7 +962,7 @@ a_menu(char *maintitle, char *path, int lastlevel) #ifdef BLOG case 'b': - if( !HAS_PERM(SYSOP) && !is_BM(bcache[currbid - 1].BM) ) + if( !HAS_PERM(PERM_SYSOP) && !is_BM_cache(currbid) ) vmsg("只有板主才可以用唷!"); else{ char genbuf[128]; @@ -974,7 +975,7 @@ a_menu(char *maintitle, char *path, int lastlevel) break; case 'B': - if( !HAS_PERM(SYSOP) && !is_BM(bcache[currbid - 1].BM) ) + if( !HAS_PERM(SYSOP) && !is_BM_cache(currbid) ) vmsg("只有板主才可以用唷!"); else BlogMain(me.now); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index a113b03d..3aaae9c2 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.103 2003/07/06 23:09:25 kcwu Exp $ */ +/* $Id: bbs.c,v 1.104 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -121,7 +121,7 @@ set_board() bp->title + 7); currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED; - if (HAS_PERM(PERM_ALLBOARD) || is_BM(bp->BM)) + if (HAS_PERM(PERM_ALLBOARD) || is_BM_cache(currbid)) currmode = currmode | MODE_BOARD | MODE_POST; else if (haspostperm(currboard)) currmode |= MODE_POST; @@ -1466,6 +1466,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) if (!not_owned && strcmp(currboard, "Test")) { if (cuser.numposts) cuser.numposts--; + /* XXX: is_BM(cuser.userid) is always true @_@ */ if (!(currmode & MODE_DIGEST && is_BM(cuser.userid))){ move(b_lines - 1, 0); clrtoeol(); diff --git a/mbbsd/board.c b/mbbsd/board.c index 415dabe1..7351d1e9 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.132 2003/07/03 03:37:39 victor Exp $ */ +/* $Id: board.c,v 1.133 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -575,7 +575,6 @@ int Ben_Perm(boardheader_t * bptr) { register int level, brdattr; - register char *ptr; level = bptr->level; brdattr = bptr->brdattr; @@ -583,8 +582,7 @@ Ben_Perm(boardheader_t * bptr) if (HAS_PERM(PERM_SYSOP)) return 1; - ptr = bptr->BM; - if (is_BM(ptr)) + if( is_BM_cache(bptr - bcache + 1) ) /* XXXbid */ return 1; /* 祕密看板:核對首席板主的好友名單 */ @@ -688,6 +686,7 @@ load_uidofgid(const int gid, const int type) else currbptr->next[type] = (boardheader_t *) ~ 0; } + static boardstat_t * addnewbrdstat(int n, int state) { diff --git a/mbbsd/cache.c b/mbbsd/cache.c index fb7baca8..ad2d7a7d 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -1,15 +1,10 @@ -/* $Id: cache.c,v 1.62 2003/06/07 14:19:12 kcwu Exp $ */ +/* $Id: cache.c,v 1.63 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" -#ifndef __FreeBSD__ -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 */ -}; +#ifdef _BBS_UTIL_C_ +# define log_usies(a, b) ; +# define abort_bbs(a) exit(1) #endif - /* * 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, @@ -25,9 +20,7 @@ safe_sleep(unsigned int seconds) sigprocmask(SIG_BLOCK, &set, &oldset); if (sigismember(&oldset, SIGALRM)) { unsigned long retv; -#if !defined(_BBS_UTIL_C_) log_usies("SAFE_SLEEP ", "avoid hang"); -#endif sigemptyset(&set); sigaddset(&set, SIGALRM); sigprocmask(SIG_UNBLOCK, &set, NULL); @@ -38,22 +31,9 @@ safe_sleep(unsigned int seconds) return sleep(seconds); } -#if defined(_BBS_UTIL_C_) -static void -setapath(char *buf, char *boardname) -{ - snprintf(buf, "man/boards/%c/%s", boardname[0], boardname); -} - -static char *str_dotdir = ".DIR"; - -static void -setadir(char *buf, char *path) -{ - sprintf(buf, "%s/%s", path, str_dotdir); -} -#endif - +/* + * section - SHM + */ static void attach_err(int shmkey, char *name) { @@ -70,7 +50,7 @@ attach_shm(int shmkey, int shmsize) shmid = shmget(shmkey, shmsize, 0); if (shmid < 0) { - // SHM should be created by uhash_loader, NOT mbbsd. + // SHM should be created by uhash_loader, NOT mbbsd or other utils attach_err(shmkey, "shmget"); } else { shmptr = (void *)shmat(shmid, NULL, 0); @@ -81,12 +61,40 @@ attach_shm(int shmkey, int shmsize) return shmptr; } +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; -#define SEM_FLG 0600 /* semaphore mode */ + GLOBALVAR = SHM->GLOBALVAR; + if (SHM->Ptouchtime == 0) + SHM->Ptouchtime = 1; + + if (SHM->Ftouchtime == 0) + SHM->Ftouchtime = 1; +} /* ----------------------------------------------------- */ /* semaphore : for critical section */ /* ----------------------------------------------------- */ +#define SEM_FLG 0600 /* semaphore mode */ + +#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 + void sem_init(int semkey, int *semid) { @@ -116,6 +124,9 @@ sem_lock(int op, int semid) } } +/* + * section - user cache(including uhash) + */ /* uhash ****************************************** */ /* * the design is this: we use another stand-alone program to create and load @@ -127,27 +138,6 @@ sem_lock(int op, int semid) * loaded yet. */ -/* attach_uhash should be called before using uhash */ - -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; -} - void add_to_uhash(int n, char *id) { @@ -166,13 +156,13 @@ add_to_uhash(int n, char *id) SHM->next_in_hash[*p = n] = -1; } +void +remove_from_uhash(int n) +{ /* * note: after remove_from_uhash(), you should add_to_uhash() (likely with a * different name) */ -void -remove_from_uhash(int n) -{ int h = StringHash(SHM->userid[n]); int *p = &(SHM->hash_head[h]); int times; @@ -188,32 +178,6 @@ remove_from_uhash(int n) } 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 -demoney(int money) -{ - return deumoney(usernum, money); -} -int -moneyof(int uid) -{ /* ptt 改進金錢處理效率 */ - return SHM->money[uid - 1]; -} -int searchuser(char *userid) { int h, p, times; @@ -231,8 +195,6 @@ searchuser(char *userid) return 0; } -#if !defined(_BBS_UTIL_C_) - int getuser(char *userid) { @@ -284,6 +246,7 @@ searchnewuser(int mode) return 0; } +#ifndef _BBS_UTIL_C_ char * u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { @@ -315,30 +278,10 @@ u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) } #endif -/*-------------------------------------------------------*/ -/* .UTMP cache */ -/*-------------------------------------------------------*/ -#if !defined(_BBS_UTIL_C_) -void -setutmpmode(unsigned int mode) -{ - if (currstat != mode) - currutmp->mode = currstat = mode; - - /* 追蹤使用者 */ - if (HAS_PERM(PERM_LOGUSER)) { - char msg[200]; - snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", - cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); - log_user(msg); - } -} -#endif - -/* Ptt:這裡加上 hash 觀念找空的 utmp */ void getnewutmpent(userinfo_t * up) { +/* Ptt:這裡加上 hash 觀念找空的 utmp */ register int i, p; register userinfo_t *uentp; for (i = 0, p = StringHash(up->userid) % USHM_SIZE; i < USHM_SIZE; i++, p++) { @@ -375,7 +318,6 @@ search_ulist(int uid) return search_ulistn(uid, 1); } -#if !defined(_BBS_UTIL_C_) userinfo_t * search_ulist_pid(int pid) { @@ -401,6 +343,7 @@ search_ulist_pid(int pid) } return 0; } + userinfo_t * search_ulistn(int uid, int unum) { @@ -432,6 +375,7 @@ search_ulistn(int uid, int unum) } return 0; } + userinfo_t * search_ulist_userid(char *userid) { @@ -458,6 +402,7 @@ search_ulist_userid(char *userid) return 0; } +#ifndef _BBS_UTIL_C_ int count_logins(int uid, int show) { @@ -491,7 +436,6 @@ count_logins(int uid, int show) return 0; } - void purge_utmp(userinfo_t * uentp) { @@ -499,12 +443,68 @@ purge_utmp(userinfo_t * uentp) memset(uentp, 0, sizeof(userinfo_t)); SHM->UTMPneedsort = 1; } +#endif + +/* + * section - money cache + */ +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 +demoney(int money) +{ + return deumoney(usernum, money); +} + +int +moneyof(int uid) +{ /* ptt 改進金錢處理效率 */ + return SHM->money[uid - 1]; +} + +/* + * section - utmp + */ +#if !defined(_BBS_UTIL_C_) /* _BBS_UTIL_C_ 不會有 utmp */ +void +setutmpmode(unsigned int mode) +{ + if (currstat != mode) + currutmp->mode = currstat = mode; + /* 追蹤使用者 */ + if (HAS_PERM(PERM_LOGUSER)) { + char msg[200]; + snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", + cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); + log_user(msg); + } +} #endif -/*-------------------------------------------------------*/ -/* .BOARDS cache */ -/*-------------------------------------------------------*/ +/* + * section - board cache + */ +void touchbtotal(int bid) { + SHM->total[bid - 1] = 0; + SHM->lastposttime[bid - 1] = 0; +} + void touchdircache(int bid) { @@ -552,19 +552,22 @@ get_fileheader_cache(int bid, char *direct, fileheader_t * headers, memcpy(headers, &(SHM->dircache[bid - 1][n]), sizeof(fileheader_t) * ret); return ret; } + 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() +sort_bcache(void) { int i; /* critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ @@ -576,13 +579,13 @@ sort_bcache() qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST) cmpboardclass); } -static void -reload_bcache() + +void +reload_bcache(void) { if (SHM->Bbusystate) { safe_sleep(1); } -#if !defined(_BBS_UTIL_C_) else { int fd, i; @@ -604,11 +607,9 @@ reload_bcache() } SHM->Bbusystate = 0; } -#endif } -void -resolve_boards() +void resolve_boards(void) { while (SHM->Buptime < SHM->Btouchtime) { reload_bcache(); @@ -616,35 +617,32 @@ resolve_boards() numboards = SHM->Bnumber; } -void -touch_boards() +void touch_boards(void) { SHM->Btouchtime = now; numboards = -1; resolve_boards(); } -void -addbrd_touchcache() +void addbrd_touchcache(void) { SHM->Bnumber++; numboards = SHM->Bnumber; reset_board(numboards); } -#if !defined(_BBS_UTIL_C_) + void -reset_board(int bid) +reset_board(int bid) /* XXXbid: from 1 */ { /* Ptt: 這樣就不用老是touch board了 */ int fd, i, nuser; boardheader_t *bhdr; - if (--bid < 0) return; - if (SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10) { + if (SHM->Bbusystate || now - SHM->busystate_b[bid] < 10) { safe_sleep(1); } else { - SHM->busystate_b[bid - 1] = now; - nuser = bcache[bid - 1].nuser; + SHM->busystate_b[bid] = now; + nuser = bcache[bid].nuser; bhdr = bcache; bhdr += bid; @@ -658,11 +656,13 @@ reset_board(int bid) bcache[i].firstchild[0] = NULL; bcache[i].firstchild[1] = NULL; } - nuser = bcache[bid - 1].nuser; - SHM->busystate_b[bid - 1] = 0; + SHM->busystate_b[bid] = 0; + + buildBMcache(bid + 1); /* XXXbid */ } } +#ifndef _BBS_UTIL_C_ /* because of Ben_Perm() in board.c */ int apply_boards(int (*func) (boardheader_t *)) { @@ -683,11 +683,13 @@ getbcache(int bid) { /* Ptt改寫 */ return bcache + bid - 1; } + int getbtotal(int bid) { return SHM->total[bid - 1]; } + void setbtotal(int bid) { @@ -725,7 +727,6 @@ touchbpostnum(int bid, int delta) *total += delta; } - int getbnum(char *bname) { @@ -748,7 +749,6 @@ getbnum(char *bname) return 0; } -#if !defined(_BBS_UTIL_C_) int haspostperm(char *bname) { @@ -784,14 +784,46 @@ haspostperm(char *bname) return HAS_PERM(i & ~PERM_POST); } -#endif + +void buildBMcache(int bid) /* bid starts from 1 */ +{ + char s[IDLEN * 3 + 3], *ptr; + int i, uid; + --bid; + + strncpy(s, bcache[bid].BM, sizeof(s)); + for( i = 0 ; s[i] != 0 ; ++i ) + if( !isalpha(s[i]) && !isdigit(s[i]) ) + s[i] = ' '; + + for( ptr = strtok(s, " "), i = 0 ; + i < MAX_BMs && ptr != NULL ; + ptr = strtok(NULL, " "), ++i ) + if( (uid = searchuser(ptr)) != 0 ) + SHM->BMcache[bid][i] = uid; + for( ; i < MAX_BMs ; ++i ) + SHM->BMcache[bid][i] = -1; +} + +int is_BM_cache(int bid) /* bid starts from 1 */ +{ + --bid; + if( currutmp->uid == SHM->BMcache[bid][0] || + currutmp->uid == SHM->BMcache[bid][1] || + currutmp->uid == SHM->BMcache[bid][2] || + currutmp->uid == SHM->BMcache[bid][3] ){ + cuser.userlevel |= PERM_BM; + return 1; + } + return 0; +} /*-------------------------------------------------------*/ /* PTT cache */ /*-------------------------------------------------------*/ -/* cachefor 動態看板 */ +/* cache for 動態看板 */ void -reload_pttcache() +reload_pttcache(void) { if (SHM->Pbusystate) safe_sleep(1); @@ -855,15 +887,13 @@ reload_pttcache() /* 等所有資料更新後再設定 uptime */ SHM->Puptime = SHM->Ptouchtime; -#if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload pttcache"); -#endif SHM->Pbusystate = 0; } } void -resolve_garbage() +resolve_garbage(void) { int count = 0; @@ -887,9 +917,9 @@ resolve_garbage() /*-------------------------------------------------------*/ /* PTT's cache */ /*-------------------------------------------------------*/ -/* cachefor from host 與最多上線人數 */ +/* cache for from host 與最多上線人數 */ static void -reload_fcache() +reload_fcache(void) { if (SHM->Fbusystate) safe_sleep(1); @@ -931,12 +961,15 @@ reload_fcache() } void -resolve_fcache() +resolve_fcache(void) { while (SHM->Fuptime < SHM->Ftouchtime) reload_fcache(); } +/* + * section - hbfl (hidden board friend list) + */ void hbflreload(int bid) { diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 70549fbe..ff434498 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.27 2003/05/19 07:10:19 in2 Exp $ */ +/* $Id: mail.c,v 1.28 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1230,7 +1230,7 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) char title[TTLEN + 1]; static char xboard[20]; char buf[20]; - boardheader_t *bp; + int bid; setuserfile(fpath, fhdr->filename); strlcpy(title, "◇ ", sizeof(title)); @@ -1253,11 +1253,11 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) completeboard_getname); if (*buf) strlcpy(xboard, buf, sizeof(xboard)); - if (*xboard && (bp = getbcache(getbnum(xboard)))) { + if (*xboard && ((bid = getbnum(xboard)) >= 0)){ /* XXXbid */ setapath(fpath, xboard); setutmpmode(ANNOUNCE); a_menu(xboard, fpath, HAS_PERM(PERM_ALLBOARD) ? 2 : - is_BM(bp->BM) ? 1 : 0); + is_BM_cache(bid) ? 1 : 0); } else { mail_man(); } diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index da5c6c94..4220f9b0 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.89 2003/07/17 00:57:21 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.90 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -162,7 +162,7 @@ u_exit(char *mode) //userec_t xuser; int diff = (time(0) - login_start_time) / 60; - /* close fd 0 & a to terminate network */ + /* close fd 0 & 1 to terminate network */ close(0); close(1); @@ -697,13 +697,16 @@ where(char *from) #endif static void -check_BM() +check_BM(void) { + /* XXX: -_- */ int i; - boardheader_t *bhdr; cuser.userlevel &= ~PERM_BM; - for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); + for( i = 0 ; i < numboards ; ++i ) + if( is_BM_cache(i + 1) ) /* XXXbid */ + return; + //for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); } static void @@ -715,8 +718,6 @@ setup_utmp(int mode) uinfo.uid = usernum; uinfo.mode = currstat = mode; uinfo.mailalert = load_mailalert(cuser.userid); - if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) - check_BM(); /* Ptt 自動取下離職板主權力 */ uinfo.userlevel = cuser.userlevel; uinfo.sex = cuser.sex % 8; @@ -749,6 +750,8 @@ setup_utmp(int mode) uinfo.invisible = YEA; getnewutmpent(&uinfo); SHM->UTMPneedsort = 1; + if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) + check_BM(); /* Ptt 自動取下離職板主權力 */ #ifndef _BBS_UTIL_C_ friend_load(); nice(3); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index a254b42c..80428954 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.12 2003/06/28 08:47:45 kcwu Exp $ */ +/* $Id: stuff.c,v 1.13 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -336,6 +336,7 @@ belong(char *filelist, char *key) return rc; } +#ifndef _BBS_UTIL_C_ /* getdata_buf */ time_t gettime(int line, time_t dt) { @@ -361,6 +362,8 @@ gettime(int line, time_t dt) } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); return mktime(&endtime); } +#endif + char * Cdate(time_t * clock) { @@ -391,6 +394,8 @@ Cdatedate(time_t * clock) return foo; } +#ifndef _BBS_UTIL_C_ +/* 這一區都是有關於畫面處理的, 故 _BBS_UTIL_C_ 不須要 */ static void capture_screen() { @@ -619,6 +624,7 @@ show_help(char *helptext[]) } pressanykey(); } +#endif // _BBS_UTIL_C_ /* ----------------------------------------------------- */ /* use mmap() to malloc large memory in CRITICAL_MEMORY */ @@ -629,7 +635,7 @@ void *MALLOC(int size) int *p; p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); p[0] = size; -#ifdef DEBUG +#if defined(DEBUG) && !defined(_BBS_UTIL_C_) vmsg("critical malloc %d bytes", size); #endif return (void *)&p[1]; @@ -639,8 +645,19 @@ void FREE(void *ptr) { int size = ((int *)ptr)[-1]; munmap((void *)(&(((int *)ptr)[-1])), size); -#ifdef DEBUG +#if defined(DEBUG) && !defined(_BBS_UTIL_C_) vmsg("critical free %d bytes", size); #endif } #endif + +unsigned +StringHash(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); +} diff --git a/mbbsd/toolkit.c b/mbbsd/toolkit.c deleted file mode 100644 index 99f80e0b..00000000 --- a/mbbsd/toolkit.c +++ /dev/null @@ -1,13 +0,0 @@ -/* $Id: toolkit.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ -#include "bbs.h" - -unsigned -StringHash(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); -} diff --git a/mbbsd/var.c b/mbbsd/var.c index 59e40eb4..4ba3cf9e 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.20 2003/07/06 23:09:25 kcwu Exp $ */ +/* $Id: var.c,v 1.21 2003/07/20 00:55:34 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -591,6 +591,7 @@ unsigned char *adv_gomoku /* [978] */ = /* name.c */ word_t *toplev; +#ifndef _BBS_UTIL_C_ /* menu.c */ commands_t cmdlist[] = { {admin, PERM_SYSOP | PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, @@ -606,6 +607,7 @@ commands_t cmdlist[] = { {Goodbye, 0, "GGoodbye 離開,再見……"}, {NULL, 0, NULL} }; +#endif /* friend.c */ /* Ptt 各種特別名單的檔名 */ diff --git a/sample/pttbbs.sh b/sample/pttbbs.sh index 9e1efc26..d5588b8a 100755 --- a/sample/pttbbs.sh +++ b/sample/pttbbs.sh @@ -4,8 +4,8 @@ case "$1" in start) - # 初始化 shared-memory, 載入使用者帳號 - /usr/bin/su -fm bbs -c /home/bbs/bin/uhash_loader + # 初始化 shared-memory, 載入 uhash, utmpsortd, timed(if necessary) + /usr/bin/su -fm bbs -c /home/bbs/bin/shmctl init # 寄信至站外 /usr/bin/su -fm bbs -c /home/bbs/bin/outmail & @@ -16,9 +16,6 @@ start) # 啟動 port 23 (port 23須使用 root 才能進行 bind ) /home/bbs/bin/mbbsd 23 & - # 啟動 utmpsortd - /bin/sleep 5; "/usr/bin/su -fm bbs -c /home/bbs/bin/shmctl utmpsortd" & - # 提示 echo -n ' mbbsd' ;; diff --git a/sample/rc.local b/sample/rc.local index 96d2cb00..4da3d8d5 100644 --- a/sample/rc.local +++ b/sample/rc.local @@ -1,5 +1,5 @@ #!/bin/sh -/usr/bin/su bbsadm -c /home/bbs/bin/uhash_loader +/usr/bin/su bbsadm -c /home/bbs/bin/shmctl init /usr/bin/su bbsadm -c /home/bbs/bin/outmail& /usr/bin/su bbsadm -c /home/bbs/innd/innbbsd 7777 /home/bbs/bin/mbbsd 23 & @@ -14,7 +14,3 @@ /home/bbs/bin/mbbsd 3008 & /home/bbs/bin/mbbsd 3009 & /home/bbs/bin/mbbsd 3010 & -/usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl utmpsortd" - -# 若您在 pttbbs.conf 中有開 OUTTA_TIMER 的話, 則須跑下面這行 -# /usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl timed" 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); |