--- openwebmail-spell.pl.orig	Sun Nov 16 13:08:41 2003
+++ openwebmail-spell.pl	Sun Nov 16 13:21:39 2003
@@ -605,7 +605,7 @@

 sub piperead {
    my $timeout=$_[0]; $timeout=10 if ($timeout<=0);
-
+log_time("piperead()");
    my ($stdout, $stderr, $retry)=('', '', 0);
    while (1) {
       my ($rin, $rout, $ein, $eout)=('','','','');
@@ -620,28 +620,39 @@
          my ($o, $e, $buf)=(-1, -1, '');
          if (vec($rout,fileno(\*spellOUT),1)) {
             $o=sysread(\*spellOUT, $buf, 65536);
-            if ($o>0) { $stdout.=$buf; $timeout=0.001; }
+            if ($o>0) { $stdout.=$buf; $timeout=0.001;
+log_time("piperead stdout buf=$buf, n=$n, tout=$timeout");
+            }
          }
          if (vec($rout,fileno(\*spellERR),1)) {
             $e=sysread(\*spellERR, $buf, 65536);
-            if ($e>0) { $stderr.=$buf; $timeout=0.001; }
+            if ($e>0) { $stderr.=$buf; $timeout=0.001;
+log_time("piperead stderr buf=$buf, n=$n, tout=$timeout");
+            }
+         }
+         if ($o==0 && $e==0) {	# os ensure there is no more data to read
+log_time("piperead osleave, n=$n, tout=$timeout, stdout=$stdout, stderr=$stderr");
          }
-         last if ($o==0 && $e==0);	# os ensure there is no more data to read

       } elsif ($n==0) {	# read timeout
          if ($stdout=~/\n/||$stderr=~/\n/) {	# data line already in
+log_time("piperead dataline, n=$n, tout=$timeout, stdout=$stdout, stderr=$stderr");
             last;
          } elsif ($stdout eq "" && $stderr eq "") {	# 1st read timeout
+log_time("piperead nothing, n=$n, tout=$timeout, stdout=$stdout, stderr=$stderr");
             $stderr="piperead nothing"; last;
          } # else continue to read until line

       } else {	# n<0, read err => child dead?
+log_time("piperead readerr, n=$n, tout=$timeout, stdout=$stdout, stderr=$stderr");
          $stderr="piperead error $n"; last;
       }

       if ($retry++>100) {
+log_time("piperead retry, n=$n, tout=$timeout, stdout=$stdout, stderr=$stderr");
          $stderr="piperead too many retries"; last;
       }
+log_time("piperead looping, n=$n, tout=$timeout, stdout=$stdout, stderr=$stderr");
    }

    if (!$piperun) {
