From 0e7340bf6b421b698578a908fa67ca6f629d698c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 9 Nov 2011 08:13:45 -0800 Subject: Fix perlcritic warning about bareword file handle dhcpv6-show-leases use 3 arg open and local file handle --- scripts/dhcpv6-client-show-leases.pl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/dhcpv6-client-show-leases.pl b/scripts/dhcpv6-client-show-leases.pl index 546668c..44be689 100644 --- a/scripts/dhcpv6-client-show-leases.pl +++ b/scripts/dhcpv6-client-show-leases.pl @@ -74,13 +74,11 @@ my %ghash = (); foreach my $lease_filename (@lease_files) { my @lines=(); - if (!open(LEASE_FILE, "; - close(LEASE_FILE); + @lines = <$f>; + close $f; chomp @lines; my $level = 0; -- cgit v1.2.3 From 02396d787f4f693622b3d0aef675473ff417a783 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 9 Nov 2011 08:17:28 -0800 Subject: cleanup rename-image 1. Get rid of perl critic warnings about use of bare file handles and open 2. Use perl rather than system() to copy and move files and check for errors. 3. Use perl rather than system() to access syslog. --- scripts/rename-image.pl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/rename-image.pl b/scripts/rename-image.pl index 8632334..be30967 100644 --- a/scripts/rename-image.pl +++ b/scripts/rename-image.pl @@ -24,6 +24,8 @@ use strict; use warnings; use Getopt::Long; use File::Temp qw/ tempfile tempdir /; +use File::Copy; +use Sys::Syslog qw/:standard :macros/; my $UNION_BOOT = '/live/image/boot'; my $XEN_DEFAULT_IMAGE = "$UNION_BOOT/%%default_image"; @@ -99,16 +101,14 @@ my $tmpfh; my $tmpfilename; ($tmpfh, $tmpfilename) = tempfile(); -if (!open (GRUBFH, "<${image_path}/grub/grub.cfg")) { - printf("Can't open grub file.\n"); - exit 1; -} +open (my $grubfh, '<', "${image_path}/grub/grub.cfg") + or die "Can't open grub file.\n"; # This is sensitive to the format of menu entries and boot paths # in the grub config file. # my $line; -while ($line = ) { +while ($line = <$grubfh>) { $line =~ s/\/boot\/$old_name/\/boot\/$new_name/g; $line =~ s/Vyatta $old_name/Vyatta $new_name/; $line =~ s/Vyatta image $old_name/Vyatta image $new_name/; @@ -117,13 +117,14 @@ while ($line = ) { } close($tmpfh); -close(GRUBFH); +close($grubfh); -system("mv $image_path/$old_name $image_path/$new_name"); -system("cp $tmpfilename $image_path/grub/grub.cfg"); +mv("$image_path/$old_name", "$image_path/$new_name") + or die "rename $old_name to $new_name failed: $!\n"; +cp($tmpfilename, "$image_path/grub/grub.cfg") + or die "copy $tmpfilename to grub.cfg failed: $!\n"; -system("logger -p local3.warning -t 'SystemImage' 'System image $old_name has been renamed $new_name'"); +syslog("warning", "System image $old_name has been renamed $new_name"); printf("Done.\n"); - -- cgit v1.2.3