]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - guardian
Add ability to reload the ignore list.
[people/stevee/guardian.git] / guardian
index 691ddc66e1f0013add0fd5245f7864d70931d049..d01612525dfe2ec2332b3aefc6afd3b74dd8f111 100644 (file)
--- a/guardian
+++ b/guardian
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2015  IPFire Development Team                                 #
+# Copyright (C) 2015-2016  IPFire Development Team                            #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
@@ -247,23 +247,24 @@ sub Worker ($) {
                        close(FILE);
 
                        # Send filename and message to the parser,
-                       # which will return if an action has to be performed.
-                       my @action = &Guardian::Parser::Parser("$parser", @message);
+                       # which will return if any actions have to be performed.
+                       my @actions = &Guardian::Parser::Parser("$parser", @message);
 
                        # Send the action to the main process and put it into
                        # the queue.
-                       if (@action) {
+                       if (@actions) {
                                # Lock the queue.
                                lock($queue);
 
-                               # Put the required action into the queue.
-                               $queue->enqueue(@action);
-                       }
-                       # If no action is returned by the Parser, the message
-                       # could not be parser corretly.
-                       else {
-                               # Log failed parse attempt.
-                               $logger->Log("err", "Error parsing event: \[$parser - @message\]");
+                               # Loop through the actions array, and perform
+                               # every single action.
+                               foreach my $action (@actions) {
+                                       # Prevent from enqueuing empty actions.
+                                       if (defined($action)) {
+                                               # Put the required action into the queue.
+                                               $queue->enqueue($action);
+                                       }
+                               }
                        }
                } else {
                        # Sleep for 10ms until the next round of the loop will start.
@@ -285,7 +286,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...");
@@ -332,6 +333,7 @@ sub SignalHandler {
        $SIG{TERM} = \&Shutdown;
        $SIG{QUIT} = \&Shutdown;
        $SIG{HUP} = \&Reload;
+       $SIG{USR1} = \&ReloadIgnoreList;
 }
 
 #
@@ -394,7 +396,7 @@ sub Reload () {
        $mainsettings{Logger} = $logger;
 
        # Update ignore list.
-       &Guardian::Events::GenerateIgnoreList($mainsettings{IgnoreFile});
+       &ReloadIgnoreList();
 
        # Re-generate hash of monitored files.
        %monitored_files = &Guardian::Base::GenerateMonitoredFiles(\%mainsettings, \%monitored_files);
@@ -403,6 +405,25 @@ 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});
+       }
+}
+
 #
 ## Shutdown function.
 #