Changeset 5497

Show
Ignore:
Timestamp:
12/02/08 14:53:43 (4 years ago)
Author:
khali
Message:

Turn chips_detected into a hash. This is more appropriate to the data
we store than the array we were using so far.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect

    r5496 r5497  
    24132413#################### 
    24142414 
    2415 use vars qw(@chips_detected); 
    2416  
    2417 # We will build a complicated structure @chips_detected here, being: 
    2418 # A list of 
    2419 #  references to hashes 
    2420 #    with field 'driver', being a string with the driver name for this chip; 
    2421 #    with field 'detected' 
    2422 #      being a reference to a list of 
    2423 #        references to hashes of type 'detect_data'; 
     2415use vars qw(%chips_detected); 
     2416 
     2417# We will build a complicated structure %chips_detected here, being a hash 
     2418# where keys are driver names and values are detected chip information in 
     2419# the form of a list of hashes of type 'detect_data'. 
    24242420 
    24252421# Type detect_data: 
     
    24472443{ 
    24482444        my ($chipdriver, $datahash) = @_; 
    2449         my ($i, $new_detected_ref, $detected_ref, $main_entry, $detected_entry, 
     2445        my ($i, $new_detected_ref, $detected_ref, $detected_entry, 
    24502446            $put_in_detected, @hash_addrs, @entry_addrs); 
    24512447 
    24522448        # First determine where the hash has to be added. 
    2453         for ($i = 0; $i < @chips_detected; $i++) { 
    2454                 last if ($chips_detected[$i]->{driver} eq $chipdriver); 
    2455         } 
    2456         if ($i == @chips_detected) { 
    2457                 push @chips_detected, { 
    2458                         driver => $chipdriver, 
    2459                         detected => [], 
    2460                 }; 
    2461         } 
    2462         $new_detected_ref = $chips_detected[$i]->{detected}; 
     2449        $chips_detected{$chipdriver} = [] 
     2450                unless exists $chips_detected{$chipdriver}; 
     2451        $new_detected_ref = $chips_detected{$chipdriver}; 
    24632452 
    24642453        # Find out whether our new entry should go into the detected list 
     
    24712460        $put_in_detected = 1; 
    24722461 FIND_LOOP: 
    2473         foreach $main_entry (@chips_detected) { 
    2474                 foreach $detected_entry (@{$main_entry->{detected}}) { 
     2462        foreach $detected_ref (values %chips_detected) { 
     2463                foreach $detected_entry (@{$detected_ref}) { 
    24752464                        @entry_addrs = ($detected_entry->{i2c_addr}); 
    24762465                        push @entry_addrs, @{$detected_entry->{i2c_sub_addrs}} 
     
    24912480        # sub address. This may not be the best idea to do, as it may remove 
    24922481        # detections without replacing them with second-best ones. Too bad. 
    2493         foreach $main_entry (@chips_detected) { 
    2494                 $detected_ref = $main_entry->{detected}; 
     2482        foreach $detected_ref (values %chips_detected) { 
    24952483                for ($i = @$detected_ref-1; $i >=0; $i--) { 
    24962484                        @entry_addrs = ($detected_ref->[$i]->{i2c_addr}); 
     
    25142502{ 
    25152503        my ($chipdriver, $datahash) = @_; 
    2516         my ($i, $new_detected_ref, $detected_ref, $main_entry); 
     2504        my ($i, $new_detected_ref, $detected_ref); 
    25172505 
    25182506        # First determine where the hash has to be added. 
    2519         for ($i = 0; $i < @chips_detected; $i++) { 
    2520                 last if ($chips_detected[$i]->{driver} eq $chipdriver); 
    2521         } 
    2522         if ($i == @chips_detected) { 
    2523                 push @chips_detected, { 
    2524                         driver => $chipdriver, 
    2525                         detected => [], 
    2526                 }; 
    2527         } 
    2528         $new_detected_ref = $chips_detected[$i]->{detected}; 
     2507        $chips_detected{$chipdriver} = [] 
     2508                unless exists $chips_detected{$chipdriver}; 
     2509        $new_detected_ref = $chips_detected{$chipdriver}; 
    25292510 
    25302511        # Find out whether our new entry should go into the detected list 
    25312512        # or not. We only compare main isa_addr here, of course. 
    2532         foreach $main_entry (@chips_detected) { 
    2533                 $detected_ref = $main_entry->{detected}; 
    2534                 for ($i = 0; $i < @{$main_entry->{detected}}; $i++) { 
     2513        foreach $detected_ref (values %chips_detected) { 
     2514                for ($i = 0; $i < @{$detected_ref}; $i++) { 
    25352515                        if (exists $detected_ref->[$i]->{isa_addr} and 
    25362516                            exists $datahash->{isa_addr} and 
     
    47874767sub generate_modprobes 
    47884768{ 
    4789         my ($chip, $detection, $adap); 
     4769        my ($driver, $detection, $adap); 
    47904770        my ($isa, $ipmi); 
    47914771        my ($modprobes, $configfile); 
    47924772 
    4793         foreach $chip (@chips_detected) { 
    4794                 foreach $detection (@{$chip->{detected}}) { 
     4773        foreach $driver (keys %chips_detected) { 
     4774                foreach $detection (@{$chips_detected{$driver}}) { 
    47954775                        # Tag adapters which host hardware monitoring chips we want to access 
    47964776                        if (exists $detection->{i2c_devnr} 
     
    48034783                        } 
    48044784                } 
    4805                 if ($chip->{driver} eq "ipmisensors") { 
     4785                if ($driver eq "ipmisensors") { 
    48064786                        $ipmi = 1; 
    48074787                } 
     
    48124792        # directly, so module options are no longer needed. 
    48134793        unless (kernel_version_at_least(2, 6, 28)) { 
    4814                 foreach $chip (@chips_detected) { 
     4794                foreach $driver (keys %chips_detected) { 
    48154795                        my @optionlist = (); 
    4816                         foreach $detection (@{$chip->{detected}}) { 
     4796                        foreach $detection (@{$chips_detected{$driver}}) { 
    48174797                                next unless exists $detection->{i2c_addr} 
    48184798                                         && exists $detection->{isa_addr} 
     
    48274807                        $configfile = "# hwmon module options\n" 
    48284808                                unless defined $configfile; 
    4829                         $configfile .= "options $chip->{driver} ignore=". 
     4809                        $configfile .= "options $driver ignore=". 
    48304810                                       (join ",", @optionlist)."\n"; 
    48314811                } 
     
    48534833        # Now determine the chip probe lines 
    48544834        $modprobes .= "# Chip drivers\n"; 
    4855         foreach $chip (@chips_detected) { 
    4856                 next if not @{$chip->{detected}}; 
    4857                 if ($chip->{driver} eq "to-be-written") { 
    4858                         $modprobes .= "# no driver for $chip->{detected}[0]{chipname} yet\n"; 
     4835        foreach $driver (keys %chips_detected) { 
     4836                next if not @{$chips_detected{$driver}}; 
     4837                if ($driver eq "to-be-written") { 
     4838                        $modprobes .= "# no driver for ${$chips_detected{$driver}}[0]{chipname} yet\n"; 
    48594839                } else { 
    4860                         open(local *INPUTFILE, "modprobe -l $chip->{driver} 2>/dev/null |"); 
     4840                        open(local *INPUTFILE, "modprobe -l $driver 2>/dev/null |"); 
    48614841                        local $_; 
    48624842                        my $modulefound = 0; 
     
    48714851                        # isn't supported 
    48724852                        if ((($? >> 8) == 0) && ! $modulefound) { 
    4873                                 $modprobes .= "# Warning: the required module $chip->{driver} is not currently installed\n". 
     4853                                $modprobes .= "# Warning: the required module $driver is not currently installed\n". 
    48744854                                              "# on your system. For status of 2.6 kernel ports check\n". 
    48754855                                              "# http://www.lm-sensors.org/wiki/Devices. If driver is built\n". 
    48764856                                              "# into the kernel, or unavailable, comment out the following line.\n"; 
    48774857                        } 
    4878                         $modprobes .= "modprobe $chip->{driver}\n"; 
     4858                        $modprobes .= "modprobe $driver\n"; 
    48794859                } 
    48804860        } 
     
    49894969        print "\n"; 
    49904970 
    4991         if (!@chips_detected) { 
     4971        if (!keys %chips_detected) { 
    49924972                print "Sorry, no sensors were detected.\n", 
    49934973                      "Either your sensors are not supported, or they are connected to an\n", 
     
    50034983        <STDIN>; 
    50044984 
    5005         my ($chip, $data); 
    5006         foreach $chip (@chips_detected) { 
    5007                 next unless @{$chip->{detected}}; 
    5008                 find_aliases($chip->{detected}); 
    5009                 print "\nDriver `$chip->{driver}':\n"; 
    5010                 print_chips_report($chip->{detected}); 
     4985        foreach my $driver (keys %chips_detected) { 
     4986                next unless @{$chips_detected{$driver}}; 
     4987                find_aliases($chips_detected{$driver}); 
     4988                print "\nDriver `$driver':\n"; 
     4989                print_chips_report($chips_detected{$driver}); 
    50114990        } 
    50124991        print "\n";