diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2017-08-14 18:34:34 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2017-08-14 18:34:34 +0300 |
commit | 2dd8c838c2abc3f0d6e41a6a2677ee439ca33967 (patch) | |
tree | 6f873f404f10be2d416b9d6567ad5254768a7995 /utils | |
parent | 873f31b6952c16b734ecfa05d78550328035d4a3 (diff) | |
download | rspamd-2dd8c838c2abc3f0d6e41a6a2677ee439ca33967.tar.gz rspamd-2dd8c838c2abc3f0d6e41a6a2677ee439ca33967.zip |
[Minor] Fix reading from a pipe
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/rspamd_stats.pl | 16 |
1 files changed, 8 insertions, 8 deletions
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 { |