summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-06-07 05:35:23 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-06-07 05:35:23 +0800
commite8fc08b9800ba86163e5bf43469cdc9f4b478b13 (patch)
treeeb2dcd75cad19ac57b7e9d9cc29c63a850d8ad86
parentc0a6419aeceaeb93d5d9ccde393236d67ff8c72f (diff)
downloadpttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar
pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.gz
pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.bz2
pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.lz
pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.xz
pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.zst
pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.zip
only one shared memory
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@296 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/bbs.h2
-rw-r--r--include/config.h5
-rw-r--r--include/proto.h8
-rw-r--r--include/pttstruct.h117
-rw-r--r--mbbsd/admin.c10
-rw-r--r--mbbsd/announce.c4
-rw-r--r--mbbsd/bbs.c6
-rw-r--r--mbbsd/board.c70
-rw-r--r--mbbsd/cache.c379
-rw-r--r--mbbsd/cal.c4
-rw-r--r--mbbsd/chicken.c4
-rw-r--r--mbbsd/kaede.c4
-rw-r--r--mbbsd/mail.c12
-rw-r--r--mbbsd/mbbsd.c19
-rw-r--r--mbbsd/menu.c19
-rw-r--r--mbbsd/name.c14
-rw-r--r--mbbsd/talk.c63
-rw-r--r--mbbsd/user.c4
-rw-r--r--mbbsd/var.c9
-rw-r--r--util/BM_money.c13
-rw-r--r--util/Makefile12
-rw-r--r--util/account.c52
-rw-r--r--util/bbsmail.c16
-rw-r--r--util/birth.c15
-rw-r--r--util/buildAnnounce.c26
-rw-r--r--util/deluserfile.c13
-rw-r--r--util/expire.c18
-rw-r--r--util/horoscope.c9
-rw-r--r--util/inndBM.c24
-rw-r--r--util/jungo.c15
-rw-r--r--util/mandex.c15
-rw-r--r--util/openticket.c16
-rw-r--r--util/openvice.c14
-rw-r--r--util/parse_news.c13
-rw-r--r--util/post.c11
-rw-r--r--util/poststat.c148
-rw-r--r--util/reaper.c15
-rw-r--r--util/rmuid.c13
-rw-r--r--util/shmctl.c149
-rw-r--r--util/shmsweep.c4
-rw-r--r--util/smtest.c15
-rw-r--r--util/toplazyBBM.c15
-rw-r--r--util/toplazyBM.c16
-rw-r--r--util/topusr.c12
-rw-r--r--util/uhash_loader.c28
-rw-r--r--util/userlist.c19
-rw-r--r--util/util_cache.c224
-rw-r--r--util/xchatd.c36
-rw-r--r--util/yearsold.c17
49 files changed, 676 insertions, 1070 deletions
diff --git a/include/bbs.h b/include/bbs.h
index 5d1469f9..7d2ef8d1 100644
--- a/include/bbs.h
+++ b/include/bbs.h
@@ -26,9 +26,9 @@
#include <arpa/inet.h>
#include <arpa/telnet.h>
#include <sys/types.h>
+#include <dirent.h>
#include <sys/mman.h>
#include <machine/param.h>
-#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
diff --git a/include/config.h b/include/config.h
index edec26dd..971c84be 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1,4 +1,4 @@
-/* $Id: config.h,v 1.4 2002/06/04 13:07:12 in2 Exp $ */
+/* $Id: config.h,v 1.5 2002/06/06 21:34:09 in2 Exp $ */
#ifndef INCLUDE_CONFIG_H
#define INCLUDE_CONFIG_H
@@ -168,11 +168,14 @@
#define MAGIC_KEY 1234 /* 身分認證信函編碼 */
+#define SHM_KEY 1228
+#if 0
#define BRDSHM_KEY 1208
#define UHASH_KEY 1218 /* userid->uid hash */
#define UTMPSHM_KEY 2221
#define PTTSHM_KEY 1220 /* 動態看版 , 節日 */
#define FROMSHM_KEY 1223 /* whereis, 最多使用者 */
+#endif
#define BRDSEM_KEY 2005 /* semaphore key */
#define PTTSEM_KEY 2000 /* semaphore key */
diff --git a/include/proto.h b/include/proto.h
index 7d8d886f..ee32cd2d 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.20 2002/06/04 13:07:12 in2 Exp $ */
+/* $Id: proto.h,v 1.21 2002/06/06 21:34:09 in2 Exp $ */
#ifndef INCLUDE_PROTO_H
#define INCLUDE_PROTO_H
@@ -115,6 +115,9 @@ int mdcacheopen(char *fpath);
void touchdircache(int bid);
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);
+
/* cal */
int give_tax(int money);
int vice(int money, char* item);
@@ -559,4 +562,7 @@ int calendar();
/* util */
void touchbtotal(int bid);
+
+/* util_cache.c */
+void reload_pttcache(void);
#endif
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 91a0d036..a9c4db57 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -1,4 +1,4 @@
-/* $Id: pttstruct.h,v 1.13 2002/06/04 13:07:12 in2 Exp $ */
+/* $Id: pttstruct.h,v 1.14 2002/06/06 21:34:09 in2 Exp $ */
#ifndef INCLUDE_STRUCT_H
#define INCLUDE_STRUCT_H
@@ -165,12 +165,6 @@ typedef struct fileheader_t {
#define HASH_BITS 16
typedef struct uhash_t {
- char userid[MAX_USERS][IDLEN + 1];
- int next_in_hash[MAX_USERS];
- int money[MAX_USERS];
- int hash_head[1 << HASH_BITS];
- int number; /* # of users total */
- int loaded; /* .PASSWD has been loaded? */
} uhash_t;
union xitem_t {
@@ -291,20 +285,6 @@ typedef struct crosspost_t {
#define SORT_BY_FIVE 4
#define SORT_BY_SEX 5
-typedef struct bcache_t {
- boardheader_t bcache[MAX_BOARD];
- boardheader_t *sorted[2][MAX_BOARD]; /* 0: by name 1: by class */
- fileheader_t dircache[MAX_BOARD][DIRCACHESIZE];
- time_t busystate_b[MAX_BOARD];
- int total[MAX_BOARD];
- int hbfl[MAX_BOARD][MAX_FRIEND + 1];
- time_t lastposttime[MAX_BOARD];
- time_t uptime;
- time_t touchtime;
- int number;
- int busystate;
-} bcache_t;
-
typedef struct keeploc_t {
char *key;
int top_ln;
@@ -314,42 +294,65 @@ typedef struct keeploc_t {
#define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */
-struct utmpfile_t {
- userinfo_t uinfo[USHM_SIZE];
- userinfo_t *sorted[2][8][USHM_SIZE];
- /* 第一維double buffer 由currsorted指向目前使用的
- 第二維sort type */
- int currsorted;
- time_t uptime;
- int number;
- int busystate;
-};
-
-struct pttcache_t {
- char notes[MAX_MOVIE][200*11];
- char today_is[20];
- int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */
- int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */
- int max_film;
- int max_history;
- time_t uptime;
- time_t touchtime;
- int busystate;
-
- int GLOBALVAR[10]; /* mbbsd間的 global variable
- 用以做統計等資料 (非常態) */
-};
-
-typedef struct fromcache_t {
- char domain[MAX_FROM][50];
- char replace[MAX_FROM][50];
- int top;
- int max_user;
- time_t max_time;
- time_t uptime;
- time_t touchtime;
- int busystate;
-} fromcache_t;
+typedef struct {
+ /* uhash */
+ char userid[MAX_USERS][IDLEN + 1];
+ int next_in_hash[MAX_USERS];
+ int money[MAX_USERS];
+ int hash_head[1 << HASH_BITS];
+ int number; /* # of users total */
+ int loaded; /* .PASSWD has been loaded? */
+
+ /* utmpshm */
+ userinfo_t uinfo[USHM_SIZE];
+ userinfo_t *sorted[2][8][USHM_SIZE];
+ /* 第一維double buffer 由currsorted指向目前使用的
+ 第二維sort type */
+ int currsorted;
+ time_t UTMPuptime;
+ int UTMPnumber;
+ int UTMPbusystate;
+
+ char gap[1024]; /* avoid some memory error / buffer overflow */
+ /* brdshm */
+ boardheader_t bcache[MAX_BOARD];
+ boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */
+ fileheader_t dircache[MAX_BOARD][DIRCACHESIZE];
+ time_t busystate_b[MAX_BOARD];
+ int total[MAX_BOARD];
+ int hbfl[MAX_BOARD][MAX_FRIEND + 1];
+ time_t lastposttime[MAX_BOARD];
+ time_t Buptime;
+ time_t Btouchtime;
+ int Bnumber;
+ int Bbusystate;
+
+ char gap2[1024]; /* avoid some memory error / buffer overflow */
+ /* pttcache */
+ char notes[MAX_MOVIE][200*11];
+ char today_is[20];
+ int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */
+ int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */
+ int max_film;
+ int max_history;
+ time_t Puptime;
+ time_t Ptouchtime;
+ int Pbusystate;
+
+ int GLOBALVAR[10]; /* mbbsd間的 global variable
+ 用以做統計等資料 (非常態) */
+
+ char gap3[1024]; /* avoid some memory error / buffer overflow */
+ /* fromcache */
+ char domain[MAX_FROM][50];
+ char replace[MAX_FROM][50];
+ int top;
+ int max_user;
+ time_t max_time;
+ time_t Fuptime;
+ time_t Ftouchtime;
+ int Fbusystate;
+} SHM_t;
typedef struct {
unsigned char oldlen; /* previous line length */
diff --git a/mbbsd/admin.c b/mbbsd/admin.c
index 9d795f90..48e21777 100644
--- a/mbbsd/admin.c
+++ b/mbbsd/admin.c
@@ -1,4 +1,4 @@
-/* $Id: admin.c,v 1.20 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: admin.c,v 1.21 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
/* 使用者管理 */
@@ -368,7 +368,7 @@ int m_board() {
char bname[32];
stand_title("看板設定");
- generalnamecomplete(msg_bid, bname, sizeof(bname), brdshm->number,
+ generalnamecomplete(msg_bid, bname, sizeof(bname), SHM->Bnumber,
completeboard_compar,
completeboard_permission,
completeboard_getname);
@@ -1053,10 +1053,10 @@ int give_money() {
stand_title("發錢中...");
if(to_all) {
int i, unum;
- for(unum = uhash->number, i=0; i<unum; i++) {
- if(bad_user_id(uhash->userid[i]))
+ for(unum = SHM->number, i=0; i<unum; i++) {
+ if(bad_user_id(SHM->userid[i]))
continue;
- id = uhash->userid[i];
+ id = SHM->userid[i];
give_id_money(id, money, fp2, tt, now);
}
// something wrong @_@
diff --git a/mbbsd/announce.c b/mbbsd/announce.c
index 3afdbac2..d7fe9cde 100644
--- a/mbbsd/announce.c
+++ b/mbbsd/announce.c
@@ -1,4 +1,4 @@
-/* $Id: announce.c,v 1.10 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: announce.c,v 1.11 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
static void g_showmenu(gmenu_t *pm) {
@@ -472,7 +472,7 @@ static int AnnounceSelect() {
clrtoeol();
move(1, 0);
generalnamecomplete("選擇精華區看板:", buf, sizeof(buf),
- brdshm->number,
+ SHM->Bnumber,
completeboard_compar,
completeboard_permission,
completeboard_getname);
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 4b401280..6b08d1db 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -1,4 +1,4 @@
-/* $Id: bbs.c,v 1.48 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: bbs.c,v 1.49 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
static void mail_by_link(char* owner, char* title, char* path) {
@@ -245,7 +245,7 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) {
move(0, 0);
clrtoeol();
generalnamecomplete(MSG_SELECT_BOARD, bname, sizeof(bname),
- brdshm->number,
+ SHM->Bnumber,
completeboard_compar,
completeboard_permission,
completeboard_getname);
@@ -727,7 +727,7 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) {
if (bp && (bp->brdattr & BRD_VOTEBOARD))
return FULLUPDATE;
generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard),
- brdshm->number,
+ SHM->Bnumber,
completeboard_compar,
completeboard_permission,
completeboard_getname);
diff --git a/mbbsd/board.c b/mbbsd/board.c
index 15cdee5b..ad19d881 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -1,4 +1,4 @@
-/* $Id: board.c,v 1.34 2002/06/05 03:10:43 ptt Exp $ */
+/* $Id: board.c,v 1.35 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
#define BRC_STRLEN 15 /* Length of board name */
#define BRC_MAXSIZE 24576
@@ -354,23 +354,21 @@ static void load_uidofgid(const int gid, const int type){
boardheader_t *bptr,*currbptr;
int n, childcount=0;
currbptr = &bcache[gid-1];
- for(n=0;n<numboards;n++)
- {
- bptr = brdshm->sorted[type][n];
- if(bptr->brdname[0]=='\0') continue;
- if(bptr->gid == gid)
- {
- if(currbptr == &bcache[gid-1])
- currbptr->firstchild[type]=bptr;
- else
- {
- currbptr->next[type]=bptr;
- currbptr->parent=&bcache[gid-1];
+ for( n = 0 ; n < numboards ; ++n ){
+ bptr = SHM->bsorted[type][n];
+ if( bptr->brdname[0] == '\0' )
+ continue;
+ if( bptr->gid == gid ){
+ if(currbptr == &bcache[gid-1])
+ currbptr->firstchild[type]=bptr;
+ else{
+ currbptr->next[type]=bptr;
+ currbptr->parent=&bcache[gid-1];
}
- childcount++;
- currbptr=bptr;
- }
- }
+ childcount++;
+ currbptr=bptr;
+ }
+ }
bcache[gid-1].childcount=childcount;
if(currbptr == &bcache[gid-1])
currbptr->firstchild[type]=(boardheader_t *) ~0;
@@ -381,8 +379,8 @@ static boardstat_t * addnewbrdstat(int n, int state)
{
boardstat_t *ptr=&nbrd[brdnum++];
boardheader_t *bptr = &bcache[n];
- ptr->total = &(brdshm->total[n]);
- ptr->lastposttime = &(brdshm->lastposttime[n]);
+ ptr->total = &(SHM->total[n]);
+ ptr->lastposttime = &(SHM->lastposttime[n]);
ptr->bid = n+1;
ptr->myattr=0;
ptr->myattr=(favbuf[n]&~BRD_ZAP);
@@ -418,7 +416,7 @@ static void load_boards(char *key) {
nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t));
for(i=0 ; i < numboards; i++)
{
- if( (bptr = brdshm->sorted[type][i]) == NULL )
+ if( (bptr = SHM->bsorted[type][i]) == NULL )
continue;
n = (int)( bptr - bcache);
if(!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD ||
@@ -656,21 +654,23 @@ static void dozap(int num){
void delutmpbid(int bid, userinfo_t *utmp)
{
userinfo_t *u;
- while (brdshm->busystate || now-brdshm->busystate_b[bid-1]<5)
- sleep(1);
- // Ptt:有問題都是這邊沒有執行到就爛掉了
-
- brdshm->busystate_b[bid-1]=now;
- u=bcache[bid-1].u;
- if(u!=(void*)utmp)
- {
- for(;u && u->nextbfriend != (void*)utmp; u=u->nextbfriend);
- if(u) u->nextbfriend = utmp->nextbfriend;
- }
- else
- bcache[bid-1].u=utmp->nextbfriend;
- if(bcache[bid-1].nuser>0) bcache[bid-1].nuser--;
- brdshm->busystate_b[bid-1]=0;
+ while( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 5 )
+ sleep(1);
+ // Ptt:有問題都是這邊沒有執行到就爛掉了
+
+ SHM->busystate_b[bid-1] = now;
+ u = bcache[bid - 1].u;
+ if( u != (void *)utmp ){
+ for( ; u && u->nextbfriend != (void*)utmp; u = u->nextbfriend )
+ ;
+ if( u )
+ u->nextbfriend = utmp->nextbfriend;
+ }
+ else
+ bcache[bid - 1].u = utmp->nextbfriend;
+ if( bcache[bid - 1].nuser > 0 )
+ bcache[bid - 1].nuser--;
+ SHM->busystate_b[bid - 1] = 0;
}
void setutmpbid(int bid)
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index ab87c3a0..d2c47fe7 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -1,4 +1,4 @@
-/* $Id: cache.c,v 1.31 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: cache.c,v 1.32 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
#ifndef __FreeBSD__
@@ -9,7 +9,6 @@ union semun {
struct seminfo *__buf; /* buffer for IPC_INFO */
};
#endif
-int fcache_semid;
/* the reason for "safe_sleep" is that we may call sleep during
SIGALRM handler routine, while SIGALRM is blocked.
@@ -53,7 +52,7 @@ static void attach_err(int shmkey, char *name) {
exit(1);
}
-static void *attach_shm(int shmkey, int shmsize) {
+void *attach_shm(int shmkey, int shmsize) {
void *shmptr;
int shmid;
@@ -130,74 +129,86 @@ void sem_lock(int op,int semid) {
*/
/* attach_uhash should be called before using uhash */
-void attach_uhash() {
- uhash = attach_shm(UHASH_KEY, sizeof(*uhash));
- if(!uhash->loaded) /* assume fresh shared memory is zeroed */
+
+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) {
int *p, h = StringHash(id);
int times;
- strcpy(uhash->userid[n], id);
+ strcpy(SHM->userid[n], id);
- p = &(uhash->hash_head[h]);
+ p = &(SHM->hash_head[h]);
for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times )
- p = &(uhash->next_in_hash[*p]);
+ p = &(SHM->next_in_hash[*p]);
if( times == MAX_USERS )
abort_bbs(0);
- uhash->next_in_hash[*p = n] = -1;
+ 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 = StringHash(uhash->userid[n]);
- int *p = &(uhash->hash_head[h]);
+ int h = StringHash(SHM->userid[n]);
+ int *p = &(SHM->hash_head[h]);
int times;
for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times )
- p = &(uhash->next_in_hash[*p]);
+ p = &(SHM->next_in_hash[*p]);
if( times == MAX_USERS )
abort_bbs(0);
if(*p == n)
- *p = uhash->next_in_hash[n];
+ *p = SHM->next_in_hash[n];
}
int setumoney(int uid, int money) {
- uhash->money[uid-1]=money;
+ SHM->money[uid-1]=money;
passwd_update_money(uid);
- return uhash->money[uid-1];
+ return SHM->money[uid-1];
}
int deumoney(int uid, int money) {
- if(money<0 && uhash->money[uid-1]<-money)
+ if(money<0 && SHM->money[uid-1]<-money)
return setumoney(uid,0);
else
- return setumoney(uid,uhash->money[uid-1]+money);
+ return setumoney(uid,SHM->money[uid-1]+money);
}
int demoney(int money) {
return deumoney(usernum,money);
}
int moneyof(int uid){ /* ptt 改進金錢處理效率 */
- return uhash->money[uid-1];
+ return SHM->money[uid-1];
}
int searchuser(char *userid) {
int h, p, times;
h = StringHash(userid);
- p = uhash->hash_head[h];
+ p = SHM->hash_head[h];
for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){
- if(strcasecmp(uhash->userid[p],userid) == 0) {
- strcpy(userid,uhash->userid[p]);
+ if(strcasecmp(SHM->userid[p],userid) == 0) {
+ strcpy(userid,SHM->userid[p]);
return p + 1;
}
- p = uhash->next_in_hash[p];
+ p = SHM->next_in_hash[p];
}
return 0;
@@ -215,14 +226,14 @@ int getuser(char *userid) {
char *getuserid(int num) {
if(--num >= 0 && num < MAX_USERS)
- return ((char *) uhash->userid[num]);
+ return ((char *) SHM->userid[num]);
return NULL;
}
void setuserid(int num, char *userid) {
if(num > 0 && num <= MAX_USERS) {
- if(num > uhash->number)
- uhash->number = num;
+ if(num > SHM->number)
+ SHM->number = num;
else
remove_from_uhash(num-1);
add_to_uhash(num-1,userid);
@@ -235,12 +246,12 @@ void setuserid(int num, char *userid) {
int searchnewuser(int mode) {
register int i, num;
- num = uhash->number;
+ num = SHM->number;
i = 0;
/* 為什麼這邊不用 hash table 去找而要用 linear search? */
while(i < num) {
- if(!uhash->userid[i++][0])
+ if(!SHM->userid[i++][0])
return i;
}
if(mode && (num < MAX_USERS))
@@ -249,24 +260,23 @@ int searchnewuser(int mode) {
}
char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) {
- register struct uhash_t *reg_ushm = uhash;
register char *ptr, tmp;
register int n, total;
char tagbuf[STRLEN];
int ch, ch2, num;
if(*tag == '\0') {
- *pnum = reg_ushm->number;
- return reg_ushm->userid[0];
+ *pnum = SHM->number;
+ return SHM->userid[0];
}
for(n = 0; tag[n]; n++)
tagbuf[n] = chartoupper(tag[n]);
tagbuf[n] = '\0';
ch = tagbuf[0];
ch2 = ch - 'A' + 'a';
- total = reg_ushm->number;
+ total = SHM->number;
for(n = num = 0; n < total; n++) {
- ptr = reg_ushm->userid[n];
+ ptr = SHM->userid[n];
tmp = *ptr;
if(tmp == ch || tmp == ch2) {
if(chkstr(tag, tagbuf, ptr))
@@ -281,12 +291,6 @@ char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) {
/*-------------------------------------------------------*/
/* .UTMP cache */
/*-------------------------------------------------------*/
-void resolve_utmp() {
- if(utmpshm == NULL) {
- utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm));
- }
-}
-
#if !defined(_BBS_UTIL_C_)
void setutmpmode(int mode) {
if(currstat != mode)
@@ -343,50 +347,50 @@ void sort_utmp()
int count, i, ns;
userinfo_t *uentp;
now=time(0);
- if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate))
- return; /* lazy sort */
- utmpshm->busystate=1;
- utmpshm->uptime = now;
- ns=(utmpshm->currsorted?0:1);
-
- for(uentp = &utmpshm->uinfo[0], count=0, i=0;
- i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i])
- {
- if(uentp->pid)
- {
- if(uentp->sex<0 || uentp->sex>7)
- memset(uentp, 0, sizeof(userinfo_t));
- else
- utmpshm->sorted[ns][0][count++]= uentp;
+ if( now - SHM->UTMPuptime < 60 &&
+ (now == SHM->UTMPuptime || SHM->UTMPbusystate) )
+ return; /* lazy sort */
+ SHM->UTMPbusystate=1;
+ SHM->UTMPuptime = now;
+ ns = (SHM->currsorted ? 0 : 1);
+
+ for( uentp = &SHM->uinfo[0], count = i = 0 ;
+ i < USHM_SIZE ;
+ ++i, uentp = &SHM->uinfo[i] ){
+ if(uentp->pid) {
+ if(uentp->sex<0 || uentp->sex>7)
+ memset(uentp, 0, sizeof(userinfo_t));
+ else
+ SHM->sorted[ns][0][count++]= uentp;
}
- }
- utmpshm->number = count;
- qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid);
+ }
+ SHM->UTMPnumber = count;
+ qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid);
for(i=0; i<count; i++)
- ((userinfo_t*)utmpshm->sorted[ns][0][i])->idoffset=i;
- memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0],
+ ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset=i;
+ memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode );
- qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle );
- qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom );
- qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive );
- qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex );
- qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid );
- qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid );
- utmpshm->currsorted=ns;
- utmpshm->busystate=0;
+ 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 *), cmputmpsex );
+ qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid );
+ qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid );
+ SHM->currsorted=ns;
+ SHM->UTMPbusystate=0;
}
// Ptt:這邊加入hash觀念 找空的utmp
void getnewutmpent(userinfo_t *up) {
@@ -394,7 +398,7 @@ void getnewutmpent(userinfo_t *up) {
register userinfo_t *uentp;
for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) {
if(p==USHM_SIZE) p=0;
- uentp = &(utmpshm->uinfo[p]);
+ uentp = &(SHM->uinfo[p]);
if(!(uentp->pid)) {
memcpy(uentp, up, sizeof(userinfo_t));
currutmp = uentp;
@@ -410,7 +414,7 @@ int apply_ulist(int (*fptr)(userinfo_t *)) {
register int i, state;
for(i = 0; i < USHM_SIZE; i++) {
- uentp = &(utmpshm->uinfo[i]);
+ uentp = &(SHM->uinfo[i]);
if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp)))
if((state = (*fptr) (uentp)))
return state;
@@ -424,11 +428,11 @@ userinfo_t *search_ulist(int uid) {
#if !defined(_BBS_UTIL_C_)
userinfo_t *search_ulist_pid(int pid) {
- register int i=0, j, start = 0, end = utmpshm->number - 1;
+ register int i=0, j, start = 0, end = SHM->UTMPnumber - 1;
register userinfo_t **ulist;
if( end == -1 )
return NULL;
- ulist=utmpshm->sorted[utmpshm->currsorted][7];
+ ulist=SHM->sorted[SHM->currsorted][7];
for(i=((start+end)/2); ;i=(start+end)/2)
{
j=pid-ulist[i]->pid;
@@ -451,11 +455,11 @@ userinfo_t *search_ulist_pid(int pid) {
return 0;
}
userinfo_t *search_ulistn(int uid, int unum) {
- register int i=0, j, start = 0, end = utmpshm->number - 1;
+ register int i=0, j, start = 0, end = SHM->UTMPnumber - 1;
register userinfo_t **ulist;
if( end == -1 )
return NULL;
- ulist=utmpshm->sorted[utmpshm->currsorted][6];
+ ulist=SHM->sorted[SHM->currsorted][6];
for(i=((start+end)/2); ;i=(start+end)/2)
{
j= uid - ulist[i]->uid;
@@ -482,11 +486,11 @@ userinfo_t *search_ulistn(int uid, int unum) {
}
int count_logins(int uid, int show) {
- register int i=0, j, start = 0, end = utmpshm->number - 1, count;
+ register int i=0, j, start = 0, end = SHM->UTMPnumber - 1, count;
register userinfo_t **ulist;
if( end == -1 )
return NULL;
- ulist=utmpshm->sorted[utmpshm->currsorted][6];
+ ulist=SHM->sorted[SHM->currsorted][6];
for(i=((start+end)/2); ;i=(start+end)/2)
{
j = uid-ulist[i]->uid;
@@ -530,7 +534,7 @@ void purge_utmp(userinfo_t *uentp) {
/*-------------------------------------------------------*/
void touchdircache(int bid)
{
- int *i= (int *)&brdshm->dircache[bid - 1][0].filename[0];
+ int *i= (int *)&SHM->dircache[bid - 1][0].filename[0];
*i=0;
}
@@ -538,15 +542,15 @@ void load_fileheader_cache(int bid, char *direct)
{
int num=getbtotal(bid);
int n = num-DIRCACHESIZE+1;
- if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10 )
- {
- brdshm->busystate_b[bid-1] = now;
- get_records(direct, brdshm->dircache[bid - 1] ,
- sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE);
- brdshm->busystate_b[bid-1] = 0;
- }
- else
- {safe_sleep(1);}
+ if( SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10 ){
+ SHM->busystate_b[bid-1] = now;
+ get_records(direct, SHM->dircache[bid - 1] ,
+ sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE);
+ SHM->busystate_b[bid-1] = 0;
+ }
+ else{
+ safe_sleep(1);
+ }
}
int get_fileheader_cache(int bid, char *direct, fileheader_t *headers,
@@ -560,7 +564,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers,
n = (num - DIRCACHESIZE+1);
- if(brdshm->dircache[bid - 1][0].filename[0]=='\0')
+ if(SHM->dircache[bid - 1][0].filename[0]=='\0')
load_fileheader_cache(bid, direct);
if (n<1)
n=recbase-1;
@@ -568,7 +572,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers,
n=recbase-n;
if(n<0) n=0;
if (ret>nlines) ret=nlines;
- memcpy(headers, &(brdshm->dircache[bid - 1][n]),sizeof(fileheader_t)*ret);
+ memcpy(headers, &(SHM->dircache[bid - 1][n]),sizeof(fileheader_t)*ret);
return ret;
}
static int cmpboardname(boardheader_t **brd, boardheader_t **tmp) {
@@ -578,72 +582,66 @@ 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 不能單獨呼叫 呼叫reload_bcache or reset_board */
- for(i=0;i<brdshm->number;i++)
- {
- brdshm->sorted[1][i]=brdshm->sorted[0][i]=&bcache[i];
- }
- qsort(brdshm->sorted[0], brdshm->number, sizeof(boardheader_t *),
+static void sort_bcache()
+{
+ int i;
+ /*critical section 不能單獨呼叫 呼叫reload_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(brdshm->sorted[1], brdshm->number, sizeof(boardheader_t *),
+ qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *),
(QCAST)cmpboardclass);
}
static void reload_bcache() {
- if(brdshm->busystate) {
+ if( SHM->Bbusystate ){
safe_sleep(1);
}
#if !defined(_BBS_UTIL_C_)
else {
int fd,i;
- brdshm->busystate = 1;
+ SHM->Bbusystate = 1;
if((fd = open(fn_board, O_RDONLY)) > 0) {
- brdshm->number =
+ SHM->Bnumber =
read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) /
sizeof(boardheader_t);
close(fd);
}
- memset(brdshm->lastposttime, 0, MAX_BOARD * sizeof(time_t));
+ memset(SHM->lastposttime, 0, MAX_BOARD * sizeof(time_t));
/* 等所有 boards 資料更新後再設定 uptime */
- brdshm->uptime = brdshm->touchtime;
+ SHM->Buptime = SHM->Btouchtime;
log_usies("CACHE", "reload bcache");
sort_bcache();
- for(i=0;i<brdshm->number;i++)
- {
- bcache[i].u=NULL;
- bcache[i].nuser=0;
- bcache[i].firstchild[0]=NULL;
- bcache[i].firstchild[1]=NULL;
- }
- brdshm->busystate = 0;
+ for( i = 0 ; i < SHM->Bnumber ; ++i ){
+ bcache[i].u=NULL;
+ bcache[i].nuser=0;
+ bcache[i].firstchild[0]=NULL;
+ bcache[i].firstchild[1]=NULL;
+ }
+ SHM->Bbusystate = 0;
}
#endif
}
void resolve_boards() {
- if(brdshm == NULL) {
- brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm));
- if(brdshm->touchtime == 0)
- brdshm->touchtime = 1;
- bcache = brdshm->bcache;
+ while( SHM->Buptime < SHM->Btouchtime ){
+ reload_bcache();
}
-
- while(brdshm->uptime < brdshm->touchtime)
- {reload_bcache();}
- numboards = brdshm->number;
+ numboards = SHM->Bnumber;
}
void touch_boards() {
- brdshm->touchtime=now;
+ SHM->Btouchtime=now;
numboards = -1;
resolve_boards();
}
void addbrd_touchcache()
{
- brdshm->number++;
- numboards=brdshm->number;
- reset_board(numboards);
+ SHM->Bnumber++;
+ numboards=SHM->Bnumber;
+ reset_board(numboards);
}
#if !defined(_BBS_UTIL_C_)
void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */
@@ -654,10 +652,10 @@ void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */
if(--bid < 0)
return;
- if(brdshm->busystate || now-brdshm->busystate_b[bid-1]<10 ) {
+ if( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10 ){
safe_sleep(1);
} else {
- brdshm->busystate_b[bid-1] = now;
+ SHM->busystate_b[bid-1] = now;
nuser = bcache[bid-1].nuser;
u = bcache[bid-1].u;
@@ -669,14 +667,14 @@ void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */
close(fd);
}
sort_bcache();
- for(i=0;i<brdshm->number;i++)
+ for(i=0;i<SHM->Bnumber;i++)
{
bcache[i].firstchild[0]=NULL;
bcache[i].firstchild[1]=NULL;
}
nuser = bcache[bid-1].nuser;
u = bcache[bid-1].u;
- brdshm->busystate_b[bid-1] = 0;
+ SHM->busystate_b[bid-1] = 0;
}
}
@@ -698,7 +696,7 @@ boardheader_t *getbcache(int bid) { /* Ptt改寫 */
}
int getbtotal(int bid)
{
- return brdshm->total[bid - 1];
+ return SHM->total[bid - 1];
}
void setbtotal(int bid) {
boardheader_t *bh = getbcache(bid);
@@ -712,34 +710,35 @@ void setbtotal(int bid) {
return; /* .DIR掛了 */
fstat(fd, &st);
num = st.st_size / sizeof(fileheader_t);
- brdshm->total[bid - 1] = num;
+ SHM->total[bid - 1] = num;
if(num>0)
{
lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET);
if(read(fd, genbuf, FNLEN)>=0)
{
- brdshm->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]);
+ SHM->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]);
}
}
else
- brdshm->lastposttime[bid - 1] = 0;
+ SHM->lastposttime[bid - 1] = 0;
close(fd);
if(num)
touchdircache(bid);
}
-void
-touchbpostnum(int bid, int delta) {
- int *total = &brdshm->total[bid - 1];
- if (*total) *total += delta;
+void touchbpostnum(int bid, int delta)
+{
+ int *total = &SHM->total[bid - 1];
+ if (*total)
+ *total += delta;
}
int getbnum(char *bname) {
- register int i=0, j, start = 0, end = brdshm->number - 1;
+ register int i=0, j, start = 0, end = SHM->Bnumber - 1;
register boardheader_t **bhdr;
- bhdr=brdshm->sorted[0];
+ bhdr=SHM->bsorted[0];
for(i=((start+end)/2); ;i=(start+end)/2)
{
if(! (j=strcasecmp(bname,bhdr[i]->brdname)))
@@ -799,11 +798,9 @@ int haspostperm(char *bname) {
/* PTT cache */
/*-------------------------------------------------------*/
/* cachefor 動態看版 */
-struct pttcache_t *ptt;
-
static void reload_pttcache()
{
- if(ptt->busystate)
+ if( SHM->Pbusystate )
safe_sleep(1);
else { /* jochang: temporary workaround */
fileheader_t item, subitem;
@@ -811,9 +808,9 @@ static void reload_pttcache()
FILE *fp, *fp1, *fp2;
int id, section = 0;
- ptt->busystate = 1;
- ptt->max_film = 0;
- bzero(ptt->notes, sizeof ptt->notes);
+ SHM->Pbusystate = 1;
+ SHM->max_film = 0;
+ bzero(SHM->notes, sizeof(SHM->notes));
setapath(pbuf, "Note");
setadir(buf, pbuf);
id = 0;
@@ -824,15 +821,15 @@ static void reload_pttcache()
setadir(buf, buf);
if(!(fp1 = fopen(buf, "r")))
continue;
- ptt->next_refresh[section] = ptt->n_notes[section] = id;
+ 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(ptt->notes[id],sizeof(char), 200*11, fp2);
- ptt->notes[id][200*11 - 1]=0;
+ fread(SHM->notes[id],sizeof(char), 200*11, fp2);
+ SHM->notes[id][200*11 - 1]=0;
id++;
fclose(fp2);
if(id >= MAX_MOVIE)
@@ -845,50 +842,44 @@ static void reload_pttcache()
}
fclose(fp);
}
- ptt->next_refresh[section] = -1;
- ptt->n_notes[section] = ptt->max_film = id-1;
- ptt->max_history = ptt->max_film - 2;
- if(ptt->max_history > MAX_HISTORY - 1)
- ptt->max_history = MAX_HISTORY - 1;
- if(ptt->max_history <0) ptt->max_history=0;
+ 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(ptt->today_is,15,fp);
- if((chr = strchr(ptt->today_is,'\n')))
+ fgets(SHM->today_is,15,fp);
+ if((chr = strchr(SHM->today_is,'\n')))
*chr = 0;
- ptt->today_is[15] = 0;
+ SHM->today_is[15] = 0;
fclose(fp);
}
/* 等所有資料更新後再設定 uptime */
- ptt->uptime = ptt->touchtime ;
+ SHM->Puptime = SHM->Ptouchtime ;
#if !defined(_BBS_UTIL_C_)
log_usies("CACHE", "reload pttcache");
#endif
- ptt->busystate = 0;
+ SHM->Pbusystate = 0;
}
}
void resolve_garbage() {
int count=0;
- if(ptt == NULL) {
- ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt));
- GLOBALVAR = ptt->GLOBALVAR;
- if(ptt->touchtime == 0)
- ptt->touchtime = 1;
- }
- while(ptt->uptime < ptt->touchtime) { /* 不用while等 */
+ while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */
reload_pttcache();
- if(count ++ > 10 && ptt->busystate) {
+ if(count ++ > 10 && SHM->Pbusystate) {
/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0
這樣會所有prcosee都會在load 動態看板 會造成load大增
但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他
解開 同樣的問題發生在reload passwd
*/
- ptt->busystate = 0;
+ SHM->Pbusystate = 0;
#ifndef _BBS_UTIL_C_
log_usies("CACHE", "refork Ptt dead lock");
#endif
@@ -901,52 +892,48 @@ void resolve_garbage() {
/*-------------------------------------------------------*/
/* cachefor from host 與最多上線人數 */
static void reload_fcache() {
- if(fcache->busystate)
+ if( SHM->Fbusystate )
safe_sleep(1);
else {
FILE *fp;
- fcache->busystate = 1;
- bzero(fcache->domain, sizeof fcache->domain);
+ SHM->Fbusystate = 1;
+ bzero(SHM->domain, sizeof(SHM->domain));
if((fp = fopen("etc/domain_name_query","r"))) {
char buf[256],*po;
- fcache->top=0;
+ SHM->top=0;
while(fgets(buf, sizeof(buf),fp)) {
if(buf[0] && buf[0] != '#' && buf[0] != ' ' &&
buf[0] != '\n') {
- sscanf(buf,"%s",fcache->domain[fcache->top]);
- po = buf + strlen(fcache->domain[fcache->top]);
+ sscanf(buf,"%s",SHM->domain[SHM->top]);
+ po = buf + strlen(SHM->domain[SHM->top]);
while(*po == ' ')
po++;
- strncpy(fcache->replace[fcache->top],po,49);
- fcache->replace[fcache->top]
- [strlen(fcache->replace[fcache->top])-1] = 0;
- (fcache->top)++;
- if(fcache->top == MAX_FROM)
+ strncpy(SHM->replace[SHM->top],po,49);
+ SHM->replace[SHM->top]
+ [strlen(SHM->replace[SHM->top])-1] = 0;
+ (SHM->top)++;
+ if(SHM->top == MAX_FROM)
break;
}
}
}
- fcache->max_user=0;
+ SHM->max_user=0;
/* 等所有資料更新後再設定 uptime */
- fcache->uptime = fcache->touchtime;
+ SHM->Fuptime = SHM->Ftouchtime;
#if !defined(_BBS_UTIL_C_)
log_usies("CACHE", "reload fcache");
#endif
- fcache->busystate = 0;
+ SHM->Fbusystate = 0;
}
}
-void resolve_fcache() {
- if(fcache == NULL) {
- fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache));
- if(fcache->touchtime == 0)
- fcache->touchtime = 1;
- }
- while(fcache->uptime < fcache->touchtime)
+void resolve_fcache()
+{
+ while( SHM->Fuptime < SHM->Ftouchtime )
reload_fcache();
}
@@ -977,17 +964,17 @@ void hbflreload(int bid)
fclose(fp);
}
hbfl[0] = now;
- memcpy(brdshm->hbfl[bid], hbfl, sizeof(hbfl));
+ memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl));
}
int hbflcheck(int bid, int uid)
{
int i;
- if( brdshm->hbfl[bid][0] < login_start_time - HBFLexpire )
+ if( SHM->hbfl[bid][0] < login_start_time - HBFLexpire )
hbflreload(bid);
- for( i = 1 ; brdshm->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){
- if( brdshm->hbfl[bid][i] == uid )
+ for( i = 1 ; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){
+ if( SHM->hbfl[bid][i] == uid )
return 0;
}
return 1;
diff --git a/mbbsd/cal.c b/mbbsd/cal.c
index 3b41d279..dbb90c71 100644
--- a/mbbsd/cal.c
+++ b/mbbsd/cal.c
@@ -1,4 +1,4 @@
-/* $Id: cal.c,v 1.13 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: cal.c,v 1.14 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
/* 防堵 Multi play */
@@ -7,7 +7,7 @@ static int count_multiplay(int unmode) {
register userinfo_t *uentp;
for(i = j = 0; i < USHM_SIZE; i++) {
- uentp = &(utmpshm->uinfo[i]);
+ uentp = &(SHM->uinfo[i]);
if(uentp->uid == usernum)
if(uentp->lockmode == unmode)
j++;
diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c
index 9c30deec..0b1c9320 100644
--- a/mbbsd/chicken.c
+++ b/mbbsd/chicken.c
@@ -1,4 +1,4 @@
-/* $Id: chicken.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: chicken.c,v 1.5 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
#define NUM_KINDS 13 /* 有多少種動物 */
@@ -828,7 +828,7 @@ int chickenpk(int fd) {
char mateid[IDLEN + 1], data[200], buf[200];
int ch = 0;
- userinfo_t *uin = &utmpshm->uinfo[currutmp->destuip];
+ userinfo_t *uin = &SHM->uinfo[currutmp->destuip];
userec_t ouser;
chicken_t *ochicken = &ouser.mychicken;
int r, attmax, i, datac, duid = currutmp->destuid, catched=0, count=0;
diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c
index d9c33589..a3005ad3 100644
--- a/mbbsd/kaede.c
+++ b/mbbsd/kaede.c
@@ -1,4 +1,4 @@
-/* $Id: kaede.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: kaede.c,v 1.4 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
char *Ptt_prints(char *str, int mode) {
@@ -20,7 +20,7 @@ char *Ptt_prints(char *str, int mode) {
while((po = strstr(str, "\033*u"))) {
int attempts;
- attempts = utmpshm->number;
+ attempts = SHM->UTMPnumber;
po[0] = 0;
sprintf(strbuf, "%s%d%s", str, attempts, po + 3);
strcpy(str, strbuf);
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index 14325216..8610e5c5 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -1,4 +1,4 @@
-/* $Id: mail.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: mail.c,v 1.12 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
char currmaildir[32];
static char msg_cc[] = "\033[32m[群組名單]\033[m\n";
@@ -578,11 +578,11 @@ int mail_all() {
if(append_record(genbuf, &mymail, sizeof(mymail)) == -1)
outs(err_uid);
- for(unum = uhash->number, i = 0; i < unum; i++) {
- if(bad_user_id(uhash->userid[i]))
+ for(unum = SHM->number, i = 0; i < unum; i++) {
+ if(bad_user_id(SHM->userid[i]))
continue; /* Ptt */
- userid = uhash->userid[i];
+ userid = SHM->userid[i];
if(strcmp(userid,STR_GUEST) && strcmp(userid, "new") &&
strcmp(userid, cuser.userid)) {
sethomepath(genbuf, userid);
@@ -1057,7 +1057,7 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) {
clrtoeol();
move(1, 0);
generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard),
- brdshm->number,
+ SHM->Bnumber,
completeboard_compar,
completeboard_permission,
completeboard_getname);
@@ -1175,7 +1175,7 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) {
generalnamecomplete("輸入看版名稱 (直接Enter進入私人信件夾):",
buf, sizeof(buf),
- brdshm->number,
+ SHM->Bnumber,
completeboard_compar,
completeboard_permission,
completeboard_getname);
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index a933b6f3..64ab1557 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -1,4 +1,4 @@
-/* $Id: mbbsd.c,v 1.33 2002/06/05 02:42:29 ptt Exp $ */
+/* $Id: mbbsd.c,v 1.34 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
#define SOCKET_QLEN 4
@@ -250,7 +250,7 @@ talk_request(int sig)
time_t now = time (0);
sprintf (buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m",
- utmpshm->uinfo[currutmp->destuip].userid, my_ctime (&now),
+ SHM->uinfo[currutmp->destuip].userid, my_ctime (&now),
(currutmp->sig == 2)? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)"
: "呼叫、呼叫,聽到請回答");
move (0, 0);
@@ -516,11 +516,10 @@ login_query ()
char uid[IDLEN + 1], passbuf[PASSLEN];
int attempts;
char genbuf[200];
- resolve_utmp ();
+ attach_SHM();
resolve_garbage ();
- attach_uhash ();
now= time(0);
- attempts = utmpshm->number;
+ attempts = SHM->UTMPnumber;
#ifdef DEBUG
move(1, 0);
prints("debugging mode\ncurrent pid: %d\n", getpid());
@@ -685,8 +684,8 @@ where (char *from)
{
register int i = 0, count = 0, j;
- for (j = 0; j < fcache->top; j++){
- char *token = strtok (fcache->domain[j], "&");
+ for (j = 0; j < SHM->top; j++){
+ char *token = strtok (SHM->domain[j], "&");
i = 0;
count = 0;
@@ -790,9 +789,9 @@ user_login ()
time (&now);
ptime = localtime (&now);
tmp = localtime (&cuser.lastlogin);
- if ((a = utmpshm->number) > fcache->max_user){
- fcache->max_user = a;
- fcache->max_time = now;
+ if ((a = SHM->UTMPnumber) > SHM->max_user){
+ SHM->max_user = a;
+ SHM->max_time = now;
}
init_brdbuf();
brc_initial (DEFAULT_BOARD);
diff --git a/mbbsd/menu.c b/mbbsd/menu.c
index cbdb0871..61bf8bda 100644
--- a/mbbsd/menu.c
+++ b/mbbsd/menu.c
@@ -1,4 +1,4 @@
-/* $Id: menu.c,v 1.9 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: menu.c,v 1.10 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
/* help & menu processring */
@@ -97,7 +97,6 @@ static int u_movie() {
}
void movie(int i) {
- extern struct pttcache_t *ptt;
static short history[MAX_HISTORY];
static char myweek[] = "天一二三四五六";
const char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"};
@@ -105,17 +104,17 @@ void movie(int i) {
int j;
if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) &&
- !ptt->busystate && ptt->max_film > 0) {
+ !SHM->Pbusystate && SHM->max_film > 0) {
if(currstat == PSALE) {
i = PSALE;
reload_money();
} else {
do {
if(!i)
- i = 1 + (int)(((float)ptt->max_film *
+ i = 1 + (int)(((float)SHM->max_film *
rand()) / (RAND_MAX + 1.0));
- for(j = ptt->max_history; j >= 0; j--)
+ for(j = SHM->max_history; j >= 0; j--)
if(i == history[j]) {
i = 0;
break;
@@ -123,15 +122,15 @@ void movie(int i) {
} while(i == 0);
}
- memcpy(history, &history[1], ptt->max_history * sizeof(short));
- history[ptt->max_history] = j = i;
+ memcpy(history, &history[1], SHM->max_history * sizeof(short));
+ history[SHM->max_history] = j = i;
if(i == 999) /* Goodbye my friend */
i = 0;
move(1, 0);
clrtoline(1 + FILMROW); /* 清掉上次的 */
- Jaky_outs(ptt->notes[i], 11); /* 只印11行就好 */
+ Jaky_outs(SHM->notes[i], 11); /* 只印11行就好 */
outs(reset_color);
}
i = ptime->tm_wday << 1;
@@ -140,8 +139,8 @@ void movie(int i) {
"\033[30m[扣機]\033[31m%s\033[0m",
ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1],
ptime->tm_hour, ptime->tm_min, currutmp->birth ?
- "生日要請客唷" : ptt->today_is,
- utmpshm->number, cuser.userid, msgs[currutmp->pager]);
+ "生日要請客唷" : SHM->today_is,
+ SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]);
outmsg(mystatus);
refresh();
}
diff --git a/mbbsd/name.c b/mbbsd/name.c
index b78b54d1..f2a0f704 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -1,4 +1,4 @@
-/* $Id: name.c,v 1.7 2002/06/04 13:08:34 in2 Exp $ */
+/* $Id: name.c,v 1.8 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
static word_t *current = NULL;
@@ -637,34 +637,34 @@ int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb,
/* general complete functions (brdshm) */
int completeboard_compar(int where, char *str, int len)
{
- return strncasecmp(brdshm->sorted[0][where]->brdname, str, len);
+ return strncasecmp(SHM->bsorted[0][where]->brdname, str, len);
}
int completeboard_permission(int where)
{
- return Ben_Perm(brdshm->sorted[0][where]);
+ return Ben_Perm(SHM->bsorted[0][where]);
}
char *completeboard_getname(int where)
{
- return brdshm->sorted[0][where]->brdname;
+ return SHM->bsorted[0][where]->brdname;
}
/* general complete functions (utmpshm) */
int completeutmp_compar(int where, char *str, int len)
{
- return strncasecmp(utmpshm->sorted[utmpshm->currsorted][0][where]->userid,
+ return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid,
str, len);
}
int completeutmp_permission(int where)
{
return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) ||
- !utmpshm->sorted[utmpshm->currsorted][0][where]->invisible);
+ !SHM->sorted[SHM->currsorted][0][where]->invisible);
}
char *completeutmp_getname(int where)
{
- return utmpshm->sorted[utmpshm->currsorted][0][where]->userid;
+ return SHM->sorted[SHM->currsorted][0][where]->userid;
}
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index e1feac1f..90b39eab 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -1,4 +1,4 @@
-/* $Id: talk.c,v 1.68 2002/06/05 03:22:43 ptt Exp $ */
+/* $Id: talk.c,v 1.69 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
#define QCAST int (*)(const void *, const void *)
@@ -215,13 +215,13 @@ int login_friend_online(void)
{
userinfo_t *uentp;
int i, stat, stat1;
- int offset=(int) (currutmp - &utmpshm->uinfo[0]);
- for (i=0;i<utmpshm->number && currutmp->friendtotal<MAX_FRIEND; i++){
- uentp = (utmpshm->sorted[utmpshm->currsorted][0][i]);
+ int offset=(int) (currutmp - &SHM->uinfo[0]);
+ for (i=0;i<SHM->UTMPnumber && currutmp->friendtotal<MAX_FRIEND; i++){
+ uentp = (SHM->sorted[SHM->currsorted][0][i]);
if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))){
stat1=reverse_friend_stat(stat);
stat <<= 24;
- stat |= (int) (uentp - &utmpshm->uinfo[0]);
+ stat |= (int) (uentp - &SHM->uinfo[0]);
currutmp->friend_online[currutmp->friendtotal++]=stat;
if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND){
stat1 <<= 24;
@@ -236,13 +236,13 @@ int login_friend_online(void)
int logout_friend_online(userinfo_t *utmp)
{
int i, j, k;
- int offset=(int) (utmp - &utmpshm->uinfo[0]);
+ int offset=(int) (utmp - &SHM->uinfo[0]);
userinfo_t *ui;
while( utmp->friendtotal > 0 ){
i = utmp->friendtotal-1;
j = (utmp->friend_online[i] & 0xFFFFFF);
utmp->friend_online[i]=0;
- ui = &utmpshm->uinfo[j];
+ ui = &SHM->uinfo[j];
if(ui->pid && ui!=utmp){
for(k=0; k<ui->friendtotal > 0 && k < MAX_FRIEND &&
(int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++);
@@ -268,7 +268,7 @@ int friend_stat(userinfo_t *me, userinfo_t * ui)
}
for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){
j = (me->friend_online[i] & 0xFFFFFF);
- if( 0 <= j && j < MAX_ACTIVE && ui == &utmpshm->uinfo[j] ){
+ if( 0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j] ){
hit |= me->friend_online[i] >>24;
break;
}
@@ -634,7 +634,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin)
if(flag == 3 && uin->msgcount) {
/* 不懂 */
- uin->destuip = currutmp - &utmpshm->uinfo[0];
+ uin->destuip = currutmp - &SHM->uinfo[0];
uin->sig = 2;
if(uin->pid > 0) kill(uin->pid, SIGUSR1);
} else if(flag != 2 &&
@@ -1185,7 +1185,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) {
currutmp->sockaddr = server.sin_port;
currutmp->destuid = uin->uid;
setutmpmode(PAGE);
- uin->destuip = currutmp - &utmpshm->uinfo[0];
+ uin->destuip = currutmp - &SHM->uinfo[0];
if(pid > 0) kill(pid, SIGUSR1);
clear();
prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid);
@@ -1197,7 +1197,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) {
if (ch == I_TIMEOUT){
ch = uin->mode;
if (!ch && uin->chatid[0] == 1 &&
- uin->destuip == currutmp - &utmpshm->uinfo[0]){
+ uin->destuip == currutmp - &SHM->uinfo[0]){
bell();
outmsg("對方回應中...");
refresh();
@@ -1223,7 +1223,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) {
outs("再");
bell();
- uin->destuip = currutmp - &utmpshm->uinfo[0];
+ uin->destuip = currutmp - &SHM->uinfo[0];
if(pid <= 0 || kill(pid, SIGUSR1) == -1){
#ifdef linux
add_io(sock, 20); /* added 4 linux... achen */
@@ -1421,8 +1421,7 @@ static char *friend_descript(char *uident) {
return space_buf;
}
-static char *descript(int show_mode, userinfo_t * uentp, time_t diff,
- fromcache_t * fcache)
+static char *descript(int show_mode, userinfo_t * uentp, time_t diff)
{
switch (show_mode){
case 1:
@@ -1431,7 +1430,7 @@ static char *descript(int show_mode, userinfo_t * uentp, time_t diff,
return (((uentp->pager != 2 && uentp->pager != 3 && diff) ||
HAS_PERM(PERM_SYSOP)) ?
#ifdef WHERE
- uentp->from_alias ? fcache->replace[uentp->from_alias] :
+ uentp->from_alias ? SHM->replace[uentp->from_alias] :
uentp->from
#else
uentp->from
@@ -1467,7 +1466,7 @@ int pickup_maxpages(int pickupway, int nfriends)
if( cuser.uflag & FRIEND_FLAG )
number = nfriends;
else
- number = utmpshm->number+
+ number = SHM->UTMPnumber+
(pickupway == 0 ? nfriends : 0);
return (number-1) / MAXPICKUP +1;
}
@@ -1482,7 +1481,7 @@ static int pickup_myfriend(pickup_t *friends,
for( i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){
where = currutmp->friend_online[i] & 0xFFFFFF;
if( 0 <= where && where < MAX_ACTIVE &&
- (uentp = &utmpshm->uinfo[where]) && uentp->pid &&
+ (uentp = &SHM->uinfo[where]) && uentp->pid &&
uentp != currutmp &&
isvisible_stat(currutmp, uentp,
frstate =
@@ -1524,8 +1523,8 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page,
int *nfriend, int *myfriend, int *friendme, int *bfriend)
{
/* avoid race condition */
- int currsorted = utmpshm->currsorted;
- int utmpnumber = utmpshm->number;
+ int currsorted = SHM->currsorted;
+ int utmpnumber = SHM->UTMPnumber;
int friendtotal= currutmp->friendtotal;
userinfo_t **utmp;
@@ -1564,7 +1563,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page,
if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP )
{
sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1));
- utmp = utmpshm->sorted[currsorted][sorted_way];
+ utmp = SHM->sorted[currsorted][sorted_way];
which = *page * MAXPICKUP-*nfriend;
if(which<0) which=0;
for(;which < utmpnumber && size < MAXPICKUP;which++)
@@ -1648,7 +1647,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way,
prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d"
"\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:"
"%-2d\033[m\n",
- msg_pickup_way[pickup_way], utmpshm->number,
+ msg_pickup_way[pickup_way], SHM->UTMPnumber,
myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0);
for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){
@@ -1715,7 +1714,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way,
/* from */
descript(show_mode, uentp,
- uentp->pager & !(friend&HRM), fcache),
+ uentp->pager & !(friend&HRM)),
/* board or mode */
#ifdef SHOWBOARD
@@ -1944,15 +1943,15 @@ static void userlist(void)
char swid[IDLEN + 1];
move(1, 0);
si = generalnamecomplete(msg_uid, swid,
- sizeof(swid), utmpshm->number,
+ sizeof(swid), SHM->UTMPnumber,
completeutmp_compar,
completeutmp_permission,
completeutmp_getname);
if( si >= 0 ){
pickup_t friends[MAX_FRIEND + 1];
int nGots, i;
- fi = utmpshm->sorted[utmpshm->currsorted][0][si] -
- &utmpshm->uinfo[0];
+ fi = SHM->sorted[SHM->currsorted][0][si] -
+ &SHM->uinfo[0];
nGots= pickup_myfriend(friends, &myfriend, &friendme);
for( i = 0 ; i < nGots ; ++i )
@@ -1987,7 +1986,7 @@ static void userlist(void)
case '9':
{ /* Thor: 可以打數字跳到該人 */
int tmp;
- if( (tmp = search_num(ch, utmpshm->number)) >= 0 ){
+ if( (tmp = search_num(ch, SHM->UTMPnumber)) >= 0 ){
if( tmp / 20 == page ){
/* in2:目的在目前這一頁, 直接
更新 offset , 不用重畫畫面 */
@@ -2046,8 +2045,8 @@ static void userlist(void)
*ans == 'n')
break;
if( HAS_PERM(PERM_SYSOP) ){
- for( i = 0 ; i < utmpshm->number && i<1000 ; ++i ){
- uentp = utmpshm->sorted[utmpshm->currsorted][0][i];
+ for( i = 0 ; i < SHM->UTMPnumber && i<1000 ; ++i ){
+ uentp = SHM->sorted[SHM->currsorted][0][i];
if( uentp->pid && kill(uentp->pid, 0) != -1 )
my_write(uentp->pid, genbuf,
uentp->userid, 1, NULL);
@@ -2060,7 +2059,7 @@ static void userlist(void)
i < MAX_FRIEND ; ++i ){
where = currutmp->friend_online[i] & 0xFFFFFF;
if( 0 <= where && where < MAX_ACTIVE &&
- (uentp = &utmpshm->uinfo[where]) &&
+ (uentp = &SHM->uinfo[where]) &&
uentp->pid &&
isvisible_stat(currutmp, uentp,
frstate =
@@ -2376,7 +2375,7 @@ int t_talk() {
*/
stand_title("打開話匣子");
generalnamecomplete(msg_uid, uident, sizeof(uident),
- utmpshm->number,
+ SHM->UTMPnumber,
completeutmp_compar,
completeutmp_permission,
completeutmp_getname);
@@ -2422,7 +2421,7 @@ void talkreply(void)
int a, sig = currutmp->sig;
talkrequest = NA;
- uip = &utmpshm->uinfo[currutmp->destuip];
+ uip = &SHM->uinfo[currutmp->destuip];
sprintf(page_requestor, "%s (%s)", uip->userid, uip->username);
currutmp->destuid = uip->uid;
currstat = XMODE; /* 避免出現動畫 */
@@ -2484,7 +2483,7 @@ void talkreply(void)
strcpy(genbuf, "不告訴你咧 !! ^o^");
write(a, genbuf, 60);
}
- uip->destuip = currutmp - &utmpshm->uinfo[0];
+ uip->destuip = currutmp - &SHM->uinfo[0];
if (buf[0] == 'y')
switch (sig){
case SIG_DARK:
diff --git a/mbbsd/user.c b/mbbsd/user.c
index 54a3a515..c7a5e455 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -1,4 +1,4 @@
-/* $Id: user.c,v 1.21 2002/06/04 13:08:34 in2 Exp $ */
+/* $Id: user.c,v 1.22 2002/06/06 21:34:11 in2 Exp $ */
#include "bbs.h"
static char *sex[8] = {
@@ -1107,7 +1107,7 @@ int u_list() {
setutmpmode(LAUSERS);
showrealname = u_list_special = usercounter = 0;
- totalusers = uhash->number;
+ totalusers = SHM->number;
if(HAS_PERM(PERM_SEEULEVELS)) {
getdata(b_lines - 1, 0, "觀看 [1]特殊等級 (2)全部?",
genbuf, 3, DOECHO);
diff --git a/mbbsd/var.c b/mbbsd/var.c
index 43dab291..123f7245 100644
--- a/mbbsd/var.c
+++ b/mbbsd/var.c
@@ -1,4 +1,4 @@
-/* $Id: var.c,v 1.6 2002/06/04 13:08:34 in2 Exp $ */
+/* $Id: var.c,v 1.7 2002/06/06 21:34:11 in2 Exp $ */
#define INCLUDE_VAR_H
#include "bbs.h"
@@ -307,12 +307,9 @@ int wmofo = -1;
/* cache.c */
int numboards = -1;
int *GLOBALVAR;
-uhash_t *uhash;
-bcache_t *brdshm;
-userinfo_t *currutmp;
+SHM_t *SHM;
boardheader_t *bcache;
-struct utmpfile_t *utmpshm;
-struct fromcache_t *fcache;
+userinfo_t *currutmp;
/* board.c */
int class_bid = 0;
diff --git a/util/BM_money.c b/util/BM_money.c
index a20dc5e3..0c1b029f 100644
--- a/util/BM_money.c
+++ b/util/BM_money.c
@@ -1,17 +1,8 @@
-/* $Id: BM_money.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */
+/* $Id: BM_money.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
/* 給版主錢的程式 */
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "common.h"
-#include "proto.h"
+#include "bbs.h"
#define FUNCTION (2100 - c*5)
diff --git a/util/Makefile b/util/Makefile
index c0616b7b..0fc23f70 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.11 2002/04/15 20:07:08 in2 Exp $
+# $Id: Makefile,v 1.12 2002/06/06 21:35:23 in2 Exp $
BBSHOME?=$(HOME)
OSTYPE?=linux
@@ -23,14 +23,14 @@ LDFLAGS=$(LDFLAGS_$(OSTYPE))
LIBMAIL=$(LIBMAIL_$(OSTYPE))
LIBCHAT=$(LIBCHAT_$(OSTYPE))
-OBJS= util_cache.o util_record.o util_passwd.o
+OBJS= util_cache.o util_record.o util_passwd.o
CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\
horoscope openvice parse_news openticket topusr yearsold uhash_loader\
poststat showboard antispam countalldice webgrep bbsrf\
initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\
merge_passwd merge_board inndBM buildAnnounce rmuid \
- toplazyBM jungo toplazyBBM shmctl mdclean
+ toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd
PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\
openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\
@@ -48,6 +48,9 @@ BM_money: BM_money.c $(OBJS)
post: post.c $(OBJS)
$(CC) $(CFLAGS) -o $@ $@.c $(OBJS)
+poststat: poststat.c $(OBJS)
+ $(CC) $(CFLAGS) -o $@ $@.c $(OBJS)
+
jungo: jungo.c $(OBJS)
$(CC) $(CFLAGS) -o $@ $@.c $(OBJS)
@@ -159,6 +162,9 @@ shmctl: shmctl.c $(OBJS)
mdclean: mdclean.c
$(CC) $(CFLAGS) -o $@ $@.c
+splitpasswd: splitpasswd.c
+ $(CC) $(CFLAGS) -o $@ $@.c
+
install: $(PROGS)
install -d $(BBSHOME)/bin/
install -c -m 755 $(PROGS) $(BBSHOME)/bin/
diff --git a/util/account.c b/util/account.c
index 9d8f6a05..cfc9f911 100644
--- a/util/account.c
+++ b/util/account.c
@@ -1,43 +1,31 @@
-/* $Id: account.c,v 1.4 2002/03/28 04:03:55 in2 Exp $ */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "proto.h"
+/* $Id: account.c,v 1.5 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
#define MAX_LINE 16
#define ADJUST_M 6 /* adjust back 5 minutes */
-extern struct pttcache_t *ptt;
-
void
- reset_garbage()
+reset_garbage()
{
- if (ptt == NULL)
+ if (SHM == NULL)
{
- ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt));
- if (ptt->touchtime == 0)
- ptt->touchtime = 1;
+ attach_SHM();
+ if (SHM->Ptouchtime == 0)
+ SHM->Ptouchtime = 1;
}
/* 不整個reload?
- for(n=0;n<=ptt->max_film;n++)
- printf("\n**%d**\n %s \n",n,ptt->notes[n]);
+ for(n=0;n<=SHM->max_film;n++)
+ printf("\n**%d**\n %s \n",n,SHM->notes[n]);
*/
- ptt->uptime = 0;
+ SHM->Puptime = 0;
reload_pttcache();
- printf("\n動態看板數[%d]\n", ptt->max_film);
+ printf("\n動態看板數[%d]\n", SHM->max_film);
/*
for(n=0; n<MAX_MOVIE_SECTION; n++)
- printf("sec%d=> 起點:%d 下次要換的:%d\n ",n,ptt->n_notes[n],
- ptt->next_refresh[n]);
+ printf("sec%d=> 起點:%d 下次要換的:%d\n ",n,SHM->n_notes[n],
+ SHM->next_refresh[n]);
printf("\n");
*/
}
@@ -230,11 +218,11 @@ int main() {
{
int a;
resolve_fcache();
- printf("此時段最多同時上線:%d 過去:%d\n", a = fcache->max_user, k);
+ printf("此時段最多同時上線:%d 過去:%d\n", a = SHM->max_user, k);
fclose(fp);
if (a > k)
{
- ptime = localtime(&fcache->max_time);
+ ptime = localtime(&SHM->max_time);
if((fp1 = fopen("etc/history", "a")))
{
fprintf(fp1,
@@ -292,7 +280,7 @@ int main() {
now = time(NULL) - ADJUST_M * 60; /* back to ancent */
ptime = localtime(&now);
- attach_uhash();
+ attach_SHM();
if((fp = fopen("etc/history.data", "r")))
{ /* 單日最多次人次,同時上線,註冊 */
if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k))
@@ -314,12 +302,12 @@ int main() {
max_login = total;
}
- if (uhash->number > max_reg + max_reg / 10)
+ if (SHM->number > max_reg + max_reg / 10)
{
fprintf(fp1, "★ 【%02d/%02d/%02d】 "
"總註冊人數提升到 %d 人 \n"
- ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, uhash->number);
- max_reg = uhash->number;
+ ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, SHM->number);
+ max_reg = SHM->number;
}
fclose(fp1);
@@ -410,7 +398,7 @@ int main() {
/* Ptt reset Ptt's share memory */
printf("重設Pttcache 與fcache\n");
- fcache->uptime = 0;
+ SHM->Puptime = 0;
resolve_fcache();
reset_garbage();
return 0;
diff --git a/util/bbsmail.c b/util/bbsmail.c
index 0afcdf7e..634b2991 100644
--- a/util/bbsmail.c
+++ b/util/bbsmail.c
@@ -1,19 +1,7 @@
-/* $Id: bbsmail.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */
+/* $Id: bbsmail.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */
#define _BBS_UTIL_C_
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "perm.h"
-#include "common.h"
-#include "proto.h"
+#include "bbs.h"
#define LOG_FILE (BBSHOME "/etc/mailog")
diff --git a/util/birth.c b/util/birth.c
index 89033830..5c13c54f 100644
--- a/util/birth.c
+++ b/util/birth.c
@@ -1,21 +1,12 @@
/* 壽星程式 96 10/11 */
-#include <stdio.h>
-#include <sys/types.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <time.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "common.h"
+#include "bbs.h"
#define OUTFILE BBSHOME "/etc/birth.today"
struct userec_t cuser;
-int bad_user_id() {
+int bad_user_id(char *userid) {
register char ch;
int j;
if (strlen(cuser.userid) < 2 || !isalpha(cuser.userid[0]))
@@ -68,7 +59,7 @@ int main(argc, argv)
fprintf(fp1, "【本日壽星】 \n");
for(j = 1; j <= MAX_USERS; j++) {
passwd_query(j, &cuser);
- if (bad_user_id())
+ if (bad_user_id(NULL))
continue;
if (cuser.month == ptime->tm_mon + 1)
{
diff --git a/util/buildAnnounce.c b/util/buildAnnounce.c
index cd4b9877..1db151f9 100644
--- a/util/buildAnnounce.c
+++ b/util/buildAnnounce.c
@@ -1,26 +1,18 @@
/* 建立所有看板精華區的連結 */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/stat.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "proto.h"
+#include "bbs.h"
#define GROUPROOT BBSHOME"/man/group"
-extern bcache_t *brdshm;
extern boardheader_t *bcache;
extern void resolve_boards();
extern int numboards;
-int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) {
- return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+
- strcasecmp((*brd)->brdname, (*tmp)->brdname);
+int cmpboardclass(const void *a, const void *b)
+{
+ boardheader_t **brd = (boardheader_t **)a;
+ boardheader_t **tmp = (boardheader_t **)b;
+ return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+
+ strcasecmp((*brd)->brdname, (*tmp)->brdname);
}
void buildchilds(int level,char *path,int gid)
{
@@ -31,7 +23,7 @@ void buildchilds(int level,char *path,int gid)
for(i=0; i<numboards; i++)
{
- ptr =&brdshm->bcache[i];
+ ptr =&SHM->bcache[i];
if(
ptr->gid != gid ||
(ptr->brdattr&(BRD_BAD | BRD_HIDE))!=0
@@ -41,7 +33,7 @@ void buildchilds(int level,char *path,int gid)
selected[count++]=ptr;
}
qsort(&selected, count, sizeof(boardheader_t *),
- cmpboardclass);
+ cmpboardclass);
for(i=0;i<count;i++)
{
ptr=selected[i];
diff --git a/util/deluserfile.c b/util/deluserfile.c
index 3cf226bb..543048d0 100644
--- a/util/deluserfile.c
+++ b/util/deluserfile.c
@@ -1,16 +1,7 @@
-/* $Id: deluserfile.c,v 1.2 2002/05/25 11:17:55 ptt Exp $ */
+/* $Id: deluserfile.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */
/* 自動砍user目錄檔案程式 */
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
+#include "bbs.h"
#define HOLDWRITELOG
#define DELZEROFILE
diff --git a/util/expire.c b/util/expire.c
index c74ac6bf..dc75a03a 100644
--- a/util/expire.c
+++ b/util/expire.c
@@ -1,21 +1,7 @@
-/* $Id: expire.c,v 1.3 2002/03/18 05:34:45 in2 Exp $ */
+/* $Id: expire.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
/* 自動砍信工具程式 */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "proto.h"
+#include "bbs.h"
#define QCAST int (*)(const void *, const void *)
diff --git a/util/horoscope.c b/util/horoscope.c
index c91db7cd..f1183591 100644
--- a/util/horoscope.c
+++ b/util/horoscope.c
@@ -1,10 +1,5 @@
-/* $Id: horoscope.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
-#include <stdio.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "common.h"
+/* $Id: horoscope.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
struct userec_t cuser;
diff --git a/util/inndBM.c b/util/inndBM.c
index 7a1f665c..17b6ce87 100644
--- a/util/inndBM.c
+++ b/util/inndBM.c
@@ -1,15 +1,6 @@
/* 依據 .BOARD檔 & newsfeeds.bbs 列出參與轉信的所有板資料 */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/stat.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "proto.h"
+#include "bbs.h"
#define INNDHOME BBSHOME"/innd"
@@ -18,7 +9,6 @@
#define INND_BADFEED INNDHOME "/badfeeds.bbs"
#define INND_SCRIPT INNDHOME "/bbsnnrpall.auto.sh"
-extern bcache_t *brdshm;
extern boardheader_t *bcache;
extern int numboards;
int istran[MAX_BOARD];
@@ -185,21 +175,21 @@ int main()
(bcache[i].brdattr & BRD_GROUPBOARD) ) continue;
if((bcache[i].brdattr & BRD_NOTRAN )&& istran[i])
{
- while(brdshm->busystate) {safe_sleep(1);}
- brdshm->busystate = 1;
+ while(SHM->Bbusystate) {safe_sleep(1);}
+ SHM->Bbusystate = 1;
bcache[i].brdattr = bcache[i].brdattr & ~BRD_NOTRAN;
strncpy(bcache[i].title + 5, "●", 2);
- brdshm->busystate = 0;
+ SHM->Bbusystate = 0;
substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1);
}
else if(!(bcache[i].brdattr & BRD_NOTRAN) && !istran[i])
{
- while(brdshm->busystate) {safe_sleep(1);}
- brdshm->busystate = 1;
+ while(SHM->Bbusystate) {safe_sleep(1);}
+ SHM->Bbusystate = 1;
bcache[i].brdattr = bcache[i].brdattr | BRD_NOTRAN;
strncpy(bcache[i].title + 5, "◎", 2);
- brdshm->busystate = 0;
+ SHM->Bbusystate = 0;
substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1);
}
diff --git a/util/jungo.c b/util/jungo.c
index 8a46f22a..17a01a10 100644
--- a/util/jungo.c
+++ b/util/jungo.c
@@ -1,16 +1,5 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "perm.h"
-#include "common.h"
-#include "proto.h"
+/* $Id: jungo.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
#define OUTFILE BBSHOME "/etc/toplazyBBM"
#define FIREFILE BBSHOME "/etc/topfireBBM"
diff --git a/util/mandex.c b/util/mandex.c
index fd005924..8b073ea2 100644
--- a/util/mandex.c
+++ b/util/mandex.c
@@ -1,19 +1,8 @@
-/* $Id: mandex.c,v 1.3 2002/03/11 11:18:19 in2 Exp $ */
+/* $Id: mandex.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
/* 'mandex -h' to help */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-
+#include "bbs.h"
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
diff --git a/util/openticket.c b/util/openticket.c
index 250d2238..33a8a54f 100644
--- a/util/openticket.c
+++ b/util/openticket.c
@@ -1,15 +1,6 @@
-/* $Id: openticket.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */
+/* $Id: openticket.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
/* 開獎的 utility */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "common.h"
-#include "util.h"
-#include "proto.h"
+#include "bbs.h"
static char *betname[8] = {"Ptt", "Jaky", "Action", "Heat",
"DUNK", "Jungo", "waiting", "wofe"};
@@ -49,7 +40,6 @@ int main()
time_t now = time(NULL);
char des[MAX_DES][200] =
{"", "", "", ""};
- extern struct utmpfile_t *utmpshm;
if(passwd_mmap())
exit(1);
@@ -103,7 +93,7 @@ int main()
*/
resolve_utmp();
- bet = utmpshm->number % 8;
+ bet = SHM->number % 8;
/*
diff --git a/util/openvice.c b/util/openvice.c
index 9b5e438f..b622eb55 100644
--- a/util/openvice.c
+++ b/util/openvice.c
@@ -1,14 +1,7 @@
-/* $Id: openvice.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
+/* $Id: openvice.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */
/* 發票開獎小程式 */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
+#include "bbs.h"
#define VICE_SHOW BBSHOME "/etc/vice.show1"
#define VICE_BINGO BBSHOME "/etc/vice.bingo"
@@ -26,10 +19,9 @@ int main()
FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w");
- extern struct utmpfile_t *utmpshm;
resolve_utmp();
- srand(utmpshm->number);
+ srand(SHM->number);
if (!fp || !fb )
perror("error open file");
diff --git a/util/parse_news.c b/util/parse_news.c
index 18fcd654..042cf107 100644
--- a/util/parse_news.c
+++ b/util/parse_news.c
@@ -1,14 +1,5 @@
-/* $Id: parse_news.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
+/* $Id: parse_news.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
#define NEWSDIRECT BBSHOME "/boards/n/newspaper"
#define MOVIEDIRECT BBSHOME "/etc/NEWS"
diff --git a/util/post.c b/util/post.c
index e14a0814..0d93e0a0 100644
--- a/util/post.c
+++ b/util/post.c
@@ -1,12 +1,5 @@
-/* $Id: post.c,v 1.3 2002/03/09 17:44:30 in2 Exp $ */
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <time.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "proto.h"
+/* $Id: post.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) {
fileheader_t fhdr;
diff --git a/util/poststat.c b/util/poststat.c
index 2577f770..9ae3b477 100644
--- a/util/poststat.c
+++ b/util/poststat.c
@@ -1,21 +1,7 @@
-/* $Id: poststat.c,v 1.2 2002/04/05 14:36:25 in2 Exp $ */
+/* $Id: poststat.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */
/* 統計今日、週、月、年熱門話題 */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-
-#ifdef __FreeBSD__
-#include <machine/param.h>
-#endif
-
-#include "config.h"
-#include "pttstruct.h"
+#include "bbs.h"
char *myfile[] =
{"day", "week", "month", "year"};
@@ -73,96 +59,6 @@ int Rename(char *src, char *dst)
return 0;
}
-
-
-/*-------------------------------------------------------*/
-/* .BOARDS cache */
-/*-------------------------------------------------------*/
-
-struct bcache_t *brdshm;
-boardheader_t *bcache;
-int numboards = -1;
-
-
-static void
-attach_err(shmkey, name)
- int shmkey;
- char *name;
-{
- fprintf(stderr, "[%s error] key = %x\n", name, shmkey);
- exit(1);
-}
-
-
-static void *
-attach_shm(shmkey, shmsize)
- int shmkey, shmsize;
-{
- void *shmptr;
- int shmid;
-
- 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");
- memset(shmptr, 0, shmsize);
- }
- else
- {
- shmptr = (void *) shmat(shmid, NULL, 0);
- if (shmptr == (void *) -1)
- attach_err(shmkey, "shmat");
- }
- return shmptr;
-}
-
-
-
-void
-resolve_boards()
-{
- if (brdshm == NULL)
- {
- brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm));
- if (brdshm->touchtime == 0)
- brdshm->touchtime = 1;
- bcache = brdshm->bcache;
- }
-
- while (brdshm->uptime < brdshm->touchtime)
- {
- if (brdshm->busystate)
- {
- sleep(1);
- }
- else
- {
- int fd;
-
- brdshm->busystate = 1;
-
- if ((fd = open(".BRD", O_RDONLY)) > 0)
- {
- brdshm->number = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t))
- / sizeof(boardheader_t);
- close(fd);
- }
-
- /* 等所有 boards 資料更新後再設定 uptime */
-
- brdshm->uptime = brdshm->touchtime;
- brdshm->busystate = 0;
- }
- }
- numboards = brdshm->number;
-}
-
-
int
ci_strcmp(s1, s2)
register char *s1, *s2;
@@ -185,46 +81,6 @@ ci_strcmp(s1, s2)
}
int
-get_record(fpath, rptr, size, id)
- char *fpath;
- char *rptr;
- int size, id;
-{
- int fd;
-
- if ((fd = open(fpath, O_RDONLY, 0)) != -1)
- {
- if (lseek(fd, size * (id - 1), SEEK_SET) != -1)
- {
- if (read(fd, rptr, size) == size)
- {
- close(fd);
- return 0;
- }
- }
- close(fd);
- }
- return -1;
-}
-
-
-int
-getbnum(bname)
- char *bname;
-{
- register int i;
- register boardheader_t *bhdr;
-
- resolve_boards();
- for (i = 0, bhdr = bcache; i++ < numboards; bhdr++)
- /* if (Ben_Perm(bhdr)) */
- if (!ci_strcmp(bname, bhdr->brdname))
- return i;
- return 0;
-}
-
-
-int
hash(key)
char *key;
{
diff --git a/util/reaper.c b/util/reaper.c
index 925ea11b..d605bb70 100644
--- a/util/reaper.c
+++ b/util/reaper.c
@@ -1,16 +1,5 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <time.h>
-#include <syslog.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "perm.h"
-#include "util.h"
+/* $Id: reaper.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
time_t now;
diff --git a/util/rmuid.c b/util/rmuid.c
index c936d160..901a31c8 100644
--- a/util/rmuid.c
+++ b/util/rmuid.c
@@ -1,14 +1,5 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
+/* $Id: rmuid.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
extern int numboards;
extern boardheader_t *bcache;
diff --git a/util/shmctl.c b/util/shmctl.c
index 7f2aae98..e264eb48 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -1,25 +1,12 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/shm.h>
-#include <errno.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "proto.h"
+/* $Id: shmctl.c,v 1.19 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
-extern struct utmpfile_t *utmpshm;
-extern struct pttcache_t *ptt;
-extern bcache_t *brdshm;
+extern SHM_t *SHM;
int logout_friend_online(userinfo_t *utmp)
{
int i, j, k;
- int offset=(int) (utmp - &utmpshm->uinfo[0]);
+ int offset=(int) (utmp - &SHM->uinfo[0]);
userinfo_t *ui;
while(utmp->friendtotal){
i = utmp->friendtotal-1;
@@ -28,7 +15,7 @@ int logout_friend_online(userinfo_t *utmp)
printf("\tonline friend error(%d)\n", j);
else{
utmp->friend_online[i]=0;
- ui = &utmpshm->uinfo[j];
+ ui = &SHM->uinfo[j];
if(ui->pid && ui!=utmp){
for(k=0; k<ui->friendtotal &&
(int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++);
@@ -72,58 +59,58 @@ int utmpfix(int argc, char **argv)
time(&now);
for( i = 0 ; i < 5 ; ++i )
- if( !utmpshm->busystate )
+ if( !SHM->UTMPbusystate )
break;
else{
puts("utmpshm is busy....");
sleep(1);
}
printf("starting scaning... %s \n", (fast ? "(fast mode)" : ""));
- utmpshm->busystate = 1;
+ SHM->UTMPbusystate = 1;
for( i = 0 ; i < USHM_SIZE ; ++i )
- if( utmpshm->uinfo[i].pid ){
+ if( SHM->uinfo[i].pid ){
clean = NULL;
- if( !isalpha(utmpshm->uinfo[i].userid[0]) )
+ if( !isalpha(SHM->uinfo[i].userid[0]) )
clean = "userid error";
- else if( kill(utmpshm->uinfo[i].pid, 0) < 0 ){
+ else if( kill(SHM->uinfo[i].pid, 0) < 0 ){
clean = "process error";
- purge_utmp(&utmpshm->uinfo[i]);
+ purge_utmp(&SHM->uinfo[i]);
}
else if( !fast ){
#ifdef DOTIMEOUT
- if( now - utmpshm->uinfo[i].lastact >
+ if( now - SHM->uinfo[i].lastact >
(timeout == -1 ? IDLE_TIMEOUT : timeout) ){
sprintf(buf, "timeout(%s",
- ctime(&utmpshm->uinfo[i].lastact));
+ ctime(&SHM->uinfo[i].lastact));
buf[strlen(buf) - 1] = 0;
strcat(buf, ")");
clean = buf;
- kill(utmpshm->uinfo[i].pid, SIGHUP);
- purge_utmp(&utmpshm->uinfo[i]);
+ kill(SHM->uinfo[i].pid, SIGHUP);
+ purge_utmp(&SHM->uinfo[i]);
}
else
#endif
- if( searchuser(utmpshm->uinfo[i].userid) == 0 ){
+ if( searchuser(SHM->uinfo[i].userid) == 0 ){
clean = "user not exist";
}
}
if( clean ){
printf("clean %06d(%s), userid: %s\n",
- i, clean, utmpshm->uinfo[i].userid);
- memset(&utmpshm->uinfo[i], 0, sizeof(userinfo_t));
+ i, clean, SHM->uinfo[i].userid);
+ memset(&SHM->uinfo[i], 0, sizeof(userinfo_t));
}
- else if ( utmpshm->uinfo[i].mind > 40 ){
+ else if ( SHM->uinfo[i].mind > 40 ){
printf("mind fix: %06d, userid: %s, mind: %d\n",
- i, utmpshm->uinfo[i].userid, utmpshm->uinfo[i].mind);
- utmpshm->uinfo[i].mind %= 40;
+ i, SHM->uinfo[i].userid, SHM->uinfo[i].mind);
+ SHM->uinfo[i].mind %= 40;
}
}
- utmpshm->busystate = 0;
+ SHM->UTMPbusystate = 0;
return 0;
}
-char *CTIME(char *buf, time_t t)
+char *CTIMEx(char *buf, time_t t)
{
strcpy(buf, ctime(&t));
buf[strlen(buf) - 1] = 0;
@@ -135,19 +122,19 @@ int utmpstate(int argc, char **argv)
time_t now;
char upbuf[64], nowbuf[64];
now = time(NULL);
- CTIME(upbuf, utmpshm->uptime);
- CTIME(nowbuf, time(NULL));
+ CTIMEx(upbuf, SHM->UTMPuptime);
+ CTIMEx(nowbuf, time(NULL));
printf("now: %s\n", nowbuf);
- printf("currsorted: %d\n", utmpshm->currsorted);
+ printf("currsorted: %d\n", SHM->currsorted);
printf("uptime: %s\n", upbuf);
- printf("number: %d\n", utmpshm->number);
- printf("busystate: %d\n", utmpshm->busystate);
+ printf("number: %d\n", SHM->number);
+ printf("busystate: %d\n", SHM->UTMPbusystate);
return 0;
}
int utmpreset(int argc, char **argv)
{
- utmpshm->busystate=0;
+ SHM->UTMPbusystate=0;
utmpstate(0, NULL);
return 0;
}
@@ -200,44 +187,44 @@ int utmpsort(int argc, char **argv)
int count, i, ns;
userinfo_t *uentp;
- if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)){
+ if(now-SHM->UTMPuptime<60 && (now==SHM->UTMPuptime || SHM->UTMPbusystate)){
puts("lazy sort");
//return; /* lazy sort */
}
- utmpshm->busystate=1;
- utmpshm->uptime = now;
- ns=(utmpshm->currsorted?0:1);
+ SHM->UTMPbusystate=1;
+ SHM->UTMPuptime = now;
+ ns=(SHM->currsorted?0:1);
- for(uentp = &utmpshm->uinfo[0], count=0, i=0;
- i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i])
+ for(uentp = &SHM->uinfo[0], count=0, i=0;
+ i< USHM_SIZE; i++,uentp = &SHM->uinfo[i])
if(uentp->pid){
- utmpshm->sorted[ns][0][count++]= uentp;
+ SHM->sorted[ns][0][count++]= uentp;
}
- utmpshm->number = count;
- qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid);
- memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0],
+ SHM->number = count;
+ qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid);
+ memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0],
+ memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0],
sizeof(userinfo_t *)*count);
- qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode );
- qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle );
- qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom );
- qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive );
- //qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex );
- qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid );
- qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid );
- utmpshm->currsorted=ns;
- utmpshm->busystate=0;
+ 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 *), cmputmpsex );
+ qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid );
+ qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid );
+ SHM->currsorted=ns;
+ SHM->UTMPbusystate=0;
puts("new utmpstate");
utmpstate(0, NULL);
@@ -252,13 +239,13 @@ int utmpwatch(int argc, char **argv)
while( 1 ){
for( i = 0 ; i < TIMES ; ++i ){
usleep(300);
- if( !utmpshm->busystate )
+ if( !SHM->UTMPbusystate )
break;
puts("busying...");
}
if( i == TIMES ){
puts("reset!");
- utmpshm->busystate = 0;
+ SHM->UTMPbusystate = 0;
}
}
return 0;
@@ -266,7 +253,7 @@ int utmpwatch(int argc, char **argv)
int utmpnum(int argc, char **argv)
{
- printf("%d.0\n", utmpshm->number);
+ printf("%d.0\n", SHM->number);
return 0;
}
@@ -274,7 +261,7 @@ int showglobal(int argc, char **argv)
{
int i;
for( i = 0 ; i < 10 ; ++i )
- printf("GLOBALVAR[%d] = %d\n", i, ptt->GLOBALVAR[i]);
+ printf("GLOBALVAR[%d] = %d\n", i, SHM->GLOBALVAR[i]);
return 0;
}
@@ -288,8 +275,8 @@ int setglobal(int argc, char **argv)
puts("only GLOBALVAR[0] ~ GLOBALVAR[9]");
return 1;
}
- printf("GLOBALVAR[%d] = %d -> ", where, ptt->GLOBALVAR[where]);
- printf("%d\n", ptt->GLOBALVAR[where] = atoi(argv[2]));
+ printf("GLOBALVAR[%d] = %d -> ", where, SHM->GLOBALVAR[where]);
+ printf("%d\n", SHM->GLOBALVAR[where] = atoi(argv[2]));
return 0;
}
@@ -299,14 +286,14 @@ int fixbfriend(int argc, char **argv)
int count, i;
for( i = 0 ; i < MAX_BOARD ; ++i ){
- if( isdigit(brdshm->bcache[i].brdname[0]) ||
- isalpha(brdshm->bcache[i].brdname[0]) ){
- for( count = 0, ptr = brdshm->bcache[i].u ;
+ if( isdigit(SHM->bcache[i].brdname[0]) ||
+ isalpha(SHM->bcache[i].brdname[0]) ){
+ for( count = 0, ptr = SHM->bcache[i].u ;
ptr != NULL && count < 256 ;
++count, ptr = ptr->nextbfriend )
;
- printf("counting %s\n", brdshm->bcache[i].brdname);
- brdshm->bcache[i].nuser = ((count == 256) ? 0 : count);
+ printf("counting %s\n", SHM->bcache[i].brdname);
+ SHM->bcache[i].nuser = ((count == 256) ? 0 : count);
}
}
@@ -319,10 +306,10 @@ struct {
} cmd[] =
{ {utmpfix, "utmpfix", "clear dead userlist entry"},
{utmpstate, "utmpstate", "list utmpstate"},
- {utmpreset, "utmpreset", "utmpshm->busystate=0"},
+ {utmpreset, "utmpreset", "SHM->busystate=0"},
{utmpsort, "utmpsort", "sort ulist"},
{utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"},
- {utmpnum, "utmpnum", "print utmpshm->number for snmpd"},
+ {utmpnum, "utmpnum", "print SHM->number for snmpd"},
{showglobal, "showglobal", "show GLOBALVAR[]"},
{setglobal, "setglobal", "set GLOBALVAR[]"},
{fixbfriend, "fixbfriend", "recount numbers of board friends"},
@@ -334,7 +321,7 @@ int main(int argc, char **argv)
if( argc >= 2 ){
/* shmctl shouldn't create shm itself */
- int shmid = shmget(UHASH_KEY, sizeof(uhash_t), 0);
+ int shmid = shmget(SHM_KEY, sizeof(SHM_t), 0);
if( shmid < 0 ){
printf("%d\n", errno);
perror("attach utmpshm");
diff --git a/util/shmsweep.c b/util/shmsweep.c
index 01acb26b..94d5291a 100644
--- a/util/shmsweep.c
+++ b/util/shmsweep.c
@@ -8,6 +8,7 @@
#include "pttstruct.h"
int main() {
+#if 0
int i, shm, counter;
struct utmpfile_t *utmpshm;
@@ -25,7 +26,7 @@ int main() {
}
for(i = counter = 0; i < USHM_SIZE; i++)
- if(utmpshm->uinfo[i].pid) {
+ if(SHM->uinfo[i].pid) {
char buf[256];
userinfo_t *f;
struct stat sb;
@@ -39,5 +40,6 @@ int main() {
}
}
printf("clear %d slots\n", counter);
+#endif
return 0;
}
diff --git a/util/smtest.c b/util/smtest.c
index 9059c419..f211cb3a 100644
--- a/util/smtest.c
+++ b/util/smtest.c
@@ -1,16 +1,5 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "perm.h"
-#include "common.h"
-#include "proto.h"
+/* $Id: smtest.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
#define WARNFILE BBSHOME "/etc/DeleteBoard.warn"
#define EXECFILE BBSHOME"/etc/DeleteBoard.exec"
diff --git a/util/toplazyBBM.c b/util/toplazyBBM.c
index 1341c17a..90f6ee2c 100644
--- a/util/toplazyBBM.c
+++ b/util/toplazyBBM.c
@@ -1,16 +1,5 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "perm.h"
-#include "common.h"
-#include "proto.h"
+/* $Id: toplazyBBM.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
#define OUTFILE BBSHOME "/etc/toplazyBBM"
#define FIREFILE BBSHOME "/etc/topfireBBM"
diff --git a/util/toplazyBM.c b/util/toplazyBM.c
index 0aba0560..3494eb07 100644
--- a/util/toplazyBM.c
+++ b/util/toplazyBM.c
@@ -1,17 +1,5 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "perm.h"
-#include "common.h"
-#include "proto.h"
-#include "modes.h"
+/* $Id: toplazyBM.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */
+#include "bbs.h"
#define OUTFILE BBSHOME "/etc/toplazyBM"
diff --git a/util/topusr.c b/util/topusr.c
index 22b95e94..0f64777d 100644
--- a/util/topusr.c
+++ b/util/topusr.c
@@ -1,15 +1,7 @@
-/* $Id: topusr.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
+/* $Id: topusr.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */
/* 使用者 上站記錄/文章篇數 排行榜 */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "perm.h"
-#include "common.h"
-#include "util.h"
+#include "bbs.h"
#define REAL_INFO
struct manrec
diff --git a/util/uhash_loader.c b/util/uhash_loader.c
index 1a963829..5fadd48e 100644
--- a/util/uhash_loader.c
+++ b/util/uhash_loader.c
@@ -1,4 +1,4 @@
-/* $Id: uhash_loader.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */
+/* $Id: uhash_loader.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */
/* standalone uhash loader -- jochang */
#include <stdio.h>
#include <unistd.h>
@@ -24,7 +24,7 @@ void add_to_uhash(int n, userec_t *id);
void fill_uhash(void);
void load_uhash(void);
-uhash_t *uhash;
+SHM_t *SHM;
int main() {
setgid(BBSGID);
@@ -36,7 +36,7 @@ int main() {
void load_uhash(void) {
int shmid;
- shmid = shmget(UHASH_KEY, sizeof(uhash_t), IPC_CREAT | 0600);
+ shmid = shmget(SHM_KEY, sizeof(SHM_t), IPC_CREAT | 0600);
/* note we didn't use IPC_EXCL here.
so if the loading fails,
(like .PASSWD doesn't exist)
@@ -48,20 +48,20 @@ void load_uhash(void) {
exit(1);
}
- uhash = (void *) shmat(shmid, NULL, 0);
- if (uhash == (void *) -1)
+ SHM = (void *) shmat(shmid, NULL, 0);
+ if (SHM == (void *) -1)
{
perror("shmat");
exit(1);
}
/* in case it's not assumed zero, this becomes a race... */
- uhash->loaded = 0;
+ SHM->loaded = 0;
fill_uhash();
/* ok... */
- uhash->loaded = 1;
+ SHM->loaded = 1;
}
void fill_uhash(void)
@@ -70,7 +70,7 @@ void fill_uhash(void)
usernumber = 0;
for (fd = 0; fd < (1 << HASH_BITS); fd++)
- uhash->hash_head[fd] = -1;
+ SHM->hash_head[fd] = -1;
if ((fd = open(FN_PASSWD, O_RDONLY)) > 0)
{
@@ -101,7 +101,7 @@ void fill_uhash(void)
perror("open");
exit(1);
}
- uhash->number = usernumber;
+ SHM->number = usernumber;
printf("total %d names loaded.\n", usernumber);
}
unsigned string_hash(unsigned char *s)
@@ -118,12 +118,12 @@ unsigned string_hash(unsigned char *s)
void add_to_uhash(int n, userec_t *user)
{
int *p, h = string_hash(user->userid);
- strcpy(uhash->userid[n], user->userid);
- uhash->money[n] = user->money;
- p = &(uhash->hash_head[h]);
+ strcpy(SHM->userid[n], user->userid);
+ SHM->money[n] = user->money;
+ p = &(SHM->hash_head[h]);
while (*p != -1)
- p = &(uhash->next_in_hash[*p]);
+ p = &(SHM->next_in_hash[*p]);
- uhash->next_in_hash[*p = n] = -1;
+ SHM->next_in_hash[*p = n] = -1;
}
diff --git a/util/userlist.c b/util/userlist.c
index 9a142926..c8d53389 100644
--- a/util/userlist.c
+++ b/util/userlist.c
@@ -7,40 +7,39 @@
#include "config.h"
#include "pttstruct.h"
-struct utmpfile_t *u;
+SHM_t *SHM;
int main(int argc, char **argv) {
int i, shm, counter;
- shm = shmget(UTMPSHM_KEY, USHM_SIZE, SHM_R | SHM_W);
+ shm = shmget(SHM_KEY, USHM_SIZE, SHM_R | SHM_W);
if(shm == -1) {
perror("shmget");
exit(0);
}
- u = shmat(shm, NULL, 0);
- if(u == (struct utmpfile_t *)-1) {
+ if( (SHM = shmat(shm, NULL, 0)) < 0 ){
perror("shmat");
exit(0);
}
if(argc > 1) {
for(i = 1; i < argc; i++)
- u->uinfo[atoi(argv[i])].pid = 0;
+ SHM->uinfo[atoi(argv[i])].pid = 0;
} else {
for(i = counter = 0; i < USHM_SIZE; i++)
- if(u->uinfo[i].pid) {
+ if(SHM->uinfo[i].pid) {
userinfo_t *f;
- f = &u->uinfo[i];
+ f = &SHM->uinfo[i];
printf(
"%4d(%d) p[%d] i[%d] u[%s] n[%s] f[%s] m[%d] d[%d] t[%ld]\n",
++counter, i, f->pager, f->invisible, f->userid,
f->username, f->from, f->mode, f->mind, f->lastact);
}
- printf("\nTotal: %d(%d)\n", counter, u->number);
- if(counter != u->number) {
- u->number = counter;
+ printf("\nTotal: %d(%d)\n", counter, SHM->number);
+ if(counter != SHM->number) {
+ SHM->number = counter;
printf("adjust user number!\n");
}
}
diff --git a/util/util_cache.c b/util/util_cache.c
index 0e1ab5a1..7f4b0897 100644
--- a/util/util_cache.c
+++ b/util/util_cache.c
@@ -1,4 +1,4 @@
-/* $Id: util_cache.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */
+/* $Id: util_cache.c,v 1.3 2002/06/06 21:34:15 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -26,8 +26,6 @@
#include "modes.h"
#include "proto.h"
-int fcache_semid;
-
/* 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. */
@@ -140,40 +138,43 @@ void sem_lock(int op,int semid) {
semop(semid, &sops, 1);
}
-/* uhash *******************************************/
-/* the design is this:
- we use another stand-alone program to create and load data into the hash.
- (that program could be run in rc-scripts or something like that)
- after loading completes, the stand-alone program sets loaded to 1 and exits.
-
- the bbs exits if it can't attach to the shared memory or
- the hash is not loaded yet.
-*/
-uhash_t *uhash;
+SHM_t *SHM;
+int *GLOBALVAR;
+boardheader_t *bcache;
+
+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;
+}
int setumoney(int uid, int money) {
- uhash->money[uid-1]=money;
+ SHM->money[uid-1]=money;
passwd_update_money(uid);
- return uhash->money[uid-1];
+ return SHM->money[uid-1];
}
int deumoney(int uid, int money) {
- if(money<0 && uhash->money[uid-1]<-money)
+ if(money<0 && SHM->money[uid-1]<-money)
return setumoney(uid,0);
else
- return setumoney(uid,uhash->money[uid-1]+money);
+ return setumoney(uid,SHM->money[uid-1]+money);
}
int moneyof(int uid){ /* ptt 改進金錢處理效率 */
- return uhash->money[uid-1];
-}
-/* attach_uhash should be called before using uhash */
-void attach_uhash() {
- uhash = attach_shm(UHASH_KEY, sizeof(*uhash));
- if(!uhash->loaded) /* assume fresh shared memory is zeroed */
- exit(1);
+ return SHM->money[uid-1];
}
-
static unsigned string_hash(unsigned char *s) {
unsigned int v=0;
while(*s) {
@@ -185,43 +186,43 @@ static unsigned string_hash(unsigned char *s) {
void add_to_uhash(int n, char *id) {
int *p, h = string_hash(id);
- strcpy(uhash->userid[n], id);
+ strcpy(SHM->userid[n], id);
- p = &(uhash->hash_head[h]);
+ p = &(SHM->hash_head[h]);
while(*p != -1)
- p = &(uhash->next_in_hash[*p]);
+ p = &(SHM->next_in_hash[*p]);
- uhash->next_in_hash[*p = n] = -1;
+ 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(uhash->userid[n]);
- int *p = &(uhash->hash_head[h]);
+ int h = string_hash(SHM->userid[n]);
+ int *p = &(SHM->hash_head[h]);
while(*p != -1 && *p != n)
- p = &(uhash->next_in_hash[*p]);
+ p = &(SHM->next_in_hash[*p]);
if(*p == n)
- *p = uhash->next_in_hash[n];
+ *p = SHM->next_in_hash[n];
}
int searchuser(char *userid) {
int h,p;
- if(uhash == NULL)
- attach_uhash(); /* for sloopy util programs */
+ if(SHM == NULL)
+ attach_SHM(); /* for sloopy util programs */
h = string_hash(userid);
- p = uhash->hash_head[h];
+ p = SHM->hash_head[h];
while(p != -1) {
- if(strcasecmp(uhash->userid[p],userid) == 0) {
- strcpy(userid,uhash->userid[p]);
+ if(strcasecmp(SHM->userid[p],userid) == 0) {
+ strcpy(userid,SHM->userid[p]);
return p + 1;
}
- p = uhash->next_in_hash[p];
+ p = SHM->next_in_hash[p];
}
return 0;
}
@@ -233,10 +234,11 @@ int getuser(char *userid) {
passwd_query(uid, &xuser);
return uid;
}
+
void setuserid(int num, char *userid) {
if(num > 0 && num <= MAX_USERS) {
- if(num > uhash->number)
- uhash->number = num;
+ if(num > SHM->number)
+ SHM->number = num;
else
remove_from_uhash(num-1);
add_to_uhash(num-1,userid);
@@ -246,13 +248,11 @@ void setuserid(int num, char *userid) {
/*-------------------------------------------------------*/
/* .UTMP cache */
/*-------------------------------------------------------*/
-struct utmpfile_t *utmpshm=NULL;
-
void resolve_utmp() {
- if(utmpshm == NULL) {
- utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm));
- if(utmpshm->uptime == 0)
- utmpshm->uptime = utmpshm->number = 1;
+ if(SHM == NULL) {
+ attach_SHM();
+ if(SHM->UTMPuptime == 0)
+ SHM->UTMPuptime = SHM->UTMPnumber = 1;
}
}
@@ -266,11 +266,11 @@ void getnewutmpent(userinfo_t *up) {
resolve_utmp();
for(i = 0; i < USHM_SIZE; i++) {
- uentp = &(utmpshm->uinfo[i]);
+ uentp = &(SHM->uinfo[i]);
if(!(uentp->pid)) {
memcpy(uentp, up, sizeof(userinfo_t));
currutmp = uentp;
- utmpshm->number++;
+ SHM->number++;
return;
}
}
@@ -283,7 +283,7 @@ int apply_ulist(int (*fptr)(userinfo_t *)) {
resolve_utmp();
for(i = 0; i < USHM_SIZE; i++) {
- uentp = &(utmpshm->uinfo[i]);
+ uentp = &(SHM->uinfo[i]);
if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp)))
if((state = (*fptr) (uentp)))
return state;
@@ -297,7 +297,7 @@ userinfo_t *search_ulist(int uid) {
resolve_utmp();
for(i = 0; i < USHM_SIZE; i++) {
- uentp = &(utmpshm->uinfo[i]);
+ uentp = &(SHM->uinfo[i]);
if(uid==uentp->uid)
return uentp;
}
@@ -308,11 +308,10 @@ userinfo_t *search_ulist(int uid) {
/* .BOARDS cache */
/*-------------------------------------------------------*/
char *fn_board=FN_BOARD;
-bcache_t *brdshm;
boardheader_t *bcache;
static void reload_bcache() {
- if(brdshm->busystate) {
+ if(SHM->Bbusystate) {
safe_sleep(1);
}
}
@@ -320,20 +319,20 @@ static void reload_bcache() {
int numboards = -1;
void resolve_boards() {
- if(brdshm == NULL) {
- brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm));
- if(brdshm->touchtime == 0)
- brdshm->touchtime = 1;
- bcache = brdshm->bcache;
+ if(SHM == NULL) {
+ attach_SHM();
+ if(SHM->Btouchtime == 0)
+ SHM->Btouchtime = 1;
+ bcache = SHM->bcache;
}
- while(brdshm->uptime < brdshm->touchtime)
+ while(SHM->Buptime < SHM->Btouchtime)
reload_bcache();
- numboards = brdshm->number;
+ numboards = SHM->number;
}
void touch_boards() {
- time(&(brdshm->touchtime));
+ time(&(SHM->Btouchtime));
numboards = -1;
resolve_boards();
}
@@ -341,15 +340,15 @@ void reset_board(int bid)
{
int fd;
if(--bid<0)return;
- if(brdshm->busystate==0)
+ if(SHM->Bbusystate==0)
{
- brdshm->busystate = 1;
+ SHM->Bbusystate = 1;
if((fd = open(fn_board, O_RDONLY)) > 0) {
lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET);
read(fd, &bcache[bid], sizeof(boardheader_t));
close(fd);
}
- brdshm->busystate = 0;
+ SHM->Bbusystate = 0;
}
}
boardheader_t *getbcache(int bid) { /* Ptt改寫 */
@@ -357,8 +356,8 @@ boardheader_t *getbcache(int bid) { /* Ptt改寫 */
}
void touchbtotal(int bid) {
- brdshm->total[bid - 1] = 0;
- brdshm->lastposttime[bid - 1] = 0;
+ SHM->total[bid - 1] = 0;
+ SHM->lastposttime[bid - 1] = 0;
}
@@ -377,10 +376,9 @@ int getbnum(char *bname) {
/* PTT cache */
/*-------------------------------------------------------*/
/* cachefor 動態看版 */
-struct pttcache_t *ptt;
-
-void reload_pttcache() {
- if(ptt->busystate)
+void reload_pttcache(void)
+{
+ if(SHM->Pbusystate)
safe_sleep(1);
else { /* jochang: temporary workaround */
fileheader_t item, subitem;
@@ -388,9 +386,9 @@ void reload_pttcache() {
FILE *fp, *fp1, *fp2;
int id, section = 0;
- ptt->busystate = 1;
- ptt->max_film = 0;
- bzero(ptt->notes, sizeof ptt->notes);
+ SHM->Pbusystate = 1;
+ SHM->max_film = 0;
+ bzero(SHM->notes, sizeof SHM->notes);
setapath(pbuf, "Note");
setadir(buf, pbuf);
id = 0;
@@ -401,15 +399,15 @@ void reload_pttcache() {
setadir(buf, buf);
if(!(fp1 = fopen(buf, "r")))
continue;
- ptt->next_refresh[section] = ptt->n_notes[section] = id;
+ 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(ptt->notes[id],sizeof(char), 200*11, fp2);
- ptt->notes[id][200*11 - 1]=0;
+ fread(SHM->notes[id],sizeof(char), 200*11, fp2);
+ SHM->notes[id][200*11 - 1]=0;
id++;
fclose(fp2);
if(id >= MAX_MOVIE)
@@ -422,46 +420,46 @@ void reload_pttcache() {
}
fclose(fp);
}
- ptt->next_refresh[section] = -1;
- ptt->n_notes[section] = ptt->max_film = id-1;
- ptt->max_history = ptt->max_film - 2;
- if(ptt->max_history > MAX_HISTORY - 1)
- ptt->max_history = MAX_HISTORY - 1;
- if(ptt->max_history <0) ptt->max_history=0;
+ 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(ptt->today_is,15,fp);
- if((chr = strchr(ptt->today_is,'\n')))
+ fgets(SHM->today_is,15,fp);
+ if((chr = strchr(SHM->today_is,'\n')))
*chr = 0;
- ptt->today_is[15] = 0;
+ SHM->today_is[15] = 0;
fclose(fp);
}
/* 等所有資料更新後再設定 uptime */
- ptt->uptime = ptt->touchtime ;
- ptt->busystate = 0;
+ SHM->Puptime = SHM->Ptouchtime ;
+ SHM->Pbusystate = 0;
}
}
void resolve_garbage() {
int count=0;
- if(ptt == NULL) {
- ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt));
- if(ptt->touchtime == 0)
- ptt->touchtime = 1;
+ if(SHM == NULL) {
+ attach_SHM();
+ if(SHM->Ptouchtime == 0)
+ SHM->Ptouchtime = 1;
}
- while(ptt->uptime < ptt->touchtime) { /* 不用while等 */
+ while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */
reload_pttcache();
- if(count ++ > 10 && ptt->busystate) {
+ if(count ++ > 10 && SHM->Pbusystate) {
/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0
這樣會所有prcosee都會在load 動態看板 會造成load大增
但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他
解開 同樣的問題發生在reload passwd
*/
- ptt->busystate = 0;
+ SHM->Pbusystate = 0;
}
}
}
@@ -470,49 +468,47 @@ void resolve_garbage() {
/* PTT's cache */
/*-------------------------------------------------------*/
/* cachefor from host 與最多上線人數 */
-struct fromcache_t *fcache;
-
static void reload_fcache() {
- if(fcache->busystate)
+ if(SHM->Fbusystate)
safe_sleep(1);
else {
FILE *fp;
- fcache->busystate = 1;
- bzero(fcache->domain, sizeof fcache->domain);
+ SHM->Fbusystate = 1;
+ bzero(SHM->domain, sizeof SHM->domain);
if((fp = fopen("etc/domain_name_query","r"))) {
char buf[101],*po;
- fcache->top=0;
+ SHM->top=0;
while(fgets(buf,100,fp)) {
if(buf[0] && buf[0] != '#' && buf[0] != ' ' &&
buf[0] != '\n') {
- sscanf(buf,"%s",fcache->domain[fcache->top]);
- po = buf + strlen(fcache->domain[fcache->top]);
+ sscanf(buf,"%s",SHM->domain[SHM->top]);
+ po = buf + strlen(SHM->domain[SHM->top]);
while(*po == ' ')
po++;
- strncpy(fcache->replace[fcache->top],po,49);
- fcache->replace[fcache->top]
- [strlen(fcache->replace[fcache->top])-1] = 0;
- (fcache->top)++;
+ strncpy(SHM->replace[SHM->top],po,49);
+ SHM->replace[SHM->top]
+ [strlen(SHM->replace[SHM->top])-1] = 0;
+ (SHM->top)++;
}
}
}
- fcache->max_user=0;
+ SHM->max_user=0;
/* 等所有資料更新後再設定 uptime */
- fcache->uptime = fcache->touchtime;
- fcache->busystate = 0;
+ SHM->Fuptime = SHM->Ftouchtime;
+ SHM->Fbusystate = 0;
}
}
void resolve_fcache() {
- if(fcache == NULL) {
- fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache));
- if(fcache->touchtime == 0)
- fcache->touchtime = 1;
+ if(SHM == NULL) {
+ attach_SHM();
+ if(SHM->Ftouchtime == 0)
+ SHM->Ftouchtime = 1;
}
- while(fcache->uptime < fcache->touchtime)
+ while(SHM->Fuptime < SHM->Ftouchtime)
reload_fcache();
}
diff --git a/util/xchatd.c b/util/xchatd.c
index 46fba147..97cb33fe 100644
--- a/util/xchatd.c
+++ b/util/xchatd.c
@@ -1,25 +1,5 @@
-/* $Id: xchatd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <time.h>
-#include <sys/resource.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "util.h"
-#include "perm.h"
-#include "common.h"
+/* $Id: xchatd.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */
+#include "bbs.h"
#include "xchatd.h"
#define SERVER_USAGE
@@ -598,7 +578,7 @@ list_belong(list, userno)
static void
-do_send(nfds, wset, msg, number)
+Xdo_send(nfds, wset, msg, number)
int nfds;
fd_set *wset;
char *msg;
@@ -686,10 +666,10 @@ send_to_room(room, msg, userno, number)
else
sprintf(sendbuf, "%3d", number);
- do_send(max, wptr, sendbuf);
+ Xdo_send(max, wptr, sendbuf);
}
else
- do_send(max, wptr, msg);
+ Xdo_send(max, wptr, msg);
}
}
@@ -720,10 +700,10 @@ send_to_user(user, msg, userno, number)
sprintf(sendbuf, "%3d %s", number, msg);
else
sprintf(sendbuf, "%3d", number);
- do_send(sock, wptr, sendbuf);
+ Xdo_send(sock, wptr, sendbuf);
}
else
- do_send(sock, wptr, msg);
+ Xdo_send(sock, wptr, msg);
}
}
@@ -737,7 +717,7 @@ send_to_sock(sock, msg) /* Thor: unused */
FD_ZERO(wptr = &wset);
FD_SET(sock, wptr);
- do_send(sock, wptr, msg);
+ Xdo_send(sock, wptr, msg);
}
#endif
diff --git a/util/yearsold.c b/util/yearsold.c
index 74e711ee..3124d778 100644
--- a/util/yearsold.c
+++ b/util/yearsold.c
@@ -1,21 +1,14 @@
-/* $Id: yearsold.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
+/* $Id: yearsold.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */
/* 站上年齡統計 */
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/types.h>
-#include "config.h"
-#include "pttstruct.h"
-#include "common.h"
-#include "util.h"
+#include "bbs.h"
#define MAX_LINE 16
struct userec_t cuser;
void
- outs(fp, buf, mode)
+fouts(fp, buf, mode)
FILE *fp;
char buf[], mode;
{
@@ -88,12 +81,12 @@ int main()
year = act[j];
if (year && (max > year) && (max - item <= year))
{
- outs(fp, buf, '7');
+ fouts(fp, buf, '7');
fprintf(fp, "%-3d", year);
}
else if (max <= year)
{
- outs(fp, buf, '4');
+ fouts(fp, buf, '4');
fprintf(fp, "█ ");
}
else