🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #16062

Re: patch for nnrpd 1.5.1 to mmap .overview files

#16062
From: Jan-Pieter Cornet
Date: Wed, 19 Mar 1997 00:00
145 lines
5585 bytes
[mailed and posted]
OK, so it's really lame to followup on your own article, but... I issued
another nonsensical patch :(

In article <5gj4cb$ppu$1@news0.xs4all.nl>,
Jan-Pieter Cornet <johnpc@xs4all.nl> wrote:
>In article <5g61g0$hak$2@news.demos.su>,
>Andrew A. Vasilyev  <andy@snm.demos.su> wrote:
>>  getpagesize() works fine, but you've not answered the question: why is
>>  it necessary to align maped region on page boundary?
>
>I had some systems barf if I didn't align on a page boundary, I think it
>was some Linux version, might be related to the libc version... and it
>says in the manual page somewhere that it should be aligned on a pagesize,
>so I decided to play it safe.

I later learned that other places in the innd source do not bother to align
on a pagesize, so when I redo this patch for the next version of inn, I'll
leave this part out (unless the other mmaps get updated too :). It does
no harm, however.

[...]
>Actually there were several bugs dwelling
>in that part of the code, apparently I was a bit sleepy when I wrote that.
>Another (incremental) patch included below.

That patch didn't quite do what it had to do. I include yet another
incremental patch below, but note that it's really much easier to start
with a clean 1.5.1 source and get the patch from my homepage:
http://www.xs4all.nl/~johnpc/inn/mmap-overview.patch. The patch below
basically undoes everything the previous patch does and then does it
right. Only for those that installed the previous patch. Really. :)

(James, this is a kind request to also update the file on ftp.isc.org,
this version has a lot of bugs fixed)

Note for anyone who's concerned: the bugs in the previous patched didn't
corrupt any data, they just had a performance impact, mostly because the
OVERgen() routine was being called more often than necessary.

--
#! ##### Jan-Pieter Cornet ##### <johnpc@xs4all.net> ##### perl
++$_;$!=$_+++$_;($:,$,,$/,$*)=$!=~/.(.)...(.)(.).(.)/;$!=$_+$_;
($@,$\,$~)=$!=~/(.)(.).(.)/; $_="$,$/$:"; $@++; $~="$~$_";($_)=
\$$=~/\((.)/;$|=++$_;$_++;$|++;$~="$~ $@$:";`$~$/$\$*$, $|>&$_`


--- article.c	1997/03/17 09:47:36	1.37
+++ article.c	1997/03/19 12:12:10
@@ -1,4 +1,4 @@
-/*  $Revision: 1.37 $
+/*  $Revision: 1.39 $
 **
 **  Article-related routines.
 */
@@ -11,6 +11,7 @@
 /*
  * OVERSCREAM - to make the overview database screaming fast, and because
  * I scream in terror about the previous implementation.
+ * See http://www.xs4all.nl/~johnpc/inn/ for more information on this patch.
  */
 
 #define OVERSCREAM
@@ -804,8 +805,6 @@
     struct stat 	sb;
     char*		p;
     static int		pagesize = 0;
-    int			hadlf;
-
 
     /* return true if already mapped */
     if ( OVERshm ) {
@@ -866,7 +865,7 @@
     }
 
     /* get last entry */
-    if ( !(hadlf = *(OVERshm + OVERsize - 1) == '\n') ) {
+    if ( *(OVERshm + OVERsize - 1) != '\n' ) {
 	/*
 	 * If you get here, then your mmap() implementation sucks.
 	 * Go complain with your OS vendor, that their mmap() can't
@@ -879,38 +878,32 @@
 	YOUR_MMAP_SUCKS;
     }
     do {
-	p = memrchr(OVERshm + OVERsize - 2, '\n', OVERsize - 2);
+	/*
+         * Try to find any newline. If there isn't any, the entire file
+	 * is crap. Normally this finds the newline right at the end.
+	 */
+	p = memrchr(OVERshm + OVERsize - 1, '\n', OVERsize - 1);
 	if ( p == NULL ) {
-	    if ( hadlf ) {
-		/* Apparently only 1 (usable) line */
-		OVERlast = OVERfirst;
-		OVERcache = NULL;
-		return TRUE;
-	    }
-	    else {
-		/* overview file only contains garbage. */
-		(void)munmap(OVERshm, OVERmsize);
-		(void)close(OVERfd);
-		OVERshm = NULL;
-		return FALSE;
-	    }
-	}
-	hadlf = TRUE;
-	OVERsize = p - OVERshm + 1;
-	if ( (p = memrchr((char*) OVERshm + OVERsize - 2, '\n',
-			    OVERsize - 1)) == NULL )
-	{
-	    syslog(L_NOTICE, "%s: %s: bad format", ClientHost, name);
+	    /* overview file only contains garbage. */
 	    (void)munmap(OVERshm, OVERmsize);
 	    (void)close(OVERfd);
 	    OVERshm = NULL;
 	    return FALSE;
 	}
+	OVERsize = p - OVERshm + 1;
+	if ( (p = memrchr((char*) OVERshm + OVERsize - 2, '\n',
+			    OVERsize - 2)) == NULL )
+	{
+	    /* Apparently only 1 (usable) line */
+	    OVERlast = OVERfirst;
+	    OVERcache = NULL;
+	    return TRUE;
+	}
 	OVERlast = atol(p+1);
     }
-    while ( OVERlast == 0 && --OVERsize >= 2 );
+    while ( OVERlast == 0 && --OVERsize );
 
-    if ( OVERsize < 2 ) {
+    if ( !OVERsize ) {
 	(void)munmap(OVERshm, OVERmsize);
 	(void)close(OVERfd);
 	OVERshm = NULL;
--
#! ##### Jan-Pieter Cornet ##### <johnpc@xs4all.net> ##### perl
++$_;$!=$_+++$_;($:,$,,$/,$*)=$!=~/.(.)...(.)(.).(.)/;$!=$_+$_;
($@,$\,$~)=$!=~/(.)(.).(.)/; $_="$,$/$:"; $@++; $~="$~$_";($_)=
\$$=~/\((.)/;$|=++$_;$_++;$|++;$~="$~ $@$:";`$~$/$\$*$, $|>&$_`

Technical Details
Message-ID: <5golpb$9hn$1@news0.xs4all.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <331EE55D.1493@cwix.net> <5g429n$d2s$1@news1.xs4all.nl> <5g61g0$hak$2@news.demos.su> <5gj4cb$ppu$1@news0.xs4all.nl>

Show Full Headers
Complete Article Headers
Message-ID: <5golpb$9hn$1@news0.xs4all.nl>
Subject: Re: patch for nnrpd 1.5.1 to mmap .overview files
Date: Wed, 19 Mar 1997 00:00:00 +0000
From: johnpc@xs4all.nl (Jan-Pieter Cornet)
References: <331EE55D.1493@cwix.net> <5g429n$d2s$1@news1.xs4all.nl> <5g61g0$hak$2@news.demos.su> <5gj4cb$ppu$1@news0.xs4all.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 226722487
X-XS4ALL-Date: Wed, 19 Mar 1997 13:22:03 MET
Organization: XS4ALL Internet
Newsgroups: news.software.nntp