guardian now captures sent process siganls and can perform
various actions based on the captured signal. Currently only
"INT", "TERM", and "QUIT" signals are handeled. Some other
may be added in the future.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
## is starting.
#
sub Init () {
## is starting.
#
sub Init () {
+ # Setup signal handler.
+ &SignalHandler();
+
# Setup IPC mechanism via Socket in an own thread.
threads->create(\&Socket);
# Setup IPC mechanism via Socket in an own thread.
threads->create(\&Socket);
# Return the position.
return $position;
}
# Return the position.
return $position;
}
+
+#
+## Function for capturing process signals.
+#
+## This function captures any sent process signals and will call various
+## actions, basend on the captured signal.
+#
+sub SignalHandler {
+ $SIG{INT} = \&Shutdown;
+ $SIG{TERM} = \&Shutdown;
+ $SIG{QUIT} = \&Shutdown;
+}
+
+#
+## Shutdown function.
+#
+## This function is used to do a clean shutdown of guardian. It will be called
+## by the signal handler when recieving INT (2), QUIT (3) and TERM (15) signals.
+#
+sub Shutdown () {
+ # Remove socket file on exit.
+ &Guardian::Socket::RemoveSocketFile();
+
+ # Exit guardian.
+ exit;
+}