From a9fd14e2b5daad846f720389453dffc56c3becce Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 10 Feb 2003 17:41:45 +0000 Subject: lazy sort utmp git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@653 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 6 ++++-- pttbbs/mbbsd/Makefile | 4 ++-- pttbbs/mbbsd/cache.c | 3 ++- pttbbs/mbbsd/mbbsd.c | 3 ++- pttbbs/util/shmctl.c | 15 +++++++++++++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 12054171..898d4447 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.28 2003/01/24 14:41:19 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.29 2003/02/10 17:41:45 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -313,7 +313,9 @@ typedef struct { int currsorted; time_t UTMPuptime; int UTMPnumber; - int UTMPbusystate; + char UTMPneedsort; + char UTMPbusystate; + char pad[2]; char gap[1024]; /* avoid some memory error / buffer overflow */ /* brdshm */ diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 85e695f0..9204ead9 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,11 +1,11 @@ -# $Id: Makefile,v 1.17 2003/01/19 16:02:25 kcwu Exp $ +# $Id: Makefile,v 1.18 2003/02/10 17:41:45 in2 Exp $ # ­q¸q°ò¥»ªì­È BBSHOME?= $(HOME) BBSHOME?= /home/bbs OSTYPE?= FreeBSD CC?= gcc -CFLAGS+= -Wall -W -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include LDFLAGS+= -pipe -Wall LIBS+= -lcrypt diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ae5caad3..023ac8a7 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.57 2003/01/24 19:48:14 in2 Exp $ */ +/* $Id: cache.c,v 1.58 2003/02/10 17:41:45 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -476,6 +476,7 @@ purge_utmp(userinfo_t * uentp) { logout_friend_online(uentp); memset(uentp, 0, sizeof(userinfo_t)); + SHM->UTMPneedsort = 1; } #endif diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 2ef59687..3a5828b0 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.65 2003/01/24 19:48:14 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.66 2003/02/10 17:41:45 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -743,6 +743,7 @@ setup_utmp(int mode) if (enter_uflag & CLOAK_FLAG) uinfo.invisible = YEA; getnewutmpent(&uinfo); + SHM->UTMPneedsort = 1; #ifndef _BBS_UTIL_C_ friend_load(); nice(3); diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 1eea2825..f1b7765c 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.31 2003/01/24 19:48:29 in2 Exp $ */ +/* $Id: shmctl.c,v 1.32 2003/02/10 17:41:45 in2 Exp $ */ #include "bbs.h" #include @@ -59,6 +59,7 @@ int utmpfix(int argc, char **argv) time_t now, timeout = -1; char *clean, buf[1024], ch; IDLE_t idle[USHM_SIZE]; + char changeflag = 0; while( (ch = getopt(argc, argv, "nt:l:")) != -1 ) switch( ch ){ @@ -131,9 +132,12 @@ int utmpfix(int argc, char **argv) i, clean, SHM->uinfo[which].userid); memset(&SHM->uinfo[which], 0, sizeof(userinfo_t)); --nownum; + changeflag = 1; } } SHM->UTMPbusystate = 0; + if( changeflag ) + SHM->UTMPneedsort = 1; return 0; } /* end of utmpfix ---------------------------------------------------------- */ @@ -202,6 +206,7 @@ inline void utmpsort(void) userinfo_t *uentp; int count, i, ns; short nusers[MAX_BOARD]; + SHM->UTMPbusystate = 1; SHM->UTMPuptime = time(NULL); ns = (SHM->currsorted ? 0 : 1); @@ -264,7 +269,13 @@ int utmpsortd(int argc, char **argv) } else{ while( 1 ){ - utmpsort(); + int i; + for( i = 0 ; SHM->UTMPbusystate && i < 5 ; ++i ) + usleep(300000); + + if( SHM->UTMPneedsort ) + utmpsort(); + sleep(1); } } -- cgit v1.2.3