more on buffindexed ...

Matthias Urlichs smurf at noris.de
Thu Sep 9 14:09:48 UTC 1999


Hi,

Katsuhiro Kondou:
> In article <Pine.BSF.4.10.9909090827010.412-100000 at thelab.hub.org>,
> 	The Hermit Hacker <scrappy at hub.org> wrote;
> 
> } can the same be done with buffindexed?  saves alot of time when just
> } strating things up, that's for sure...
> 
> Currently not.  The size must be the size written in
> buffindexed.conf at least.  I'll drop the check, since
> the buffer can be extended by pwrite().

You can't drop the check; the system tries to mmap() unallocated space if
you do that.

You can, however, pwrite a null byte to the end of the buffer if the length
check says that the file is too small, though personally I'd do that only
if it's either zero-length or bitmap-length.

Index: base.409/storage/buffindexed/buffindexed.c
--- base.409/storage/buffindexed/buffindexed.c Thu, 09 Sep 1999 06:21:44 +0200 smurf (net_news_inn/p/31_buffindexe 1.6.1.8 664)
+++ test.11(w)/storage/buffindexed/buffindexed.c Thu, 09 Sep 1999 16:08:16 +0200 smurf (net_news_inn/p/31_buffindexe 1.6.1.8 664)
@@ -309,14 +311,27 @@
   tonextblock = OV_HDR_PAGESIZE - (base & (OV_HDR_PAGESIZE - 1));
   ovbuff->base = base + tonextblock;
   if (S_ISREG(sb.st_mode) && (len != sb.st_size || ovbuff->base > sb.st_size)) {
-    if (len != sb.st_size)
-      syslog(L_NOTICE, "%s: length mismatch '%ld' for index '%d' (%ld bytes)",
-        LocalLogName, len, ovbuff->index, sb.st_size);
-    if (ovbuff->base > sb.st_size)
+    if (sb.st_size != 0 && ovbuff->base > sb.st_size) {
       syslog(L_NOTICE, "%s: length must be at least '%ld' for index '%d' (%ld bytes)",
         LocalLogName, ovbuff->base, ovbuff->index, sb.st_size);
-    DISPOSE(ovbuff);
-    return FALSE;
+      DISPOSE(ovbuff);
+      return FALSE;
+    }
+    if (len != sb.st_size) {
+      int fd = -1;
+      syslog(L_NOTICE, "%s: length mismatch '%ld' for index '%d' (%ld bytes)",
+        LocalLogName, len, ovbuff->index, sb.st_size);
+      if ((sb.st_size != 0 && sb.st_size != ovbuff->base) ||
+	  (fd = open(ovbuff->path,O_RDWR)) == -1 ||
+	  pwrite(fd, "", 1, len-1) != 1) {
+        syslog(L_NOTICE, "%s: length mismatch correction failed: %s",
+          LocalLogName, strerror(errno));
+        if (fd > -1)
+	  close(fd);
+	return FALSE;
+      }
+      close(fd);
+    }
   }
   ovbuff->len = len;
   ovbuff->fd = -1;

-- 
Matthias Urlichs  |  noris network GmbH   |   smurf at noris.de  |  ICQ: 20193661
The quote was selected randomly. Really.    |      http://www.noris.de/~smurf/
-- 
Millions for defense, but not one cent for tribute.
                                        -- C. C. Pinckney


More information about the inn-workers mailing list