]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - guardian
Add LogFacility for logging to a single file.
[people/stevee/guardian.git] / guardian
index 07e0c146c74d7c31ae2292d21dafcd19c9c2ddc6..148f50e38e9f2b166336c16642087965e0c02be6 100644 (file)
--- a/guardian
+++ b/guardian
@@ -90,9 +90,13 @@ $SIG{__DIE__} = sub { $logger->Log("err", "@_"); };
 # Initialize the event handler.
 my $events = Guardian::Events->Init(%mainsettings);
 
-# Shared hash between the main process and all threads. It will store all
+# Hash to store the currently monitored files and their configured
+# parsers.
+my %monitored_files = ();
+
+# Shared hash between the main process and all threads. It will store the
 # monitored files and their current file position.
-my %monitored_files :shared = ();
+my %file_positions :shared = ();
 
 # Create the main queue. It is used to store and process all events which are
 # reported and enqueued by the worker threads.
@@ -187,6 +191,10 @@ sub Init () {
 sub Worker ($) {
        my $file = $_[0];
 
+       # Obtain the parser name which should be used to parser any
+       # messages of this file.
+       my $parser = $monitored_files{$file};
+
        # Signal handler to kill worker.
        $SIG{'KILL'} = sub { threads->exit(); };
 
@@ -210,7 +218,7 @@ sub Worker ($) {
                        my @message = ();
 
                        # Obtain fileposition from hash.
-                       my $fileposition = $monitored_files{$file};
+                       my $fileposition = $file_positions{$file};
 
                        # Open the file.
                        open (FILE, $file) or die "Could not open $file. $!";
@@ -229,10 +237,10 @@ sub Worker ($) {
 
                        {
                                # Lock shared hash.
-                               lock(%monitored_files);
+                               lock(%file_positions);
 
                                # Update fileposition.
-                               $monitored_files{$file} = tell(FILE);
+                               $file_positions{$file} = tell(FILE);
                        }
 
                        # Close file.
@@ -240,16 +248,16 @@ sub Worker ($) {
 
                        # Send filename and message to the parser,
                        # which will return if an action has to be performed.
-                       my @action = &Guardian::Parser::Parser("$file", @message);
+                       my $action = &Guardian::Parser::Parser("$parser", @message);
 
                        # Send the action to the main process and put it into
                        # the queue.
-                       if (@action) {
+                       if (defined ($action)) {
                                # Lock the queue.
                                lock($queue);
 
                                # Put the required action into the queue.
-                               $queue->enqueue(@action);
+                               $queue->enqueue($action);
                        }
                } else {
                        # Sleep for 10ms until the next round of the loop will start.
@@ -271,7 +279,7 @@ sub Worker ($) {
 #
 sub Socket () {
        # Create the Server socket by calling the responsible function.
-       my $server = &Guardian::Socket::Server();
+       my $server = &Guardian::Socket::Server($mainsettings{SocketOwner});
 
        # Log successfull creation of socket.
        $logger->Log("debug", "Listening to Socket...");
@@ -328,6 +336,9 @@ sub SignalHandler {
 ## be added to the array of running workers.
 #
 sub StartWorkers () {
+       # Init/Update hash which contains the cursor position of EOF.
+       %file_positions = &Guardian::Base::FilePositions(\%monitored_files, \%file_positions);
+
        # Loop through the hash which contains the monitored files and start
        # a worker thread for each single one.
        foreach my $file (keys %monitored_files) {
@@ -376,6 +387,11 @@ sub Reload () {
        # Update logger object in mainsettings hash.
        $mainsettings{Logger} = $logger;
 
+       # Update ignore list, if one has been specified.
+       if (exists($mainsettings{IgnoreFile})) {
+               &Guardian::Events::GenerateIgnoreList($mainsettings{IgnoreFile});
+       }
+
        # Re-generate hash of monitored files.
        %monitored_files = &Guardian::Base::GenerateMonitoredFiles(\%mainsettings, \%monitored_files);