export_report: do collectcfiles work in perl itself
authorJim Cromie <jim.cromie@gmail.com>
Mon, 23 May 2011 18:44:55 +0000 (12:44 -0600)
committerMichal Marek <mmarek@suse.cz>
Tue, 24 May 2011 14:07:07 +0000 (16:07 +0200)
Avoid spawning a shell pipeline doing cat, grep, sed, and do it all
inside perl.  The <*.c> globbing construct works at least as far back
as 5.8.9

Note that this is not just an optimization; the sed command
in the pipeline was unterminated, due to lack of escape on the
end-of-line (\$) in the regex, resulting in this:

    $ perl ../linux-2.6/scripts/export_report.pl  > /dev/null
    sed: -e expression #1, char 5: unterminated `s' command
    sh: .mod.c/: not found

Comments on an earlier patch sought an all-perl implementation.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
cc: Michal Marek <mmarek@suse.cz>,
cc: linux-kbuild@vger.kernel.org
cc: Arnaud Lacombe lacombar@gmail.com
cc: Stephen Hemminger shemminger@vyatta.com
Signed-off-by: Michal Marek <mmarek@suse.cz>
scripts/export_report.pl

index 04dce7c..f97899c 100644 (file)
@@ -49,8 +49,14 @@ sub usage {
 }
 
 sub collectcfiles {
-    my @file
-       = `cat .tmp_versions/*.mod | grep '.*\.ko\$' | sed s/\.ko$/.mod.c/`;
+    my @file;
+    while (<.tmp_versions/*.mod>) {
+       open my $fh, '<', $_ or die "cannot open $_: $!\n";
+       push (@file,
+             grep s/\.ko/.mod.c/,      # change the suffix
+             grep m/.+\.ko/,           # find the .ko path
+             <$fh>);                   # lines in opened file
+    }
     chomp @file;
     return @file;
 }