X-Git-Url: http://git.ipfire.org/?p=people%2Fstevee%2Fguardian.git;a=blobdiff_plain;f=guardian;h=f3c287b593305caf7769618a3439d33c5131cbf8;hp=cf759b04821511c5394567dadf0e28f1e3522d81;hb=4d19939e53a4dfca420b683dd2bb8157d7d24fdd;hpb=3111df627870b496ce35c30192098db316a64da4 diff --git a/guardian b/guardian index cf759b0..f3c287b 100644 --- a/guardian +++ b/guardian @@ -265,6 +265,7 @@ sub SignalHandler { $SIG{INT} = \&Shutdown; $SIG{TERM} = \&Shutdown; $SIG{QUIT} = \&Shutdown; + $SIG{HUP} = \&Reload; } # @@ -294,10 +295,31 @@ sub StopWorkers () { 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')->detach(); + $worker->kill('KILL'); } } +# +## 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 () { + # Stop all running workers. + &StopWorkers(); + + # Re-read configuration file. + %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"}); + + # Re-generate hash of monitored files. + %monitored_files = &Guardian::Base::GenerateMonitoredFiles(\%mainsettings, \%monitored_files); + + # Restart the worker threads. + &StartWorkers(); +} + # ## Shutdown function. # @@ -311,6 +333,11 @@ sub Shutdown () { # Remove socket file on exit. &Guardian::Socket::RemoveSocketFile(); + # Sleep for one second to give perl some + # time to proper clean up everything before + # exiting. + sleep(1); + # Exit guardian. exit; }