Use local file handles, use three argument open. Don't modify arguments in perl grep (use sed instead)
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -49,10 +49,10 @@ sub usage { · 48 unmodified lines | ||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | sub collectcfiles { |
| 52 | − my @file = `cat .tmp_versions/*.mod | grep '.*\.ko\$'`; | |
| 53 | − @file = grep {s/\.ko/.mod.c/} @file; | |
| 54 | − chomp @file; | |
| 55 | − return @file; | |
| 52 | + my @file | |
| 53 | + = `cat .tmp_versions/*.mod | grep '.*\.ko\$' | sed s/\.ko$/.mod.c/`; | |
| 54 | + chomp @file; | |
| 55 | + return @file; | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | my (%SYMBOL, %MODULE, %opt, @allcfiles); |
| @@ -71,37 +71,40 @@ if (not defined $opt{'k'}) { · 12 unmodified lines | ||
| 71 | 71 | $opt{'k'} = "Module.symvers"; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | −unless (open(MODULE_SYMVERS, $opt{'k'})) { | |
| 75 | − die "Sorry, cannot open $opt{'k'}: $!\n"; | |
| 76 | −} | |
| 74 | +open (my $module_symvers, '<', $opt{'k'}) | |
| 75 | + or die "Sorry, cannot open $opt{'k'}: $!\n"; | |
| 77 | 76 | |
| 78 | 77 | if (defined $opt{'o'}) { |
| 79 | − unless (open(OUTPUT_HANDLE, ">$opt{'o'}")) { | |
| 80 | − die "Sorry, cannot open $opt{'o'} $!\n"; | |
| 81 | − } | |
| 82 | − select OUTPUT_HANDLE; | |
| 78 | + open (my $out, '>', $opt{'o'}) | |
| 79 | + or die "Sorry, cannot open $opt{'o'} $!\n"; | |
| 80 | + | |
| 81 | + select $out; | |
| 83 | 82 | } |
| 83 | + | |
| 84 | 84 | # |
| 85 | 85 | # collect all the symbols and their attributes from the |
| 86 | 86 | # Module.symvers file |
| 87 | 87 | # |
| 88 | −while ( <MODULE_SYMVERS> ) { | |
| 88 | +while ( <$module_symvers> ) { | |
| 89 | 89 | chomp; |
| 90 | 90 | my (undef, $symbol, $module, $gpl) = split; |
| 91 | 91 | $SYMBOL { $symbol } = [ $module , "0" , $symbol, $gpl]; |
| 92 | 92 | } |
| 93 | −close(MODULE_SYMVERS); | |
| 93 | +close($module_symvers); | |
| 94 | 94 | |
| 95 | 95 | # |
| 96 | 96 | # collect the usage count of each symbol. |
| 97 | 97 | # |
| 98 | 98 | foreach my $thismod (@allcfiles) { |
| 99 | − unless (open(MODULE_MODULE, $thismod)) { | |
| 100 | − print "Sorry, cannot open $thismod: $!\n"; | |
| 99 | + my $module; | |
| 100 | + | |
| 101 | + unless (open ($module, '<', $thismod)) { | |
| 102 | + warn "Sorry, cannot open $thismod: $!\n"; | |
| 101 | 103 | next; |
| 102 | 104 | } |
| 105 | + | |
| 103 | 106 | my $state=0; |
| 104 | − while ( <MODULE_MODULE> ) { | |
| 107 | + while ( <$module> ) { | |
| 105 | 108 | chomp; |
| 106 | 109 | if ($state == 0) { |
| 107 | 110 | $state = 1 if ($_ =~ /static const struct modversion_info/); |
| @@ -124,7 +127,7 @@ foreach my $thismod (@allcfiles) { · 16 unmodified lines | ||
| 124 | 127 | if ($state != 2) { |
| 125 | 128 | print "WARNING:$thismod is not built with CONFIG_MODVERSION enabled\n"; |
| 126 | 129 | } |
| 127 | − close(MODULE_MODULE); | |
| 130 | + close($module); | |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | 133 | print "\tThis file reports the exported symbols usage patterns by in-tree\n", |