summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Keepalived.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Vyatta/Keepalived.pm')
-rwxr-xr-xlib/Vyatta/Keepalived.pm41
1 files changed, 38 insertions, 3 deletions
diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm
index 13966c5..6d6a153 100755
--- a/lib/Vyatta/Keepalived.pm
+++ b/lib/Vyatta/Keepalived.pm
@@ -125,21 +125,56 @@ sub get_master_file {
return $file;
}
+sub alphanum_split {
+ my ($str) = @_;
+ my @list = split m/(?=(?<=\D)\d|(?<=\d)\D)/, $str;
+ return @list;
+}
+
+sub natural_order {
+ my ($a, $b) = @_;
+ my @a = alphanum_split($a);
+ my @b = alphanum_split($b);
+
+ while (@a && @b) {
+ my $a_seg = shift @a;
+ my $b_seg = shift @b;
+ my $val;
+ if (($a_seg =~ /\d/) && ($b_seg =~ /\d/)) {
+ $val = $a_seg <=> $b_seg;
+ } elsif (($a_seg eq '.') && ($b_seg eq '_')) {
+ return 1;
+ } else {
+ $val = $a_seg cmp $b_seg;
+ }
+ if ($val != 0) {
+ return $val;
+ }
+ }
+ return @a <=> @b;
+}
+
+sub intf_sort {
+ my @a = @_;
+ my @new_a = sort { natural_order($a,$b) } @a;
+ return @new_a;
+}
+
sub get_state_files {
my ($intf, $group) = @_;
- # todo: fix sorting for ethX > 9
my @state_files;
my $LS;
if ($group eq "all") {
- open($LS,"ls $state_dir |grep '^vrrpd_$intf.*\.state\$' | sort |");
+ open($LS,"ls $state_dir |grep '^vrrpd_$intf.*\.state\$' |");
} else {
my $intf_group = $intf . "_" . $group . ".state";
open($LS,
- "ls $state_dir |grep '^vrrpd_$intf_group\$' | sort |");
+ "ls $state_dir |grep '^vrrpd_$intf_group\$' |");
}
@state_files = <$LS>;
close($LS);
+ @state_files = intf_sort(@state_files);
foreach my $i (0 .. $#state_files) {
$state_files[$i] = "$state_dir/$state_files[$i]";
}