summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-02 17:15:40 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-02 17:15:40 +0800
commitcc20a4029a76c6342bfd58bd4314a24e21b5953b (patch)
tree9bd53af05e1cf1016bc609ba7119b5345b047c37
parent300e4e2b21bf2ff69d02b18b38e85de37299279c (diff)
downloadpttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.tar
pttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.tar.gz
pttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.tar.bz2
pttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.tar.lz
pttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.tar.xz
pttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.tar.zst
pttbbs-cc20a4029a76c6342bfd58bd4314a24e21b5953b.zip
fix bugs
git-svn-id: http://opensvn.csie.org/pttbbs/branches/outtacache@1685 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--cacheserver/Makefile5
-rw-r--r--cacheserver/utmpserver.c15
-rw-r--r--cacheserver/utmpsync.c12
3 files changed, 19 insertions, 13 deletions
diff --git a/cacheserver/Makefile b/cacheserver/Makefile
index fd2b08c7..af95a2f0 100644
--- a/cacheserver/Makefile
+++ b/cacheserver/Makefile
@@ -1,7 +1,8 @@
# $Id$
.include "../pttbbs.mk"
-PROGRAMS= utmpserver utmpsync
+AUTO_PROGRAMS= utmpserver
+PROGRAMS= ${AUTO_PROGRAMS} utmpsync
all: ${PROGRAMS}
@@ -12,7 +13,7 @@ utmpsync: utmpsync.c
${CC} ${CFLAGS} ${LDFLAGS} -DPTTBBS_UTIL -o utmpsync utmpsync.c \
../util/util_*.o
-.for fn in utmpsync utmpserver
+.for fn in ${AUTO_PROGRAMS}
${fn}: ${fn}.c
${CC} ${CFLAGS} ${LDFLAGS} -o ${fn} ${fn}.c
.endfor
diff --git a/cacheserver/utmpserver.c b/cacheserver/utmpserver.c
index 1414fae3..67989340 100644
--- a/cacheserver/utmpserver.c
+++ b/cacheserver/utmpserver.c
@@ -34,6 +34,7 @@ int main(int argc, char **argv)
return 1;
while( 1 ){
+ len = sizeof(clientaddr);
if( (cfd = accept(sfd, (struct sockaddr *)&clientaddr, &len)) < 0 ){
if( errno != EINTR )
sleep(1);
@@ -41,15 +42,17 @@ int main(int argc, char **argv)
}
toread(cfd, &index, sizeof(index));
if( index == -1 ){
- for( i = 0 ; i < MAX_ACTIVE ; ++i )
- if( toread(cfd, &utmp[i].uid, sizeof(utmp[i].uid)) &&
- toread(cfd, utmp[i].friend, sizeof(utmp[i].friend)) &&
- toread(cfd, utmp[i].reject, sizeof(utmp[i].reject)) )
+ int nSynced = 0;
+ for( i = 0 ; i < MAX_ACTIVE ; ++i, ++nSynced )
+ if( toread(cfd, &utmp[i].uid, sizeof(utmp[i].uid)) > 0 &&
+ toread(cfd, utmp[i].friend, sizeof(utmp[i].friend)) > 0 &&
+ toread(cfd, utmp[i].reject, sizeof(utmp[i].reject)) > 0 )
;
else
for( ; i < MAX_ACTIVE ; ++i )
utmp[i].uid = 0;
close(cfd);
+ fprintf(stderr, "%d users synced\n", nSynced);
continue;
}
}
@@ -82,11 +85,11 @@ int toread(int fd, void *buf, int len)
{
int l;
for( l = 0 ; len > 0 ; )
- if( (l = read(fd, buf, len)) < 0 )
+ if( (l = read(fd, buf, len)) <= 0 )
return -1;
else{
buf += l;
len -= l;
}
- return len;
+ return l;
}
diff --git a/cacheserver/utmpsync.c b/cacheserver/utmpsync.c
index 3d4de841..a8d6731c 100644
--- a/cacheserver/utmpsync.c
+++ b/cacheserver/utmpsync.c
@@ -16,9 +16,11 @@ int main(int argc, char **argv)
index = -1;
towrite(sfd, &index, sizeof(index));
for( i = 0 ; i < MAX_ACTIVE ; ++i )
- if( !towrite(sfd, &SHM->uinfo[i].uid, sizeof(SHM->uinfo[i].uid)) ||
- !towrite(sfd, SHM->uinfo[i].friend, sizeof(SHM->uinfo[i].friend))||
- !towrite(sfd, SHM->uinfo[i].reject, sizeof(SHM->uinfo[i].reject))){
+ if( towrite(sfd, &SHM->uinfo[i].uid, sizeof(SHM->uinfo[i].uid)) < 0 ||
+ towrite(sfd, SHM->uinfo[i].friend,
+ sizeof(SHM->uinfo[i].friend)) < 0 ||
+ towrite(sfd, SHM->uinfo[i].reject,
+ sizeof(SHM->uinfo[i].reject)) < 0 ){
fprintf(stderr, "sync error %d\n", i);
}
return 0;
@@ -29,13 +31,13 @@ int towrite(int fd, void *buf, int len)
{
int l;
for( l = 0 ; len > 0 ; )
- if( (l = write(fd, buf, len)) < 0 )
+ if( (l = write(fd, buf, len)) <= 0 )
return -1;
else{
buf += l;
len -= l;
}
- return len;
+ return l;
}
int toconnect(char *host, int port)