Subject: | Log::Log4perl::Appender::File dies when writing zero length (or undef) message |
Date: | Mon, 24 Apr 2017 10:37:31 +0200 (CEST) |
To: | "bug-Log-Log4perl [...] rt.cpan.org" <bug-log-log4perl [...] rt.cpan.org> |
From: | kgabi <kgabi [...] freemail.hu> |
In version 1.49 appeared the old #67132 bug: If the message has zero bytes to it, it will die, and $! will not be set.
The problem is checking the syswrite return value:
my $rc =
syswrite( $fh,
$self->{ syswrite_encoder } ?
$self->{ syswrite_encoder }->($params{message}) :
$params{message} );
if(!$rc) {<!-- -->
die "Cannot syswrite to '$self->{filename}': $!";
}
This is not quite right.
That is, syswrite returns undef on failure, a return of 0 merely means that syswrite wrote nothing.
The correct way to do this would be:
if(!defined $rc) {<!-- -->
die "Cannot syswrite to '$self->{filename}': $!";
}
Version 1.48 worked fine:
defined (syswrite $fh, $params{message}) or
die "Cannot syswrite to '$self->{filename}': $!";
Regards,
Gabor Kanizsai