]> git.ipfire.org Git - people/stevee/guardian.git/commitdiff
Merge remote-tracking branch 'logrotate'
authorStefan Schantl <stefan.schantl@ipfire.org>
Tue, 14 Jun 2016 13:31:42 +0000 (15:31 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Tue, 14 Jun 2016 13:31:42 +0000 (15:31 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
1  2 
guardian
modules/Events.pm

diff --cc guardian
index d01612525dfe2ec2332b3aefc6afd3b74dd8f111,16d4198bc873b4dd44c0a0d80b9b6b796400e4e3..0facdc696245abb3ee814e90c496caab75ec3675
+++ b/guardian
@@@ -405,25 -403,49 +405,68 @@@ sub Reload () 
        &StartWorkers();
  }
  
 +#
 +## ReloadIgnoreList function.
 +#
 +## This function will be called if the signal handler recieves a "SIGUSR1" signal,
 +## or the reload-ignore-list command will be sent via the socket connection. It just
 +## performs a simple check if an ignore file has been configured and calls the responsible
 +## function on the events module.
 +#
 +sub ReloadIgnoreList () {
 +      # Update ignore list, if an ignorefile has been specified.
 +      if (exists($mainsettings{IgnoreFile})) {
 +              # Log reload of the ignore list.
 +              $logger->Log("info", "Reloading ignore list...");
 +
 +              # Call responsible function from the events module.
 +              &Guardian::Events::GenerateIgnoreList($mainsettings{IgnoreFile});
 +      }
 +}
 +
+ #
+ ## Logrotate function.
+ #
+ ## This function only get called when the logrotate command will be sent via
+ ## the socket connection. It is responsible for validating and altering the current
+ ## curser positions of the monitored files and stopping/starting the worker threads.
+ #
+ sub Logrotate () {
+       # Stop all running workers.
+       &StopWorkers();
+       {
+       # Lock shared hash.
+       lock(%file_positions);
+       # Loop through the hash which contains the current
+       # file positions.
+       foreach my $file (keys(%file_positions)) {
+               # Obtain stored value from hash.
+               my $stored_position = $file_positions{$file};
+               # Call function to get the current position.
+               my $current_position = &Guardian::Base::GetFileposition($file);
+               # Compare if the current position still matches
+               # the stored one.
+               if ($current_position ne $stored_position) {
+                       # Update to the new position, because
+                       # they has changed during file rotation.
+                       $file_positions{$file} = $current_position;
+                       # Log notice about rotated file.
+                       $logger->Log("debug", "$file have been rotated - Using new file position.");
+               }
+       }
+       # After this bracket, the lock of the hash will be released.
+       }
+       # Restart all worker threads.
+       &StartWorkers();
+ }
  #
  ## Shutdown function.
  #
index 376438fb25681119ac6df1537e046d8994f01a1d,2be2ac729f143a4090aeb35a324510049d916ae8..2d2c776b144248d54b9963a4402547fe56990044
@@@ -13,7 -13,7 +13,8 @@@ my %commands = 
        'unblock' => \&CallUnblock,
        'flush' => \&CallFlush,
        'reload' => \&main::Reload,
 +      'reload-ignore-list' => \&main::ReloadIgnoreList,
+       'logrotate' => \&main::Logrotate,
  );
  
  # Hash to store addresses and their current count.