diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-04-02 09:50:06 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-04-02 09:50:06 -0700 |
commit | b68ac2b1969060ea6fa2f011a3107c83ad26e96d (patch) | |
tree | 095e7b1269f5413c72f97c5c7b19a4ee756f211c /lib/Vyatta | |
parent | c50d5766a919fa44642543bffa23d17986ee329c (diff) | |
download | vyatta-cfg-b68ac2b1969060ea6fa2f011a3107c83ad26e96d.tar.gz vyatta-cfg-b68ac2b1969060ea6fa2f011a3107c83ad26e96d.zip |
Use opendir/grep to get rid of running ls/grep
Do file scanning in perl directly rather than using extra
programs. Motivated by desire to get rid of perlcritic warning
rather than any real performance issue.
Diffstat (limited to 'lib/Vyatta')
-rwxr-xr-x | lib/Vyatta/Keepalived.pm | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm index 437b055..403d385 100755 --- a/lib/Vyatta/Keepalived.pm +++ b/lib/Vyatta/Keepalived.pm @@ -164,17 +164,18 @@ sub intf_sort { sub get_state_files { my ($intf, $group) = @_; + opendir my $sdir, $state_dir + or die "Can't open $state_dir: $!\n"; + my @state_files; - my $LS; if ($group eq "all") { - open($LS,"ls $state_dir |grep '^vrrpd_$intf.*\.state\$' |"); + @state_files = grep { /^vrrpd_$intf.*\.state$/ } $sdir; } else { my $intf_group = $intf . "_" . $group . ".state"; - open($LS, - "ls $state_dir |grep '^vrrpd_$intf_group\$' |"); + @state_files = grep { /^vrrpd_$intf_group$/ } $sdir; } - @state_files = <$LS>; - close($LS); + close $sdir; + @state_files = intf_sort(@state_files); foreach my $i (0 .. $#state_files) { $state_files[$i] = "$state_dir/$state_files[$i]"; |