From 66fa1a26ce1a99b9b3212f1aa53e020153734791 Mon Sep 17 00:00:00 2001 From: mivirl <> Date: Wed, 7 Feb 2024 10:24:44 -0600 Subject: [PATCH] client: Don't monitor non-text logs When recursively adding logs from /var/log , logs that appear to be binary files will not be continuously monitored, only uploaded once. Otherwise files that aren't append-only may be corrupted --- src/client.pl | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/client.pl b/src/client.pl index 1f36e24..dfaa3c2 100644 --- a/src/client.pl +++ b/src/client.pl @@ -300,8 +300,16 @@ send_log('/var/log/cron'); send_log('/var/log/messages'); send_log('/var/log/syslog'); +my @binary_logfiles; foreach my $logfile (get_files_recursively('/var/log')) { - send_log($logfile); + # Only continuously monitor a log if it looks like a text file, otherwise + # upload as a single file since sending output line-by-line may corrupt + # files that aren't append-only + if (-T $logfile) { + send_log($logfile); + } else { + push @binary_logfiles, $logfile; + } } # These files will be sent once @@ -321,14 +329,15 @@ send_file('/etc/syslog.conf'); # Syslog configuration send_file('/var/log/lastlog'); # Previously logged in users send_file('/var/log/wmtp'); # Current logged in users -foreach my $logfile (get_files_recursively('/etc/pam.d'), - get_files_recursively('/etc/rc/init.d'), - get_files_recursively('/etc/ssh'), - get_files_recursively('/etc/security'), - get_files_recursively('/etc/sysconfig'), - get_files_recursively('/etc/cron*'), - get_files_recursively('/etc/init.d')) { - send_file($logfile); +foreach my $file (get_files_recursively('/etc/pam.d'), + get_files_recursively('/etc/rc/init.d'), + get_files_recursively('/etc/ssh'), + get_files_recursively('/etc/security'), + get_files_recursively('/etc/sysconfig'), + get_files_recursively('/etc/cron*'), + get_files_recursively('/etc/init.d'), + @binary_logfiles) { + send_file($file); } # These commands will have their output sent as they are updated -- 2.39.5