From: Stefan Schantl Date: Mon, 20 Oct 2014 18:51:14 +0000 (+0200) Subject: guardian: Write-out process id to pidfile (/run/guardian.pid). X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da6ba086b48e5690dfbc91730f25a53b054f76c9;p=people%2Fstevee%2Fipfire-2.x.git guardian: Write-out process id to pidfile (/run/guardian.pid). --- diff --git a/config/guardian/guardian b/config/guardian/guardian index 9124e2b3b1..d3f4acce82 100644 --- a/config/guardian/guardian +++ b/config/guardian/guardian @@ -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; }