Subject: | ->read() returns false instead of blocking |
File::Tail::read should never return false.
It is documented as blocking when there is no data to deliver.
However, as this program demonstrates, it can be made to return false
when maxbuf is set to 1.
SunOS porpoise.net.isc.upenn.edu 5.9 Generic_118558-21 sun4u sparc
SUNW,Sun-Fire-V240
use File::Tail;
my $FILE = "/tmp/file-tail-has-a-bug";
my $pid = fork;
die "fork: $!" unless defined $pid;
END { kill 15 => $pid if $pid } # clean up child on exit
make_file() if $pid == 0; # child process writes the file
# parent reads it back with File::Tail
sleep 2;
my $z = File::Tail->new(name => $FILE, maxbuf => 1)
or die;
while (defined(my $l = $z->read)) {
if ($l eq "") { # This should never happen
die "File::Tail::read returned the empty string"
}
}
print "OK\n";
exit;
sub make_file {
open F, ">", $FILE or die "Couldn't write demo file '$FILE': $!";
select F;
$| = 1;
while (1) {
print time, "\n";
}
}