From ef4f38060813b27207508a7e870a07e801662c07 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Wed, 14 May 2003 05:49:46 +0000 Subject: [PATCH] Replaced faulty sort and compare method for checking lists with List::Compare CPAN module --- src/spong-network.pl | 9 ++++++--- src/spong-server.pl | 13 +++++++------ src/wap-spong.pl | 12 ++++++++---- src/www-spong.pl | 16 ++++++++++------ 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/spong-network.pl b/src/spong-network.pl index 68267a7..4ed8b74 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -17,7 +17,7 @@ # (2) Converted checks to new plugin mechanism (Stephen Johnson May 28, 1999) # Added user-configurable escalation mechanism # -# $Id: spong-network.pl,v 1.46 2003/01/29 22:47:57 sljohnson Exp $ +# $Id: spong-network.pl,v 1.47 2003/05/14 05:49:46 sljohnson Exp $ use Carp; use lib "@@LIBDIR@@"; @@ -34,6 +34,8 @@ use Spong::Daemon; use Spong::Status qw(status); use Spong::Log; +use List::Compare; + # Check to see if the Time::HiRes module is available eval { require Time::HiRes; import Time::HiRes qw(time); }; if (! $@ ) { $hires = 1; } else { $hires = 0; }; @@ -489,8 +491,9 @@ sub load_config_files { # Fallback, if we didn't read things correctly... - if( sort ( @HOSTS_LIST ) != sort ( keys %HOSTS ) ) { - @HOSTS_LIST = sort keys %HOSTS; } + my $lc = List::Compare->new( \@HOSTS_LIST, \@{[keys %HOSTS]} ); + + if( ! $lc->is_LequivalentR ) { @HOSTS_LIST = sort keys %HOSTS; } &debug( "host file loaded" ); } diff --git a/src/spong-server.pl b/src/spong-server.pl index 916f1b5..6ab7dfd 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -6,7 +6,7 @@ # There are one or more update processes that listen for status updates # from client programs. -# $Id: spong-server.pl,v 1.57 2003/05/14 03:47:13 sljohnson Exp $ +# $Id: spong-server.pl,v 1.58 2003/05/14 05:49:46 sljohnson Exp $ use lib "@@LIBDIR@@"; @@ -21,6 +21,8 @@ use Spong::Log; use Spong::HostGroups; use Spong::ConfigFile; +use List::Compare; + use Sys::Hostname; use File::Path; use Socket; @@ -1340,9 +1342,8 @@ sub load_config_files { eval $evalme || die "Invalid spong.hosts file: $@"; # Fallback, if we didn't read things correctly... - - if( sort ( @HOSTS_LIST ) != sort ( keys %HOSTS ) ) { - @HOSTS_LIST = sort keys %HOSTS; } + my $lc = List::Compare->new( \@HOSTS_LIST, \@{[keys %HOSTS]} ); + if( ! $lc->is_LequivalentR ) { @HOSTS_LIST = sort keys %HOSTS; } # Do the same thing for the groups file. @@ -1357,8 +1358,8 @@ sub load_config_files { close( GROUPS ); eval $evalme || die "Invalid spong.groups file: $@"; - if( sort ( @GROUPS_LIST ) != sort ( keys %GROUPS ) ) { - @GROUPS_LIST = sort keys %GROUPS; } + $lc = List::Compare->new( \@GROUPS_LIST, \@{[keys %GROUPS]} ); + if( ! $lc->is_LequivalentR ) { @GROUPS_LIST = sort keys %GROUPS; } } diff --git a/src/wap-spong.pl b/src/wap-spong.pl index b6c139a..a59c514 100644 --- a/src/wap-spong.pl +++ b/src/wap-spong.pl @@ -13,11 +13,15 @@ # (3) Re-did as a client which gets info from the spong-server (07/24/1997) # (4) Did a whole bunch of stuff (Ed Hill, 06/18/1998) +use lib "@@LIBDIR@@"; + use Sys::Hostname; use Getopt::Long; use Socket; use POSIX; +use List::Compare; + # Load our configuration variables, including the user specified configuration # information (spong.conf, spong.hosts, and spong.groups files). @@ -662,9 +666,9 @@ sub load_config_files { eval $evalme || die "Invalid spong.hosts file: $@"; # Fallback, if we didn't read things correctly... + my $lc = List::Compare->new( \@HOSTS_LIST, \@{[keys %HOSTS]} ); + if( ! $lc->is_LequivalentR ) { @HOSTS_LIST = sort keys %HOSTS; } - if( sort ( @HOSTS_LIST ) != sort ( keys %HOSTS ) ) { - @HOSTS_LIST = sort keys %HOSTS; } # Do the same thing for the groups file. @@ -679,8 +683,8 @@ sub load_config_files { close( GROUPS ); eval $evalme || die "Invalid spong.groups file: $@"; - if( sort ( @GROUPS_LIST ) != sort ( keys %GROUPS ) ) { - @GROUPS_LIST = sort keys %GROUPS; } + $lc = List::Compare->new( \@GROUPS_LIST, \@{[keys %GROUPS]} ); + if( ! $lc->is_LequivalentR ) { @GROUPS_LIST = sort keys %GROUPS; } } diff --git a/src/www-spong.pl b/src/www-spong.pl index 0124e54..eb76642 100755 --- a/src/www-spong.pl +++ b/src/www-spong.pl @@ -12,13 +12,17 @@ # (3) Re-did as a client which gets info from the spong-server (07/24/1997) # (4) Did a whole bunch of stuff (Ed Hill, 06/18/1998) # -# $Id: www-spong.pl,v 1.21 2003/01/29 23:00:12 sljohnson Exp $ +# $Id: www-spong.pl,v 1.22 2003/05/14 05:49:46 sljohnson Exp $ + +use lib "@@@LIBDIR@@"; use Sys::Hostname; use Getopt::Long; use Socket; use POSIX; +use List::Compare; + # Load our configuration variables, including the user specified configuration # information (spong.conf, spong.hosts, and spong.groups files). @@ -642,10 +646,9 @@ sub load_config_files { eval $evalme || die "Invalid spong.hosts file: $@"; # Fallback, if we didn't read things correctly... + my $lc = List::Compare->new( \@HOSTS_LIST, \@{[keys %HOSTS]} ); + if( ! $lc->is_LequivalentR ) { @HOSTS_LIST = sort keys %HOSTS; } - if( sort ( @HOSTS_LIST ) != sort ( keys %HOSTS ) ) { - @HOSTS_LIST = sort keys %HOSTS; } - # Do the same thing for the groups file. $evalme = ""; @@ -659,8 +662,9 @@ sub load_config_files { close( GROUPS ); eval $evalme || die "Invalid spong.groups file: $@"; - if( sort ( @GROUPS_LIST ) != sort ( keys %GROUPS ) ) { - @GROUPS_LIST = sort keys %GROUPS; } + $lc = List::Compare->new( \@GROUPS_LIST, \@{[keys %GROUPS]} ); + if( ! $lc->is_LequivalentR ) { @GROUPS_LIST = sort keys %GROUPS; } + } -- 2.30.2