Mac::SysProfile.pm gettype changes for compatibility with MacOS 10.6 & 10.7

Bug #874290 reported by Andreas Xenos
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OCS Inventory: Unified Unix Agent
In Progress
Undecided
mortheres

Bug Description

Hello,

due to the changes of Apple's system_profiler in MacOS X 10.6 and 10.7, here is the gettype function of Mac/SysProfile.pm which reports the memory, the storage and the cpu correctly to the server.

While creating the hash for the Storages.pm, the keys $hdr had the same value. For example, I had $hdr = Intel 6 Series Chipset for every different storage in my computer. In case this happens, I used a workaround to rename each one of it to:
Intel 6 Series Chipset 1
Intel 6 Series Chipset 2
Intel 6 Series Chipset 3
......

If I kept the original name, the hash only contained the values of the last key with the same name.

sub gettype {
    my ($pro, $typ, $fre) = @_;
    $pro->types() unless exists $types{$typ};
    if(!exists $types{$typ}) {
        delete $pro->{$typ};
        return undef;
    }
    my $raw = $fre || !$pro->{$typ} ? `$conf{bin} $typ` : $pro->{$typ};
    my $hdr = '';
    my($k,$v,$k2);
    my $counter = 0;
    for(split /\n/, $raw) {
        next if m/^\s*$/ || m/^\w/;
        if(m/^\s{4}\w/) {
            $hdr = $_;
            $hdr =~ s/^\s+//;
            $hdr =~ s/:.*$//;
            if ($counter > 0) {
                $hdr .= " " . $counter;
            }
            $pro->{$typ}->{$hdr} = {};
            ++$counter;
        } elsif(m/^\s{6}\w/) {
            s/^\s+//;
            s/\s+$//;
            ($k,$v) = split /:\s+/;
            if($hdr) {
                $pro->{$typ}->{$hdr}->{$k} = $v;
            } else {
                $pro->{$typ}->{$k} = $v;
            }
        } elsif(m/^\s{8}\w/) {
            $k2 = $_;
            $k2 =~ s/^\s+//;
            $k2 =~ s/:.*$//;
            if($hdr) {
                $pro->{$typ}->{$hdr}->{$k2} = {};
            } else {
                $pro->{$typ}->{$k2} = {};
            }
        } elsif(m/^\s{10}\w/) {
            s/^\s+//;
            s/\s+$//;
            my($k3,$v3) = split /:\s+/;
            if($hdr) {
                $pro->{$typ}->{$hdr}->{$k2}->{$k3} = $v3;
            } else {
                $pro->{$typ}->{$k2}->{$k3} = $v3;
            }
        }
    }
    return $pro->{$typ};
}

Regards,
Andreas

mortheres (mortheres)
Changed in ocsinventory-unix-agent:
assignee: nobody → mortheres (mortheres)
Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

In the 10 whitespaces els if statement, there should be a check for $k2. If it doesn't exist, an undefined variable error is returned:

if ($k2) {
    if($hdr) {
        $pro->{$typ}->{$hdr}->{$k2}->{$k3} = $v3;
     } else {
        $pro->{$typ}->{$k2}->{$k3} = $v3;
     }
} else {
    if ($hdr) {
         $pro->{$typ}->{$hdr}->{$k3} = $v3;
    } else {
       $pro->{$typ}->{$k3} = $v3;
    }
}

I have also modified the code in order to enable automatic calculation of the whitespaces, instead of declaring by hand the four cases (4, 6, 8, 10 whitespaces).

Andreas

Revision history for this message
mortheres (mortheres) wrote :

Hi Andreas,

Thanks a lot for your works and your proposal. I am currently working on the OCS agent Mac inventory refund because Mac::Sysprofile has been updated to use the system_profile XML output (better way than before !). Many OCS agent modules have been modified and I will take in consideration your feedback and proposal. I will paste here the various commits links and an MacOSX beta4 test agent link ASAP to see if it solves your problems.

Kind regards,

Guillaume

mortheres (mortheres)
Changed in ocsinventory-unix-agent:
status: New → In Progress
Revision history for this message
mortheres (mortheres) wrote :

Hi Andreas,

New OCS MacOSX agent 2.0 beta4 has been released and it should solves this problem: http://launchpad.net/ocsinventory-unix-agent/stable-2.0/2.0.3/+download/Ocsinventory_Agent_MacOSX_beta4.pkg.zip. Can you tell me if it solves this problem ?

Kind regards,

Guillaume

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.