mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 06:15:15 +00:00
Perl cleanups as suggested by ton of #perl@ircnet (part 1).
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2639 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
@@ -1659,6 +1659,8 @@ sub swap_bytes
|
|||||||
# $_[0] is the sought value
|
# $_[0] is the sought value
|
||||||
# @_[1..] is the list to seek in
|
# @_[1..] is the list to seek in
|
||||||
# Returns: 0 on failure, 1 if found.
|
# Returns: 0 on failure, 1 if found.
|
||||||
|
# Note: Every use of this sub probably indicates the use of the wrong
|
||||||
|
# datastructure
|
||||||
sub contains
|
sub contains
|
||||||
{
|
{
|
||||||
my $sought = shift;
|
my $sought = shift;
|
||||||
@@ -1672,7 +1674,7 @@ sub parse_not_to_scan
|
|||||||
{
|
{
|
||||||
my ($min,$max,$to_parse) = @_;
|
my ($min,$max,$to_parse) = @_;
|
||||||
my @ranges = split /\s*,\s*/, $to_parse;
|
my @ranges = split /\s*,\s*/, $to_parse;
|
||||||
my @res = ();
|
my @res;
|
||||||
my $range;
|
my $range;
|
||||||
foreach $range (@ranges) {
|
foreach $range (@ranges) {
|
||||||
my ($start,$end) = split /\s*-s*/, $range;
|
my ($start,$end) = split /\s*-s*/, $range;
|
||||||
@@ -1784,7 +1786,7 @@ use vars qw($modules_conf $dev_i2c);
|
|||||||
sub initialize_conf
|
sub initialize_conf
|
||||||
{
|
{
|
||||||
my $use_devfs = 0;
|
my $use_devfs = 0;
|
||||||
open INPUTFILE, "/proc/mounts" or die "Can't access /proc/mounts!";
|
open(local *INPUTFILE, "/proc/mounts") or die "Can't access /proc/mounts!";
|
||||||
while (<INPUTFILE>) {
|
while (<INPUTFILE>) {
|
||||||
if (m@^\w+ /dev devfs @) {
|
if (m@^\w+ /dev devfs @) {
|
||||||
$use_devfs = 1;
|
$use_devfs = 1;
|
||||||
@@ -1844,12 +1846,11 @@ use vars qw(%modules_list);
|
|||||||
|
|
||||||
sub initialize_modules_list
|
sub initialize_modules_list
|
||||||
{
|
{
|
||||||
open INPUTFILE, "/proc/modules" or return;
|
open(local *INPUTFILE, "/proc/modules") or return;
|
||||||
while (<INPUTFILE>) {
|
while (<INPUTFILE>) {
|
||||||
tr/_/-/;
|
tr/_/-/;
|
||||||
$modules_list{$1} = 1 if m/^(\S*)/;
|
$modules_list{$1} = 1 if m/^(\S*)/;
|
||||||
}
|
}
|
||||||
close INPUTFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
##############
|
##############
|
||||||
@@ -1865,7 +1866,7 @@ use vars qw(%pci_list);
|
|||||||
sub read_proc_dev_pci
|
sub read_proc_dev_pci
|
||||||
{
|
{
|
||||||
my ($dfn,$vend,%pci_list);
|
my ($dfn,$vend,%pci_list);
|
||||||
open INPUTFILE, "/proc/bus/pci/devices" or return;
|
open(local *INPUTFILE, "/proc/bus/pci/devices") or return;
|
||||||
while (<INPUTFILE>) {
|
while (<INPUTFILE>) {
|
||||||
my $record = {};
|
my $record = {};
|
||||||
($dfn,$vend,$record->{irq},$record->{base_addr0},$record->{base_addr1},
|
($dfn,$vend,$record->{irq},$record->{base_addr0},$record->{base_addr1},
|
||||||
@@ -1881,7 +1882,6 @@ sub read_proc_dev_pci
|
|||||||
$pci_list{ sprintf("%04x:%04x",$record->{vendid},$record->{devid}) } =
|
$pci_list{ sprintf("%04x:%04x",$record->{vendid},$record->{devid}) } =
|
||||||
$record;
|
$record;
|
||||||
}
|
}
|
||||||
close INPUTFILE or return;
|
|
||||||
return %pci_list;
|
return %pci_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1897,7 +1897,7 @@ sub initialize_proc_pci
|
|||||||
|
|
||||||
sub all_available_adapters
|
sub all_available_adapters
|
||||||
{
|
{
|
||||||
my @res = ();
|
my @res;
|
||||||
foreach my $adapter (@pci_adapters) {
|
foreach my $adapter (@pci_adapters) {
|
||||||
push @res, $adapter->{driver}
|
push @res, $adapter->{driver}
|
||||||
if exists $modules_list{$adapter->{driver}};
|
if exists $modules_list{$adapter->{driver}};
|
||||||
@@ -2391,7 +2391,7 @@ sub add_isa_to_chips_detected
|
|||||||
not exists $new_misdetected_ref->[$i]->{isa_addr} and
|
not exists $new_misdetected_ref->[$i]->{isa_addr} and
|
||||||
defined $alias_detect and
|
defined $alias_detect and
|
||||||
$new_misdetected_ref->[$i]->{chipname} eq $datahash->{chipname}) {
|
$new_misdetected_ref->[$i]->{chipname} eq $datahash->{chipname}) {
|
||||||
open FILE,"$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}" or
|
open(local *FILE, "$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}") or
|
||||||
print("Can't open $dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"),
|
print("Can't open $dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"),
|
||||||
next;
|
next;
|
||||||
binmode FILE;
|
binmode FILE;
|
||||||
@@ -2404,10 +2404,8 @@ sub add_isa_to_chips_detected
|
|||||||
$new_misdetected_ref->[$i]->{isa_addr} = $datahash->{isa_addr};
|
$new_misdetected_ref->[$i]->{isa_addr} = $datahash->{isa_addr};
|
||||||
$new_misdetected_ref->[$i]->{isa_extra} = $datahash->{isa_extra}
|
$new_misdetected_ref->[$i]->{isa_extra} = $datahash->{isa_extra}
|
||||||
if exists $datahash->{isa_extra};
|
if exists $datahash->{isa_extra};
|
||||||
close FILE;
|
|
||||||
return $new_misdetected_ref->[$i];
|
return $new_misdetected_ref->[$i];
|
||||||
}
|
}
|
||||||
close FILE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2417,7 +2415,7 @@ sub add_isa_to_chips_detected
|
|||||||
not exists $new_detected_ref->[$i]->{isa_addr} and
|
not exists $new_detected_ref->[$i]->{isa_addr} and
|
||||||
defined $alias_detect and
|
defined $alias_detect and
|
||||||
$new_detected_ref->[$i]->{chipname} eq $datahash->{chipname}) {
|
$new_detected_ref->[$i]->{chipname} eq $datahash->{chipname}) {
|
||||||
open FILE,"$dev_i2c$new_detected_ref->[$i]->{i2c_devnr}" or
|
open(local *FILE, "$dev_i2c$new_detected_ref->[$i]->{i2c_devnr}") or
|
||||||
print("Can't open $dev_i2c$new_detected_ref->[$i]->{i2c_devnr}?!?\n"),
|
print("Can't open $dev_i2c$new_detected_ref->[$i]->{i2c_devnr}?!?\n"),
|
||||||
next;
|
next;
|
||||||
binmode FILE;
|
binmode FILE;
|
||||||
@@ -2431,11 +2429,9 @@ sub add_isa_to_chips_detected
|
|||||||
$new_detected_ref->[$i]->{isa_extra} = $datahash->{isa_extra}
|
$new_detected_ref->[$i]->{isa_extra} = $datahash->{isa_extra}
|
||||||
if exists $datahash->{isa_extra};
|
if exists $datahash->{isa_extra};
|
||||||
($datahash) = splice (@$new_detected_ref, $i, 1);
|
($datahash) = splice (@$new_detected_ref, $i, 1);
|
||||||
close FILE;
|
|
||||||
$isalias=1;
|
$isalias=1;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
close FILE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2491,7 +2487,7 @@ sub scan_adapter
|
|||||||
# As we modify it, we need a copy
|
# As we modify it, we need a copy
|
||||||
my @not_to_scan = @$not_to_scan;
|
my @not_to_scan = @$not_to_scan;
|
||||||
|
|
||||||
open FILE,"$dev_i2c$adapter_nr" or
|
open(local *FILE, "$dev_i2c$adapter_nr") or
|
||||||
(print "Can't open $dev_i2c$adapter_nr\n"), return;
|
(print "Can't open $dev_i2c$adapter_nr\n"), return;
|
||||||
binmode FILE;
|
binmode FILE;
|
||||||
|
|
||||||
@@ -4521,7 +4517,7 @@ sub generate_modprobes
|
|||||||
|
|
||||||
# Collect all loaded adapters
|
# Collect all loaded adapters
|
||||||
# i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information
|
# i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information
|
||||||
open INPUTFILE,"i2cdetect -l |" or die "Couldn't find i2cdetect program!!";
|
open(local *INPUTFILE, "i2cdetect -l |") or die "Couldn't find i2cdetect program!!";
|
||||||
while (<INPUTFILE>) {
|
while (<INPUTFILE>) {
|
||||||
my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/;
|
my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/;
|
||||||
next if ($type eq "dummy");
|
next if ($type eq "dummy");
|
||||||
@@ -4581,8 +4577,6 @@ sub generate_modprobes
|
|||||||
} else {
|
} else {
|
||||||
$modprobes .= "modprobe $chip->{driver}\n";
|
$modprobes .= "modprobe $chip->{driver}\n";
|
||||||
}
|
}
|
||||||
@optionlist = ();
|
|
||||||
@probelist = ();
|
|
||||||
|
|
||||||
# Handle detects at addresses normally not probed
|
# Handle detects at addresses normally not probed
|
||||||
foreach $detection (@{$chip->{detected}}) {
|
foreach $detection (@{$chip->{detected}}) {
|
||||||
@@ -4651,22 +4645,13 @@ sub vpd_bios_build_id
|
|||||||
my $found = 0;
|
my $found = 0;
|
||||||
my $bbid;
|
my $bbid;
|
||||||
|
|
||||||
return 0
|
open(local *MEM, '/dev/mem') || return 0;
|
||||||
unless open MEM, '/dev/mem';
|
|
||||||
binmode MEM;
|
binmode MEM;
|
||||||
unless (seek MEM, $pos, SEEK_SET)
|
seek MEM, $pos, SEEK_SET || return 0;
|
||||||
{
|
|
||||||
close MEM;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
while ($pos <= 0xFFFD0 && !$found)
|
while ($pos <= 0xFFFD0 && !$found)
|
||||||
{
|
{
|
||||||
my $r = read(MEM, my $buf, 48);
|
my $r = read(MEM, my $buf, 48);
|
||||||
unless ($r == 48)
|
return 0 unless ($r == 48);
|
||||||
{
|
|
||||||
close MEM;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
seek (MEM, -32, SEEK_CUR);
|
seek (MEM, -32, SEEK_CUR);
|
||||||
my $len;
|
my $len;
|
||||||
if (substr($buf, 0, 5) eq "\xAA\x55VPD"
|
if (substr($buf, 0, 5) eq "\xAA\x55VPD"
|
||||||
@@ -4683,7 +4668,6 @@ sub vpd_bios_build_id
|
|||||||
}
|
}
|
||||||
$pos += 16;
|
$pos += 16;
|
||||||
}
|
}
|
||||||
close MEM;
|
|
||||||
|
|
||||||
return 1 unless $found;
|
return 1 unless $found;
|
||||||
print " System vendor: IBM\n";
|
print " System vendor: IBM\n";
|
||||||
@@ -4830,7 +4814,7 @@ sub main
|
|||||||
|
|
||||||
my ($inp,@not_to_scan,$inp2);
|
my ($inp,@not_to_scan,$inp2);
|
||||||
# i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information
|
# i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information
|
||||||
open INPUTFILE,"i2cdetect -l |" or die "Couldn't find i2cdetect program!!";
|
open(local *INPUTFILE, "i2cdetect -l |") or die "Couldn't find i2cdetect program!!";
|
||||||
while (<INPUTFILE>) {
|
while (<INPUTFILE>) {
|
||||||
my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/;
|
my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/;
|
||||||
next if ($type eq "dummy");
|
next if ($type eq "dummy");
|
||||||
@@ -4839,7 +4823,6 @@ sub main
|
|||||||
print "Do you want to scan it? (YES/no/selectively): ";
|
print "Do you want to scan it? (YES/no/selectively): ";
|
||||||
|
|
||||||
$inp = <STDIN>;
|
$inp = <STDIN>;
|
||||||
@not_to_scan=();
|
|
||||||
if ($inp =~ /^\s*[Ss]/) {
|
if ($inp =~ /^\s*[Ss]/) {
|
||||||
print "Please enter one or more addresses not to scan. Separate them ",
|
print "Please enter one or more addresses not to scan. Separate them ",
|
||||||
"with comma's.\n",
|
"with comma's.\n",
|
||||||
@@ -4970,7 +4953,7 @@ sub main
|
|||||||
mkdir '/etc/sysconfig', 0777
|
mkdir '/etc/sysconfig', 0777
|
||||||
or die "Sorry, can't create /etc/sysconfig ($!)?!?";
|
or die "Sorry, can't create /etc/sysconfig ($!)?!?";
|
||||||
}
|
}
|
||||||
open(SYSCONFIG, ">/etc/sysconfig/lm_sensors")
|
open(local *SYSCONFIG, ">/etc/sysconfig/lm_sensors")
|
||||||
or die "Sorry, can't create /etc/sysconfig/lm_sensors ($!)?!?";
|
or die "Sorry, can't create /etc/sysconfig/lm_sensors ($!)?!?";
|
||||||
print SYSCONFIG <<'EOT';
|
print SYSCONFIG <<'EOT';
|
||||||
# /etc/sysconfig/sensors - Defines modules loaded by /etc/rc.d/init.d/lm_sensors
|
# /etc/sysconfig/sensors - Defines modules loaded by /etc/rc.d/init.d/lm_sensors
|
||||||
@@ -5015,7 +4998,6 @@ EOT
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
print SYSCONFIG $sysconfig;
|
print SYSCONFIG $sysconfig;
|
||||||
close(SYSCONFIG);
|
|
||||||
print "Copy prog/init/lm_sensors.init to /etc/rc.d/init.d/lm_sensors\n";
|
print "Copy prog/init/lm_sensors.init to /etc/rc.d/init.d/lm_sensors\n";
|
||||||
print "for initialization at boot time.\n";
|
print "for initialization at boot time.\n";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user