From: Stephen L Johnson Date: Mon, 7 Feb 2000 04:48:03 +0000 (+0000) Subject: added fix in new() method for Perl's that have readdir() implemenatations that misbeh... X-Git-Tag: spong-2_7-alpha5~98 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7b922d4261a31fec43f4975a710e8a8794b73e9;p=spong.git added fix in new() method for Perl's that have readdir() implemenatations that misbehave. It is activation by adding $SERVICELISTFIX = 1 into spong.conf. --- diff --git a/src/lib/Spong/ServiceList.pm b/src/lib/Spong/ServiceList.pm index c2fe484..6d9d1f8 100755 --- a/src/lib/Spong/ServiceList.pm +++ b/src/lib/Spong/ServiceList.pm @@ -43,27 +43,55 @@ sub new { # Go through the database, and grab the name and state of each service # running on this host. - opendir( DIR, "$main::SPONGDB/$host/services" ); - while( defined( $_ = readdir( DIR ) ) ) { - next unless /^(.*)-(green|yellow|red)$/ ; - my( $name, $color ) = ($1, $2); + if ( ! $main::SERVICELISTFIX ) { + opendir( DIR, "$main::SPONGDB/$host/services" ); + while( defined( $_ = readdir( DIR ) ) ) { + next unless /^(.*)-(green|yellow|red)$/ ; + my( $name, $color ) = ($1, $2); + + # A hack to get around a local problem. + if( $name eq "procs" ) { $name = "jobs"; } + + $got_one = 1; + my( $rtime ) = (stat( "$main::SPONGDB/$host/services/$_" ))[9]; + my $service = Spong::Service->new( $host, $name ); + + $service->rtime( $rtime ); + if( $rtime < ( time() - (3 * $main::SPONGSLEEP) ) ) { + $service->rcolor( $color ); $service->color( "purple" ); + } else { + $service->rcolor( $color ); $service->color( $color ); + } + $service_hash{$name} = $service; + } + closedir( DIR ); + } else { + my @files = (); + { + local $SIG{'CHLD'} = 'IGNORE'; + eval { @files = `cd $main::SPONGDB/$host/services/; ls *`; }; + } + foreach ( @files ) { + chomp; + next unless /^(.*)-(green|yellow|red)$/ ; + my( $name, $color ) = ($1, $2); - # A hack to get around a local problem. - if( $name eq "procs" ) { $name = "jobs"; } + # A hack to get around a local problem. + if( $name eq "procs" ) { $name = "jobs"; } - $got_one = 1; - my( $rtime ) = (stat( "$main::SPONGDB/$host/services/$_" ))[9]; - my $service = Spong::Service->new( $host, $name ); + $got_one = 1; + my( $rtime ) = (stat( "$main::SPONGDB/$host/services/$_" ))[9]; + my $service = Spong::Service->new( $host, $name ); - $service->rtime( $rtime ); - if( $rtime < ( time() - (3 * $main::SPONGSLEEP) ) ) { - $service->rcolor( $color ); $service->color( "purple" ); - } else { - $service->rcolor( $color ); $service->color( $color ); + $service->rtime( $rtime ); + if( $rtime < ( time() - (3 * $main::SPONGSLEEP) ) ) { + $service->rcolor( $color ); $service->color( "purple" ); + } else { + $service->rcolor( $color ); $service->color( $color ); + } + $service_hash{$name} = $service; } - $service_hash{$name} = $service; } - closedir( DIR ); return undef unless $got_one;