Changeset 3249 in MondoRescue for branches/3.2/MondoRescue


Ignore:
Timestamp:
Feb 27, 2014, 3:48:19 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • create function mr_kernel_get_modules in MondoRescue::Kernel.pm from code previously in get-modules.pl which now just calls it
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/lib/MondoRescue/Kernel.pm

    r3219 r3249  
    1212use strict 'vars';
    1313use Data::Dumper;
     14use POSIX "uname";
    1415use lib qw (lib);
    1516use ProjectBuilder::Base;
     
    2627
    2728our @ISA = qw(Exporter);
    28 our @EXPORT = qw(mr_kernel_get_version);
     29our @EXPORT = qw(mr_kernel_get_version mr_kernel_get_modules);
    2930
    3031=pod
     
    5556$kernelver = "unknown";
    5657
    57 ($os,$ver,$kernelver,$rest) = split(/ /,$mr_os->{'files'}->{'proc_version'}) if ($mr_os->{'os'} eq "linux");
     58my ($sysname, $nodename, $release, $version, $machine ) = uname();
     59$kernelver = $release if (defined $release);
    5860
    5961return($kernelver);
     62}
     63
     64
     65=item B<mr_kernel_get_modules>
     66
     67Tis function takes as input the kernel version to examined (can be undef in which case the running kernel is used) and a list of modules names to examined as well (can be undef in which case all modules ar taken)
     68This function returns back the modules path as a first argument and the list of relative modules path for the modules names passed.
     69
     70Example:
     71mr_kernel_get_modules("3.8.13.4-desktop-1.mga3","ext3") returns
     72("/lib/modules/3.8.13.4-desktop-1.mga3", "kernel/fs/ext3/ext3.ko.xz","kernel/fs/jbd/jbd.ko.xz")
     73
     74=cut
     75
     76sub mr_kernel_get_modules {
     77
     78my $ver = $_;
     79$ver = mr_kernel_get_version() if (not defined ($ver));
     80my @allmodules = @_;
     81
     82my $module = "";
     83my %modlist;
     84my $void = "";
     85my @allmodpaths;
     86my $modulepath = "";
     87
     88# If no module names list passed as parameter, the work on all modules of the system
     89if (not defined $allmodules[0]) {
     90    open(LSMOD, "/sbin/lsmod |") or die "Unable to launch lsmod";
     91    while (<LSMOD>) {
     92        next if (/^Module/);
     93        ($module, $void) = split(/ /);
     94        push @allmodules,$module;
     95    }
     96    close(LSMOD);
     97}
     98
     99open(DEPMOD, "/sbin/depmod -n $ver |") or die "Unable to launch depmod";
     100while (<DEPMOD>) {
     101    ($module, $void) = split(/:/);
     102    last if ($module =~ /^#/);
     103    chomp($void);
     104    $modlist{$module} = $void;
     105    pb_log(2,"Depmod on $module gives $void\n");
     106}
     107close(DEPMOD);
     108
     109#print Dumper(%modlist)."\n";
     110
     111my $lib;
     112my $modulep;
     113my $kernelv;
     114my $modpath;
     115
     116foreach my $m (@allmodules) {
     117    pb_log(1,"Analyzing $m\n");
     118    open(MODINFO, "/sbin/modinfo -n -k $ver $m 2>/dev/null |") or die "Unable to launch modinfo";
     119    $module = <MODINFO>;
     120    close(MODINFO);
     121    if ((not defined $module) || ($module =~ '^$')) {
     122        pb_log(1,"WARNING: No modinfo for module $m\n");
     123        next;
     124    }
     125    chomp($module);
     126    ($void,$lib,$modulep,$kernelv,$modpath) = split(/\//,$module,5);
     127    next if (not defined $modpath);
     128    pb_log(2,"modpath: $modpath\n");
     129    push @allmodpaths,$modpath,split(/ /,$modlist{$modpath});
     130}
     131$modulepath = "/$lib/$modulep/$kernelv";
     132pb_log(1,"modules path: $modulepath\n");
     133pb_log(1,"all modpaths: ".join(' ',@allmodpaths)."\n");
     134return($modulepath,@allmodpaths);
    60135}
    61136
Note: See TracChangeset for help on using the changeset viewer.