From d76125e4fff6c06d636507116804dfee23c4230c Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Tue, 14 Mar 2000 23:11:05 +0000 Subject: [PATCH] added check to abort spong-network if it is already running --- src/spong-network.pl | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/spong-network.pl b/src/spong-network.pl index 3cd967f..1b95974 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -36,8 +36,8 @@ srand( time() ^ ($$ + ($$ << 15 )) ); $debug = $restart = $kill = 0; -Getopt::Long::Configure('pass_through'); -if ( ! GetOptions("debug:i" => \$debuglevel, "restart" => \$restart, +#Getopt::Long::Configure('pass_through'); +if ( ! GetOptions("debug=i" => \$debuglevel, "restart" => \$restart, "kill" => \$kill, "nosleep|refresh" => \$nosleep ) ) { &usage(); exit 1; @@ -65,7 +65,7 @@ Spong::Daemon::Daemonize() # Daemonize if not signalling or a one-shot while( 1 ) { foreach $host ( @HOSTS_LIST ) { - &debug( "checking network services ($checks) on $host" ); + &debug( "checking network services on $host" ); my $check; foreach $check (('ping',split(/\s+/,$HOSTS{$host}->{'services'}))) { @@ -343,12 +343,34 @@ sub handle_signals { exit(0); } + # Check to see if we are already running + &already_running(); + # Write our pid to the spong tmp directory. system( "echo $$ >$SPONGTMP/spong-network.pid" ) unless $nosleep; } +# This routine check to see if another instance of spong-server is already +# running. If there is another instance, this instance will complain and die + +sub already_running { + # if there is a PID file + if ( -f "$SPONGTMP/spong-network.pid" ) { + # Read the pid + open( PID, "$SPONGTMP/spong-network.pid" ) || die "Can't open pid: $!"; + my $pid = ; chomp $pid; + close PID; + + if ( kill 0,$pid ) { + &error("Spong-network is already running as pid $pid"); + exit 1; + } + } +} + + # Output functions, one for debugging information, the other for errors. sub debug { Spong::Log::debug($_[0],$_[1]); } -- 2.30.2