summaryrefslogtreecommitdiffstats
path: root/util
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 /util
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
Diffstat (limited to 'util')
-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
30 files changed, 303 insertions, 690 deletions
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