diff options
-rw-r--r-- | pttbbs/common/bbs/cache.c | 10 | ||||
-rw-r--r-- | pttbbs/include/cmbbs.h | 1 | ||||
-rw-r--r-- | pttbbs/mbbsd/bbs.c | 5 | ||||
-rw-r--r-- | pttbbs/mbbsd/board.c | 8 | ||||
-rw-r--r-- | pttbbs/mbbsd/cache.c | 2 | ||||
-rw-r--r-- | pttbbs/mbbsd/fav.c | 4 | ||||
-rw-r--r-- | pttbbs/mbbsd/mbbsd.c | 5 | ||||
-rw-r--r-- | pttbbs/mbbsd/user.c | 2 | ||||
-rw-r--r-- | pttbbs/mbbsd/var.c | 1 | ||||
-rw-r--r-- | pttbbs/mbbsd/vote.c | 3 | ||||
-rw-r--r-- | pttbbs/util/boardlist.c | 4 | ||||
-rw-r--r-- | pttbbs/util/buildAnnounce.c | 6 | ||||
-rw-r--r-- | pttbbs/util/inndBM.c | 3 | ||||
-rw-r--r-- | pttbbs/util/toplazyBM.c | 4 |
14 files changed, 35 insertions, 23 deletions
diff --git a/pttbbs/common/bbs/cache.c b/pttbbs/common/bbs/cache.c index ba300191..3ce422a9 100644 --- a/pttbbs/common/bbs/cache.c +++ b/pttbbs/common/bbs/cache.c @@ -136,7 +136,6 @@ attach_check_SHM(int version, int SHM_t_size) if (SHM->Btouchtime == 0) SHM->Btouchtime = 1; bcache = SHM->bcache; - numboards = SHM->Bnumber; if (SHM->Ptouchtime == 0) SHM->Ptouchtime = 1; @@ -508,14 +507,17 @@ void resolve_boards(void) while (SHM->Buptime < SHM->Btouchtime) { reload_bcache(); } - numboards = SHM->Bnumber; +} + +int num_boards(void) +{ + return SHM->Bnumber; } void addbrd_touchcache(void) { SHM->Bnumber++; - numboards = SHM->Bnumber; - reset_board(numboards); + reset_board(num_boards()); sort_bcache(); } diff --git a/pttbbs/include/cmbbs.h b/pttbbs/include/cmbbs.h index 08278cea..d0cd107d 100644 --- a/pttbbs/include/cmbbs.h +++ b/pttbbs/include/cmbbs.h @@ -66,6 +66,7 @@ extern void touchbtotal(int bid); extern void sort_bcache(void); extern void reload_bcache(void); extern void resolve_boards(void); +extern int num_boards(void); extern void addbrd_touchcache(void); extern void reset_board(int bid); extern void setbottomtotal(int bid); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index a328b0ac..c867b52e 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -793,6 +793,7 @@ whereami(void) boardheader_t *bh, *p[WHEREAMI_LEVEL]; int i, j; int bid = currbid; + int total_boards; if (!bid) return 0; @@ -802,7 +803,9 @@ whereami(void) assert(0<=bid-1 && bid-1<MAX_BOARD); bh = getbcache(bid); p[0] = bh; - for (i = 0; i+1 < WHEREAMI_LEVEL && p[i]->parent>1 && p[i]->parent < numboards; i++) + for (i = 0, total_boards = num_boards(); + i+1 < WHEREAMI_LEVEL && p[i]->parent>1 && p[i]->parent < total_boards; + i++) p[i + 1] = getbcache(p[i]->parent); j = i; prints("我在哪?\n%-40.40s %.13s\n", p[j]->title + 7, p[j]->BM); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 422334da..158907a6 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -838,11 +838,13 @@ load_uidofgid(const int gid, const int type) { boardheader_t *bptr, *currbptr, *parent; int bid, n, childcount = 0; + int boardcount; assert(0<=type && type<2); assert(0<= gid-1 && gid-1<MAX_BOARD); currbptr = parent = &bcache[gid - 1]; - assert(0<=numboards && numboards<=MAX_BOARD); - for (n = 0; n < numboards; ++n) { + boardcount = num_boards(); + assert(0<=boardcount && boardcount<=MAX_BOARD); + for (n = 0; n < boardcount; ++n) { bid = SHM->bsorted[type][n]+1; if( bid<=0 || !(bptr = getbcache(bid)) || bptr->brdname[0] == '\0' ) @@ -1016,7 +1018,7 @@ load_boards(char *key) } #endif else { // general case - nbrdsize = numboards; + nbrdsize = num_boards(); assert(0<nbrdsize && nbrdsize<=MAX_BOARD); nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * nbrdsize); for (i = 0; i < nbrdsize; i++) { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index bf10e577..e6d256b4 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -144,7 +144,7 @@ apply_boards(int (*func) (boardheader_t *)) register int i; register boardheader_t *bhdr; - for (i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + for (i = num_boards(), bhdr = bcache; i > 0; i--, bhdr++) { if (!(bhdr->brdattr & BRD_GROUPBOARD) && HasBoardPerm(bhdr) && (*func) (bhdr) == QUIT) return QUIT; diff --git a/pttbbs/mbbsd/fav.c b/pttbbs/mbbsd/fav.c index 318501fc..fc976d9e 100644 --- a/pttbbs/mbbsd/fav.c +++ b/pttbbs/mbbsd/fav.c @@ -1146,8 +1146,8 @@ int updatenewfav(int mode) if( (fd = OpenCreate(fname, O_RDWR)) != -1 ){ - assert(numboards>=0); - brdnum = numboards; /* avoid race */ + brdnum = num_boards(); /* avoid race */ + assert(brdnum >= 0); if ((brd = (char *)malloc((brdnum + 1) * sizeof(char))) == NULL) return -1; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index ab1e840f..1d6347bb 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -982,10 +982,10 @@ where(const char *from) static void check_BM(void) { - int i; + int i, total; assert(HasUserPerm(PERM_BM)); - for( i = 0 ; i < numboards ; ++i ) + for( i = 0, total = num_boards() ; i < total ; ++i ) if( is_BM_cache(i + 1) ) /* XXXbid */ return; @@ -1174,7 +1174,6 @@ user_login(void) * 否則可藉機 race condition 達到 multi-login */ /* resolve_boards(); */ - numboards = SHM->Bnumber; /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 90d725f0..3c074116 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -226,7 +226,7 @@ user_display(const userec_t * u, int adminmode) outs("\t擔任板主: "); - for (i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + for (i = num_boards(), bhdr = bcache; i > 0; i--, bhdr++) { if ( is_uBM(bhdr->BM, u->userid)) { outs(bhdr->brdname); outc(' '); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index d5f24d4f..bcbcae71 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -365,7 +365,6 @@ int wmofo = NOTREPLYING; /* cache.c */ -int numboards = -1; SHM_t *SHM; boardheader_t *bcache; userinfo_t *currutmp; diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index b8cb44e6..0be205e3 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -321,6 +321,7 @@ b_closepolls(void) { boardheader_t *fhp; int pos; + int total; #ifndef BARRIER_HAS_BEEN_IN_SHM char *fn_vote_polling = ".polling"; @@ -341,7 +342,7 @@ b_closepolls(void) fclose(cfp); #endif - for (fhp = bcache, pos = 1; pos <= numboards; fhp++, pos++) { + for (fhp = bcache, pos = 1, total = num_boards(); pos <= total; fhp++, pos++) { if (fhp->bvote && b_close(fhp)) { if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); diff --git a/pttbbs/util/boardlist.c b/pttbbs/util/boardlist.c index 35956a8e..1e858af3 100644 --- a/pttbbs/util/boardlist.c +++ b/pttbbs/util/boardlist.c @@ -21,8 +21,10 @@ load_uidofgid(const int gid, const int type) { boardheader_t *bptr, *currbptr, *parent; int bid, n, childcount = 0; + int boardcount; currbptr = parent = &bcache[gid - 1]; - for (n = 0; n < numboards; ++n) { + boardcount = num_boards(); + for (n = 0; n < boardcount; ++n) { bid = SHM->bsorted[type][n]+1; if( bid<=0 || !(bptr = &bcache[bid-1]) || bptr->brdname[0] == '\0' ) diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index e9aa3298..cb70664c 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -4,7 +4,6 @@ #define GROUPROOT BBSHOME"/man/group" extern boardheader_t *bcache; -extern int numboards; int cmpboardclass(const void *a, const void *b) { @@ -23,8 +22,9 @@ void buildchilds(int level,char *path,int gid) int preserved=32; selected=malloc(preserved * sizeof(boardheader_t*)); - /* XXX It will cost O(ngroup * numboards) totally. */ - for(i=0; i<numboards; i++) { + int boardcount = num_boards(); + /* XXX It will cost O(ngroup * boardcount) totally. */ + for(i=0; i<boardcount; i++) { ptr =&SHM->bcache[i]; if(ptr->gid != gid) continue; diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 535608b3..33e1f4d6 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -171,7 +171,8 @@ int main(int argc, char **argv) } // 重設轉信與不轉信板標記 - for(i=0;i<numboards;i++) + int total = num_boards(); + for(i=0;i<total;i++) { if(bcache[i].brdname[0]=='\0' || (bcache[i].brdattr & BRD_GROUPBOARD) ) continue; diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 0b712779..129182ac 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -4,7 +4,6 @@ #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" extern boardheader_t *bcache; -extern int numboards; #ifndef LAZY_BM_LIMIT_DAYS #define LAZY_BM_LIMIT_DAYS (90) @@ -77,9 +76,12 @@ int main(int argc, char *argv[]) { int bmid, i, j=0; FILE *inf, *firef; + int numboards; + time4_t now=time(NULL); attach_SHM(); resolve_boards(); + numboards = num_boards(); if(passwd_init()) exit(1); |