Forum OpenACS Q&A: Response to Immune aolserver-error process

Collapse
Posted by Steve Woodcock on

Don, here's the patch we made to aolserver-errors.pl to fix the infinite loop problem. I'll post it elsewhere if this gets mangled...

Index: aolserver-errors.pl
===================================================================
RCS file: /usr/local/cvsroot/intranet/packages/scholastic-core/bin/aolserver-errors.pl,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- aolserver-errors.pl 2002/01/31 16:37:39     1.1
+++ aolserver-errors.pl 2002/02/01 22:50:49     1.1.2.1
@@ -90,9 +90,21 @@
     $start_time = sprintf "%02d%02d%02d%02d", (localtime(time - (60*$num_minutes)))[4,3,2,1];

     seek LOG, -$bite_size, 2;
+    $search_from = tell(LOG);

     while (1) {
         while () {
+
+           # Don't search past where we got to last time, rewind to
+           # where we started and leave (next iter will go back
+           # another chunk)
+           if (defined $search_to) {
+               if (tell(LOG) >= $search_to) {
+                   seek LOG, -$bite_size, 1;
+                   last;
+               }
+           }
+
             if (/^[([0-9]+)/([A-Za-z]+)/([0-9]+):([0-9]+):([0-9]+)/) {
                 my($day, $month_name, $year, $hour, $minute) = ($1, $2, $3, $4, $5);

@@ -122,7 +134,15 @@
                     # the end of the file. If it's the second case, we
                     # need to set the starting point to the end of the file.
                     $starting_point = $last_position unless $starting_point;
-                }
+                } else {
+                   # We found a dated entry but we need to go further
+                   # back. Go back from where we started from last
+                   # time, to avoid infinite loop where the whole
+                   # $bite_size doesn't have any dates
+
+                   $rewind = (tell(LOG) - $search_from); # how far to rewind to get back to search_from
+                   seek LOG, -$rewind, 1;
+               }
                 # We only need to get one time stamp
                 last;
             }
@@ -130,11 +150,11 @@

         last if defined $starting_point;

+       $search_to = tell(LOG); # don't bother searching after where we are now
         seek LOG, -$bite_size, 1;
-
-        $position = tell LOG;
+       $search_from = tell(LOG);

-        if ($position < $bite_size) {
+        if ($search_from < $bite_size) {
             # then we need to read the entire file
             $starting_point = 0;
             last;