+## Function to start the workers (threads) for all monitored files.
+#
+## This function will loop through the hash of monitored files and will
+## spawn an own thread based worker for each file. Every created worker will
+## 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) {
+ $logger->Log("debug", "Starting worker thread for $file");
+ # Create worker thread for the file.
+ push @running_workers, threads->create(\&Worker,$file);
+ }
+}
+
+#
+## Function to stop all running workers.
+#
+## This function is used to stop all currently running workers and will be
+## called when reloading or shutting down guardian.
+#
+sub StopWorkers () {
+ # Loop through all running workers.
+ foreach my $worker (@running_workers) {
+ # Send the worker the "KILL" signal and detach the
+ # thread so perl can do an automatically clean-up.
+ $worker->kill('KILL');
+ }
+ $logger->Log("debug", "All workers are stopped now...");
+}
+
+#
+## Reload function.
+#
+## This function will get called if the signal handler recieves a "SIGHUP" signal,
+## or the reload command will be sent via socket connection. It is responsible for
+## reloading all configure options and stopping/starting the worker threads.
+#
+sub Reload () {
+ # Log reload.
+ $logger->Log("info", "Reload configuration...");
+
+ # Stop all running workers.
+ &StopWorkers();
+
+ # Re-read configuration file.
+ %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
+
+ # Update Logger settings.
+ $logger = Guardian::Logger->Init(%mainsettings);
+
+ # Update logger object in mainsettings hash.
+ $mainsettings{Logger} = $logger;