From 915d9f4513423b25b2dfb1a375c0476a0394b9b4 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Mon, 23 Nov 2015 10:34:55 +0100 Subject: [PATCH] Capture process signals. 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 --- guardian | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/guardian b/guardian index 3435c09..2ec8ac4 100644 --- a/guardian +++ b/guardian @@ -102,6 +102,9 @@ while(1) { ## is starting. # sub Init () { + # Setup signal handler. + &SignalHandler(); + # Setup IPC mechanism via Socket in an own thread. threads->create(\&Socket); @@ -260,3 +263,29 @@ sub Init_fileposition ($) { # 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; +} -- 2.39.2