From a27530c6b20d65c75b86146bd8c9db559ba9e0df Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 16 Oct 2014 21:18:11 +0200 Subject: [PATCH] guardian: Rework daemonize function. --- config/guardian/guardian.pl | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/config/guardian/guardian.pl b/config/guardian/guardian.pl index 3d3f26c343..82580a925c 100644 --- a/config/guardian/guardian.pl +++ b/config/guardian/guardian.pl @@ -589,24 +589,28 @@ sub logger { } } +# +## Function to daemonize guardian. +# sub daemonize { - my ($home); - if (fork()) { -# parent - exit(0); - } else { -# child - &logger("debug", "Guardian process id $$\n"); - $home = (getpwuid($>))[7] || die "No home directory!\n"; - chdir($home); # go to my homedir - setpgrp(0,0); # become process leader - close(STDOUT); - close(STDIN); - close(STDERR); - print "Testing...\n"; + my $home; + + # Daemonize guardian. + my $pid = fork(); + + # Die if we got no process id returned. + if ($pid < 0) { + die "Could not fork: $!\n"; + } + # Everything done. + elsif ($pid) { + exit 0; } } +# +## Function for capturing process signals. +# sub sig_handler_setup { $SIG{INT} = \&clean_up_and_exit; # kill -2 $SIG{TERM} = \&clean_up_and_exit; # kill -9 -- 2.39.5