]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
guardian: Write-out process id to pidfile (/run/guardian.pid).
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 20 Oct 2014 18:51:14 +0000 (20:51 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 20 Oct 2014 18:51:14 +0000 (20:51 +0200)
config/guardian/guardian

index 9124e2b3b1e2b7617496ddd582a382bd6269b0f8..d3f4acce82e5bd912ac48e753ee2a23b6b299163 100644 (file)
@@ -43,6 +43,8 @@ my $TimeLimit = "86400";
 my $hostgatewaybyte = "1";
 
 our $watcher;
+# Pidfile to store the process-id of the running daemon.
+my $pidfile = "/run/guardian.pid";
 
 # Path to guardianctrl.
 my $guardianctrl = "/usr/local/bin/guardianctrl";
@@ -691,6 +693,15 @@ sub daemonize {
        elsif ($pid) {
                exit 0;
        }
+
+       # Create pidfile.
+       open(PIDFILE, ">$pidfile") or die "Could not write pidfile. $!\n";
+
+       # Write process-id to the pidfile.
+       print PIDFILE "$$";
+
+       # Close pidfile.
+       close(PIDFILE);
 }
 
 #
@@ -792,6 +803,9 @@ sub clean_up_and_exit {
                &logger("debug", "Removing $address for shutdown\n");
                &call_unblock ($address);
        }
+       # Delete pidfile.
+       unlink $pidfile;
+
        exit;
 }