summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-11-10 08:12:00 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-11-10 08:12:00 -0800
commiteeeae8262a02d299c754fc0ba97024d746d35c44 (patch)
tree6565a622cbe66391a7928a2412dbbd957eefc320
parent97bc0ed6b7d3f47fcf3216c20ab1a50ee269d55e (diff)
downloadvyatta-op-eeeae8262a02d299c754fc0ba97024d746d35c44.tar.gz
vyatta-op-eeeae8262a02d299c754fc0ba97024d746d35c44.zip
Change pci id parsing
Make the PCI id interaction with sysfs more robust by using strtol and sprintf to explicitly convert to integer and hex.
-rw-r--r--scripts/vyatta-show-snmp-ifmib10
1 files changed, 6 insertions, 4 deletions
diff --git a/scripts/vyatta-show-snmp-ifmib b/scripts/vyatta-show-snmp-ifmib
index a0647e6..8fb1004 100644
--- a/scripts/vyatta-show-snmp-ifmib
+++ b/scripts/vyatta-show-snmp-ifmib
@@ -23,6 +23,7 @@
use strict;
use warnings;
use Getopt::Long;
+use POSIX qw(strtol);
# This is used to show values corresponding to to results IF-MIB.
my %interfaces;
@@ -52,8 +53,8 @@ sub read_sysfs {
my $val = <$f>;
close $f;
- chomp $val;
- return $val;
+
+ return strtol($val);
}
# Imitate code in net-snmp to lookup PC
@@ -65,8 +66,9 @@ sub pci_info {
return unless ( defined($vendor_id) && defined($device_id) );
- open( my $pci, '-|', "lspci -m -d $vendor_id:$device_id" )
- or die "Can't run lspci";
+ my $cmd = sprintf("lspci -m -d %04x:%04x", $vendor_id, $device_id);
+ open( my $pci, '-|', $cmd )
+ or die "Can't run $cmd";
my $info = <$pci>;
close $pci;