]> git.etc.gen.nz Git - spong.git/commitdiff
added fix in new() method for Perl's that have readdir() implemenatations that misbeh...
authorStephen L Johnson <sjohnson@monsters.org>
Mon, 7 Feb 2000 04:48:03 +0000 (04:48 +0000)
committerStephen L Johnson <sjohnson@monsters.org>
Mon, 7 Feb 2000 04:48:03 +0000 (04:48 +0000)
src/lib/Spong/ServiceList.pm

index c2fe484ad2a32105b8ffef5bde18b3e3b351146b..6d9d1f80b382a337893735f71c44cb6884211e6d 100755 (executable)
@@ -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;