]> _ Git - remote-logging.git/commitdiff
client: Don't monitor non-text logs
authormivirl <>
Wed, 7 Feb 2024 16:24:44 +0000 (10:24 -0600)
committermivirl <>
Wed, 7 Feb 2024 16:45:59 +0000 (10:45 -0600)
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

index 1f36e2454f850d372d1a7af08fea2eb43470dbcd..dfaa3c28c128dde7ca6aba684e6b4cee271abc0f 100644 (file)
@@ -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