Messages in this thread Patch in this message | | | Subject | Re: Stripped kernel modules? | From | (Aaron M. Ucko) | Date | 20 May 1998 13:20:51 -0500 |
| |
Nitpickish patch, mostly to address my dislike of easily avoided single-argument calls to system (multi-argument calls being safer and more efficient):
--- selstrip.pl.dist Wed May 20 12:59:39 1998 +++ selstrip.pl Wed May 20 13:11:19 1998 @@ -26,6 +26,7 @@ require 5; use strict; use English; +use POSIX; my $strip = "/usr/bin/strip"; my $nm = "/usr/bin/nm"; @@ -33,10 +34,10 @@ my $mv = "/bin/mv"; my $rm = "/bin/rm"; my $tmp = "/tmp"; -my $command_size = 400; # arbitrary but safe my $tmpcopy = "$tmp/$PID.object"; -my $nmout = "$tmp/$PID.nmout"; + +my $command_size = sysconf(&_SC_ARG_MAX) - length("$strip $tmpcopy "); my $i; @@ -44,17 +45,18 @@ strip_module($ARGV[$i]); } -do_command("$rm -f $tmpcopy $nmout"); +# do_command($rm, '-f', $tmpcopy, $nmout); +unlink $tmpcopy or die "unlink failed: $ERRNO"; exit(0); sub strip_module() { my ($object) = @_; - my (%keep, %to_strip, $symbol, $command, $changed, $line, @f); - do_command("$cp -a $object $tmpcopy"); - do_command("$nm $tmpcopy > $nmout"); - open(NMOUT, "<$nmout") || die "cannot read $nmout"; + my (%keep, %to_strip, $symbol, @command, $cmdlen, $changed, $line); + my (@f, $s); + do_command($cp, '-a', $object, $tmpcopy); + open(NMOUT, "$nm $tmpcopy|") || die "nm failed: $ERRNO"; while (defined($line = <NMOUT>)) { chop($line); my @field = split(' ', substr($line, 9)); @@ -95,32 +97,36 @@ } } close(NMOUT); - $command = ""; + @command = (); + $cmdlen = 0; $changed = 0; foreach $symbol (keys(%to_strip)) { if (!defined($keep{$symbol})) { $changed = 1; - if (length($command) > $command_size) { - do_command("$strip $command $tmpcopy"); - $command = ""; + $s = "--strip-symbol=$symbol"; + if ($cmdlen + length($s) >= $command_size) { + do_command($strip, @command, $tmpcopy); + @command = (); + $cmdlen = 0; } - $command = "$command --strip-symbol=$symbol"; + push(@command, $s); + $cmdlen += length("$s "); } } - if ($command ne "") { + if (@command) { $changed = 1; - do_command("$strip $command $tmpcopy"); + do_command($strip, @command, $tmpcopy); } if ($changed) { - do_command("$mv $tmpcopy $object"); + do_command($mv, $tmpcopy, $object); } } sub do_command() { - my ($command) = @_; + my @command = @_; my $ret; - if (($ret = system($command)) != 0) { - die("command \"$command\" failed $ret"); + if (($ret = system(@command)) != 0) { + die('command "', join(' ', @command), "\" failed ($ret)"); } }
-- Aaron M. Ucko <amu@mit.edu> (finger amu@monk.mit.edu) [Stark raving sane]
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu
| |