看板 PttCurrent 關於我們 聯絡資訊
我的站上出現一點問題 我把追蹤的結果post出來 希望站大有空幫我的忙 (這可能是個bug) 問題是這樣子 我站上所有使用者 沒辦法加入一個id為好友 (id是 zoo) 在使用者名單增加好友以後 該個id不會變色 我檢查了 overrides 確定該筆 id 有進入檔案 然後我在程式碼裡加了一些東西 檢查 SHM->uinfo->friend SHM->uinfo->friend_online 確定 zoo 的資料有讀入而且正確 我比對了一些地方 最後trace到 talk.c, pickup_myfriend() pickup_myfriend(pickup_t * friends, int *myfriend, int *friendme, int *badfriend) { userinfo_t *uentp; int i, where, frstate, ngets = 0; *badfriend = 0; *myfriend = *friendme = 1; for (i = 0; currutmp->friend_online[i] && i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; /* Begin of DEBUG code */ uentp = &SHM->uinfo[where]; vmsg("%s", uentp->userid); vmsg("%d", where); if(0 <= where) vmsg("ck1"); if(where < MAX_ACTIVE) vmsg("ck2"); if(uentp = &SHM->uinfo[where]) vmsg("ck3"); if(uentp->pid) vmsg("ck4"); /* End of DEBUG code */ if (0 <= where && where < MAX_ACTIVE && 紅色的程式碼, 會取出zoo這個id在 uinfo[] 陣列的 index, 存在 where 綠色的程式碼, 會檢查 where 是否超出範圍 檢查的結果, zoo這個id每次都會超出 MAX_ACTIVE ------ 我懷疑是上站時 配置uinfo位置程式碼有問題 我找到了 cache.c, getnewutmpent() 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++) { if (p == USHM_SIZE) p = 0; // vmsg("utmp location: %d", p); uentp = &(SHM->uinfo[p]); if (!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; return; } } 我站上的 MAX_ACTIVE 設成 1024 當 zoo 這個 id 送入 StringHash() 傳回值就是 1024 所以每次 zoo 上站時 他永遠被配置在 uinfo[1024] / uinfo[1025] / info[1026] / info[1027] 導致前面檢查 where < MAX_ACTIVE 永遠出錯 上面標黃色的程式碼改成 if(p >= MAX_ACTIVE) 可以治標 只是USHM_SIZE為什麼要設成MAX_ACTIVE + 4 在這邊造成一些不一致的問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.168.153.227