]> git.ipfire.org Git - people/stevee/guardian.git/commitdiff
Capture process signals.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 23 Nov 2015 09:34:55 +0000 (10:34 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 23 Nov 2015 09:34:55 +0000 (10:34 +0100)
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>
guardian

index 3435c096690ec8a8f4d27342b51b7e17416c5e5b..2ec8ac4b4cf59cd7399b4767d5a2e9183dc1cb23 100644 (file)
--- a/guardian
+++ b/guardian
@@ -102,6 +102,9 @@ while(1) {
 ## 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);
 
@@ -260,3 +263,29 @@ sub Init_fileposition ($) {
        # 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;
+}