]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
guardian: Rework daemonize function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 16 Oct 2014 19:18:11 +0000 (21:18 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 16 Oct 2014 19:18:11 +0000 (21:18 +0200)
config/guardian/guardian.pl

index 3d3f26c3430217068cf6a5c5508ff3dc5e7324b7..82580a925c134755808e964a9557ede6a10bb588 100644 (file)
@@ -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