From: Alexander Moisseev Date: Mon, 14 Aug 2017 15:34:34 +0000 (+0300) Subject: [Minor] Fix reading from a pipe X-Git-Tag: 1.7.0~721^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1800%2Fhead;p=rspamd.git [Minor] Fix reading from a pipe --- diff --git a/utils/rspamd_stats.pl b/utils/rspamd_stats.pl index b51431c7a..2c40e347c 100755 --- a/utils/rspamd_stats.pl +++ b/utils/rspamd_stats.pl @@ -323,10 +323,13 @@ Messages scanned: $total"; } sub ProcessLog { - my $ts_format = &log_time_format($rspamd_log); + my ( $ts_format, @line ) = &log_time_format($rspamd_log); my $is_syslog = defined $ts_format && $ts_format eq 'syslog'; - while(<$rspamd_log>) { + while() { + last if eof $rspamd_log; + $_ = (@line) ? shift @line : <$rspamd_log>; + if (!$enabled && ($search_pattern eq "" || /$search_pattern/)) { $enabled = 1; } @@ -537,8 +540,9 @@ sub GetLogfilesList { sub log_time_format { my $fh = shift; - my $format; + my ( $format, $line ); while (<$fh>) { + $line = $_; # 2017-08-08 00:00:01 #66984( # 2017-08-08 00:00:01.001 #66984( @@ -563,11 +567,7 @@ sub log_time_format { exit 1; } } - - # XXX: in case of pipe, we still will miss one element... - seek( $fh, 0, 0 ); - - return $format; + return ( $format, $line ); } sub normalized_time {