]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - guardian
Adjust error messages in case of failure.
[people/stevee/guardian.git] / guardian
index ba8e99cf52400c8c92cebdbdc2a1441cf53cd95c..f480c11b9d7437e29e1f0864ebb806638a0dba1d 100644 (file)
--- a/guardian
+++ b/guardian
@@ -73,13 +73,16 @@ my %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
 my $logger = Guardian::Logger->New(%mainsettings);
 $logger->Log("debug", "Logger successfully initialized...");
 
+# Redirect perls "die" messages to the logger before exiting.
+$SIG{__DIE__} = sub { $logger->Log("err", "@_"); };
+
 # Shared hash between the main process and all threads. It will store all
 # monitored files and their current file position.
 my %monitored_files :shared = ();
 
 # Create the main queue. It is used to store and process all events which are
 # reported and enqueued by the worker threads.
-my $queue :shared = new Thread::Queue or die "Could not create new, empty queue. $!\n";;
+my $queue :shared = new Thread::Queue or die "Could not create new, empty queue. $!";;
 
 # Array to store all currently running worker objects.
 # (Does not include the socket thread)
@@ -157,10 +160,10 @@ sub Worker ($) {
        $SIG{'KILL'} = sub { threads->exit(); };
 
        # Create inotify watcher.
-       my $watcher = new Linux::Inotify2 or die "Could not use inotify. $!\n";
+       my $watcher = new Linux::Inotify2 or die "Could not use inotify. $!";
 
        # Monitor the specified file.
-       $watcher->watch("$file", IN_MODIFY) or die "Could not monitor $file. $!\n";
+       $watcher->watch("$file", IN_MODIFY) or die "Could not monitor $file. $!";
 
        # Switch watcher into non-blocking mode.
        $watcher->blocking(0);
@@ -179,7 +182,7 @@ sub Worker ($) {
                        my $fileposition = $monitored_files{$file};
 
                        # Open the file.
-                       open (FILE, $file) or die "Could not open $file. $!\n";
+                       open (FILE, $file) or die "Could not open $file. $!";
 
                        # Seek to the last known position.
                        seek (FILE, $fileposition, 0);