diff options
author | ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-11-17 11:35:31 +0800 |
---|---|---|
committer | ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-11-17 11:35:31 +0800 |
commit | 000083cc87916be528e889208126e700918c313e (patch) | |
tree | 2c0dacc861e0700fb3cc1705080f282117ab21eb | |
parent | 86dbcf633bd13c10081ee3414c136c299a4c7e13 (diff) | |
download | pttbbs-000083cc87916be528e889208126e700918c313e.tar pttbbs-000083cc87916be528e889208126e700918c313e.tar.gz pttbbs-000083cc87916be528e889208126e700918c313e.tar.bz2 pttbbs-000083cc87916be528e889208126e700918c313e.tar.lz pttbbs-000083cc87916be528e889208126e700918c313e.tar.xz pttbbs-000083cc87916be528e889208126e700918c313e.tar.zst pttbbs-000083cc87916be528e889208126e700918c313e.zip |
rewrite SHM->HBcache sorted bsorted as offset value.
git-svn-id: http://opensvn.csie.org/pttbbs/branches/ptt.linux@2334 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/pttstruct.h | 6 | ||||
-rw-r--r-- | mbbsd/board.c | 10 | ||||
-rw-r--r-- | mbbsd/cache.c | 70 | ||||
-rw-r--r-- | mbbsd/name.c | 16 | ||||
-rw-r--r-- | mbbsd/talk.c | 34 | ||||
-rw-r--r-- | util/boardlist.c | 4 | ||||
-rw-r--r-- | util/shmctl.c | 82 |
7 files changed, 123 insertions, 99 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h index 6689e851..34917ec7 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -413,7 +413,7 @@ typedef struct { /* utmpshm */ userinfo_t uinfo[USHM_SIZE]; - userinfo_t *sorted[2][8][USHM_SIZE]; + int sorted[2][8][USHM_SIZE]; /* 第一維double buffer 由currsorted指向目前使用的 第二維sort type */ int currsorted; @@ -425,10 +425,10 @@ typedef struct { /* brdshm */ int BMcache[MAX_BOARD][MAX_BMs]; boardheader_t bcache[MAX_BOARD]; - boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + int bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ #if HOTBOARDCACHE unsigned char nHOTs; - boardheader_t *HBcache[HOTBOARDCACHE]; + int HBcache[HOTBOARDCACHE]; #endif time_t busystate_b[MAX_BOARD]; int total[MAX_BOARD]; diff --git a/mbbsd/board.c b/mbbsd/board.c index 61d369c8..954c7d8f 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -131,7 +131,8 @@ load_uidofgid(const int gid, const int type) int n, childcount = 0; currbptr = &bcache[gid - 1]; for (n = 0; n < numboards; ++n) { - if( !(bptr = SHM->bsorted[type][n]) || bptr->brdname[0] == '\0' ) + if( !(bptr = &bcache[SHM->bsorted[type][n]]) + || bptr->brdname[0] == '\0' ) continue; if (bptr->gid == gid) { if (currbptr == &bcache[gid - 1]) @@ -259,14 +260,15 @@ load_boards(char *key) else if( class_bid == -1 ){ nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * SHM->nHOTs); for( i = 0 ; i < SHM->nHOTs ; ++i ) - addnewbrdstat(SHM->HBcache[i] - SHM->bcache, - HasPerm(SHM->HBcache[i])); + if(SHM->HBcache[i]==-1) continue; + addnewbrdstat(SHM->HBcache[i], + HasPerm(bcache[SHM->HBcache[i]])); } #endif else { // general case nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { - if ((bptr = SHM->bsorted[type][i]) == NULL) + if ((bptr = &bcache[SHM->bsorted[type][i]]) == NULL) continue; n = getbid(bptr); if (!bptr->brdname[0] || diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 32cc4a95..c66a5b5b 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -318,14 +318,16 @@ userinfo_t * search_ulist_pid(int pid) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; - register userinfo_t **ulist; + int *ulist; + register userinfo_t *u; if (end == -1) return NULL; ulist = SHM->sorted[SHM->currsorted][7]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - j = pid - ulist[i]->pid; + u = &SHM->uinfo[ulist[i]]; + j = pid - u->pid; if (!j) { - return (userinfo_t *) (ulist[i]); + return u; } if (end == start) { break; @@ -344,19 +346,21 @@ userinfo_t * search_ulistn(int uid, int unum) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; - register userinfo_t **ulist; + int *ulist; + register userinfo_t *u; if (end == -1) return NULL; ulist = SHM->sorted[SHM->currsorted][6]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - j = uid - ulist[i]->uid; + u = &SHM->uinfo[ulist[i]]; + j = uid - u->uid; if (j == 0) { - for (; i > 0 && uid == ulist[i - 1]->uid; --i) + for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; --i) ;/* 指到第一筆 */ if ( i + unum - 1 >= 0 && - (ulist[i + unum - 1] != NULL && - uid == ulist[i + unum - 1]->uid) ) - return (userinfo_t *) (ulist[i + unum - 1]); + (ulist[i + unum - 1] >= 0 && + uid == SHM->uinfo[ulist[i + unum - 1]].uid ) ) + return &SHM->uinfo[ulist[i + unum - 1]]; break; /* 超過範圍 */ } if (end == start) { @@ -376,14 +380,16 @@ userinfo_t * search_ulist_userid(char *userid) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; - register userinfo_t **ulist; + int *ulist; + register userinfo_t * u; if (end == -1) return NULL; ulist = SHM->sorted[SHM->currsorted][0]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - j = strcasecmp(userid, ulist[i]->userid); + u = &SHM->uinfo[ulist[i]]; + j = strcasecmp(userid, u->userid); if (!j) { - return (userinfo_t *) (ulist[i]); + return u; } if (end == start) { break; @@ -403,20 +409,24 @@ int count_logins(int uid, int show) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count; - register userinfo_t **ulist; + int *ulist; + userinfo_t *u; if (end == -1) return 0; ulist = SHM->sorted[SHM->currsorted][6]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - j = uid - ulist[i]->uid; + u = &SHM->uinfo[ulist[i]]; + j = uid - u->uid; if (!j) { - for (; i > 0 && uid == ulist[i - 1]->uid; i--); /* 指到第一筆 */ + for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; i--); + /* 指到第一筆 */ for (count = 0; (ulist[i + count] && - uid == ulist[i + count]->uid); count++) { + (u = &SHM->uinfo[ulist[i + count]]) && + uid == u->uid); count++) { if (show) prints("(%d) 目前狀態為: %-17.16s(來自 %s)\n", - count + 1, modestring(ulist[i + count], 0), - ulist[i + count]->from); + count + 1, modestring(u, 0), + u->from); } return count; } @@ -488,16 +498,17 @@ void touchbtotal(int bid) { static int -cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) +cmpboardname(int i, int j) { - return strcasecmp((*brd)->brdname, (*tmp)->brdname); + return strcasecmp(bcache[i].brdname, bcache[j].brdname); } static int -cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) +cmpboardclass(int i, int j) { - return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + - strcasecmp((*brd)->brdname, (*tmp)->brdname); + boardheader_t *brd1 = &bcache[i], *brd2 = &bcache[j]; + return (strncmp(brd1->title, brd2->title, 4) << 8) + + strcasecmp(brd1->brdname, brd2->brdname); } void @@ -510,11 +521,11 @@ sort_bcache(void) { sleep(1); return; } SHM->Bbusystate = 1; for (i = 0; i < SHM->Bnumber; i++) { - SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; + SHM->bsorted[1][i] = SHM->bsorted[0][i] = i; } - qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(int), (QCAST) cmpboardname); - qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(int), (QCAST) cmpboardclass); for (i = 0; i < SHM->Bnumber; i++) { @@ -679,11 +690,10 @@ int getbnum(const char *bname) { register int i = 0, j, start = 0, end = SHM->Bnumber - 1; - register boardheader_t **bhdr; - bhdr = SHM->bsorted[0]; + int *blist = SHM->bsorted[0]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - if (!(j = strcasecmp(bname, bhdr[i]->brdname))) - return (int)(bhdr[i] - bcache + 1); + if (!(j = strcasecmp(bname, bcache[blist[i]].brdname))) + return (int)(blist[i] + 1); if (end == start) { break; } else if (i == start) { diff --git a/mbbsd/name.c b/mbbsd/name.c index 9253a843..0c9009e8 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -661,13 +661,14 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, int completeboard_compar(int where, char *str, int len) { - return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); + boardheader_t *bh = &bcache[SHM->bsorted[0][where]]; + return strncasecmp(bh->brdname, str, len); } int completeboard_permission(int where) { - boardheader_t *bptr = SHM->bsorted[0][where]; + boardheader_t *bptr = &bcache[SHM->bsorted[0][where]]; return (!(bptr->brdattr & BRD_SYMBOLIC) && (GROUPOP() || HasPerm(bptr)) && !(bptr->brdattr & BRD_GROUPBOARD)); @@ -676,28 +677,29 @@ completeboard_permission(int where) char * completeboard_getname(int where) { - return SHM->bsorted[0][where]->brdname; + return bcache[SHM->bsorted[0][where]].brdname; } /* general complete functions (utmpshm) */ int completeutmp_compar(int where, char *str, int len) { - return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, - str, len); + userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]]; + return strncasecmp(u->userid, str, len); } int completeutmp_permission(int where) { + userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]]; return (unlikely(HAS_PERM(PERM_SYSOP)) || unlikely(HAS_PERM(PERM_SEECLOAK)) || // !SHM->sorted[SHM->currsorted][0][where]->invisible); - isvisible(currutmp, SHM->sorted[SHM->currsorted][0][where])); + isvisible(currutmp, u)); } char * completeutmp_getname(int where) { - return SHM->sorted[SHM->currsorted][0][where]->userid; + return SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]].userid; } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index c8bb5d50..5952b433 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -243,7 +243,7 @@ void login_friend_online(void) } #endif for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) { - uentp = (SHM->sorted[SHM->currsorted][0][i]); + uentp = (&SHM->uinfo[SHM->sorted[SHM->currsorted][0][i]]); if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) { stat1 = reverse_friend_stat(stat); stat <<= 24; @@ -1785,7 +1785,7 @@ pickup_bfriend(pickup_t * friends, int base) int currsorted = SHM->currsorted, number = SHM->UTMPnumber; friends = friends + base; for (i = 0; i < number && ngets < MAX_FRIEND - base; ++i) { - uentp = SHM->sorted[currsorted][0][i]; + uentp = &SHM->uinfo[SHM->sorted[currsorted][0][i]]; /* TODO isvisible() 重複用到了 friend_stat() */ if (uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && currutmp != uentp && isvisible(currutmp, uentp) && @@ -1806,7 +1806,8 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, int utmpnumber = SHM->UTMPnumber; int friendtotal = currutmp->friendtotal; - userinfo_t **utmp; + int *ulist; + userinfo_t *u; int which, sorted_way, size = 0, friend; if (friendtotal == 0) @@ -1850,17 +1851,18 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, if (!(cuser.uflag & FRIEND_FLAG) && size < nPickups) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); - utmp = SHM->sorted[currsorted][sorted_way]; + ulist = SHM->sorted[currsorted][sorted_way]; which = *page * nPickups - *nfriend; if (which < 0) which = 0; for (; which < utmpnumber && size < nPickups; which++) { - friend = friend_stat(currutmp, utmp[which]); + u = &SHM->uinfo[ulist[which]]; + friend = friend_stat(currutmp, u); /* TODO isvisible() 重複用到了 friend_stat() */ if ((pickup_way || - (currutmp != utmp[which] && !(friend & ST_FRIEND))) && - isvisible(currutmp, utmp[which])) { - currpickup[size].ui = utmp[which]; + (currutmp != u && !(friend & ST_FRIEND))) && + isvisible(currutmp, u)) { + currpickup[size].ui = u; currpickup[size++].friend = friend; } } @@ -2267,12 +2269,11 @@ userlist(void) if (si >= 0) { pickup_t friends[MAX_FRIEND + 1]; int nGots, i; - userinfo_t **utmp = + int *ulist = SHM->sorted[SHM->currsorted] [((pickup_way == 0) ? 0 : (pickup_way - 1))]; - fi = utmp[si] - &SHM->uinfo[0]; - + fi = ulist[si]; nGots = pickup_myfriend(friends, &myfriend, &friendme, &badfriend); for (i = 0; i < nGots; ++i) @@ -2294,10 +2295,14 @@ userlist(void) } for( ; fi < nPickups && i < SHM->UTMPnumber ; ++i ) - if( isvisible(currutmp, utmp[i]) ){ - currpickup[fi].ui = utmp[i]; + { + userinfo_t *u; + u = &SHM->uinfo[ulist[i]]; + if( isvisible(currutmp, u) ){ + currpickup[fi].ui = u; currpickup[fi++].friend = 0; } + } skippickup = 1; } redrawall = redraw = 1; @@ -2380,7 +2385,8 @@ userlist(void) break; } for (i = 0; i < SHM->UTMPnumber; ++i) { - uentp = SHM->sorted[SHM->currsorted][0][i]; + uentp = &SHM->uinfo[ + SHM->sorted[SHM->currsorted][0][i]]; if (uentp->pid && kill(uentp->pid, 0) != -1) my_write(uentp->pid, genbuf, uentp->userid, WATERBALL_PREEDIT, NULL); diff --git a/util/boardlist.c b/util/boardlist.c index 606a0192..b6aae6ee 100644 --- a/util/boardlist.c +++ b/util/boardlist.c @@ -9,7 +9,9 @@ load_uidofgid(const int gid, const int type) int n, childcount = 0; currbptr = &bcache[gid - 1]; for (n = 0; n < numboards; ++n) { - if( !(bptr = SHM->bsorted[type][n]) || bptr->brdname[0] == '\0' ) + if(SHM->bsorted[type][n]<0) continue; + bptr = &SHM->bcache[SHM->bsorted[type][n]]; + if( bptr->brdname[0] == '\0' ) continue; if (bptr->gid == gid) { if (currbptr == &bcache[gid - 1]) diff --git a/util/shmctl.c b/util/shmctl.c index 493e7c35..531f5235 100644 --- a/util/shmctl.c +++ b/util/shmctl.c @@ -42,7 +42,7 @@ int logout_friend_online(userinfo_t *utmp) void purge_utmp(userinfo_t *uentp) { logout_friend_online(uentp); - //memset(uentp, 0, sizeof(userinfo_t)); + //memset(uentp, 0, sizeof(int)); } typedef struct { @@ -203,7 +203,7 @@ int utmpfix(int argc, char **argv) if( clean ){ printf("clean %06d(%s), userid: %s\n", i, clean, SHM->uinfo[which].userid); - memset(&SHM->uinfo[which], 0, sizeof(userinfo_t)); + memset(&SHM->uinfo[which], 0, sizeof(int)); --nownum; changeflag = 1; } @@ -224,33 +224,33 @@ int utmpfix(int argc, char **argv) /* utmpsortd --------------------------------------------------------------- */ static int -cmputmpuserid(const void *i, const void *j) +cmputmpuserid(int i, int j) { - return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); + return strcasecmp(SHM->uinfo[i].userid, SHM->uinfo[j].userid); } static int -cmputmpmode(const void *i, const void *j) +cmputmpmode(int i, int j) { - return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; + return SHM->uinfo[i].mode - SHM->uinfo[j].mode; } static int -cmputmpidle(const void *i, const void *j) +cmputmpidle(int i, int j) { - return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; + return SHM->uinfo[i].lastact - SHM->uinfo[j].lastact; } static int -cmputmpfrom(const void *i, const void *j) +cmputmpfrom(int i, int j) { - return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); + return strcmp(SHM->uinfo[i].from, SHM->uinfo[j].from); } static int -cmputmpfive(const void *i, const void *j) +cmputmpfive(int i, int j) { - userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j)); + userinfo_t *a=&SHM->uinfo[i],*b=&SHM->uinfo[j]; int played_a=(a->five_win+a->five_lose+a->five_lose)!=0; int played_b=(b->five_win+b->five_lose+b->five_lose)!=0; int type; @@ -267,9 +267,9 @@ cmputmpfive(const void *i, const void *j) } static int -cmputmpchc(const void *i, const void *j) +cmputmpchc(int i, int j) { - userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j)); + userinfo_t *a=&SHM->uinfo[i],*b=&SHM->uinfo[j]; int total_a=a->chc_win+a->chc_lose+a->chc_lose; int total_b=b->chc_win+b->chc_lose+b->chc_lose; int played_a=(total_a!=0); @@ -303,15 +303,15 @@ cmputmpchc(const void *i, const void *j) } static int -cmputmppid(const void *i, const void *j) +cmputmppid(int i, int j) { - return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; + return SHM->uinfo[i].pid - SHM->uinfo[j].pid; } static int -cmputmpuid(const void *i, const void *j) +cmputmpuid(int i, int j) { - return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; + return SHM->uinfo[i].uid - SHM->uinfo[j].uid; } inline void utmpsort(int sortall) @@ -336,36 +336,36 @@ inline void utmpsort(int sortall) if (uentp->sex < 0 || uentp->sex > 7) purge_utmp(uentp); else - SHM->sorted[ns][0][count++] = uentp; + SHM->sorted[ns][0][count++] = i; } } SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); + qsort(SHM->sorted[ns][0], count, sizeof(int), cmputmpuserid); memcpy(SHM->sorted[ns][6], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][7], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); - qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); + SHM->sorted[ns][0], sizeof(int) * count); + qsort(SHM->sorted[ns][6], count, sizeof(int), cmputmpuid); + qsort(SHM->sorted[ns][7], count, sizeof(int), cmputmppid); if( sortall ){ memcpy(SHM->sorted[ns][1], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][2], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][3], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][4], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][5], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); - qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); + SHM->sorted[ns][0], sizeof(int) * count); + qsort(SHM->sorted[ns][1], count, sizeof(int), cmputmpmode); + qsort(SHM->sorted[ns][2], count, sizeof(int), cmputmpidle); + qsort(SHM->sorted[ns][3], count, sizeof(int), cmputmpfrom); + qsort(SHM->sorted[ns][4], count, sizeof(int), cmputmpfive); + qsort(SHM->sorted[ns][5], count, sizeof(int), cmputmpchc); memset(nusers, 0, sizeof(nusers)); for (i = 0; i < count; ++i) { - uentp = SHM->sorted[ns][0][i]; + uentp = &SHM->bcache[SHM->sorted[ns][0][i]]; if (uentp && uentp->pid && 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) ++nusers[uentp->brc_id - 1]; @@ -373,9 +373,10 @@ inline void utmpsort(int sortall) { #if HOTBOARDCACHE int k, r, last = 0, top = 0; - boardheader_t *HBcache[HOTBOARDCACHE]; + int HBcache[HOTBOARDCACHE]; + for (i = 0; i < HOTBOARDCACHE; i++) HBcache[i]=-1; #endif - for (i = 0; i < SHM->Bnumber; ++i) + for (i = 0; i < SHM->Bnumber; i++) if (SHM->bcache[i].brdname[0] != 0){ SHM->bcache[i].nuser = nusers[i]; #if HOTBOARDCACHE @@ -384,14 +385,15 @@ inline void utmpsort(int sortall) IS_BOARD(&SHM->bcache[i]) && IS_OPENBRD(&SHM->bcache[i]) ){ for( k = top - 1 ; k >= 0 ; --k ) - if( nusers[i] < HBcache[k]->nuser ) + if(HBcache[k]>=0 && + nusers[i] < SHM->bcache[HBcache[k]].nuser ) break; if( top < HOTBOARDCACHE ) ++top; for( r = top - 1 ; r > (k + 1) ; --r ) HBcache[r] = HBcache[r - 1]; - HBcache[k + 1] = &SHM->bcache[i]; - last = nusers[(HBcache[top - 1] - SHM->bcache)]; + HBcache[k + 1] = i; + last = nusers[HBcache[top - 1]]; } #endif } |