Changeset 3354


Ignore:
Timestamp:
Mar 5, 2015, 1:23:38 PM (5 years ago)
Author:
Bruno Cornec
Message:
  • mr-kernel-get-modules now uses Getopt for parameter management, allowing verbosity increase
  • Fix mr_kernel_get_modules to support depmod version providing relative paths such as on RHEL5
  • Fix mr_kernel_get_modules to support modinfo version withou -k option support, using module full path instead
  • the modlist hash is now having keys being full path module names as a consequence
Location:
branches/3.2/MondoRescue
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/bin/mr-kernel-get-modules

    r3250 r3354  
    66use ProjectBuilder::Base;
    77use MondoRescue::Kernel;
     8use Getopt::Long qw(:config auto_abbrev no_ignore_case);
    89
    9 my $ver = undef;
     10my %opts;                           # CLI Options
    1011
    11 if ((defined $ARGV[0]) && ($ARGV[0] eq "-v")) {
    12     #$pbverbose = 1;
    13     shift;
    14 }
    15 if ((defined $ARGV[0]) && ($ARGV[0] eq "-k")) {
    16     shift;
    17     $ver = $ARGV[0];
    18     shift;
    19 }
    20 if ((defined $ARGV[0]) && ($ARGV[0] eq "-m")) {
    21     shift;
    22 }
     12GetOptions(
     13        "kernel|k:s" => \$opts{'k'},
     14        "verbose|v+" => \$opts{'v'},
     15);
    2316
    24 print join(' ',mr_kernel_get_modules($ver,@ARGV))."\n";
     17$pbdebug = $opts{'v'};
     18$pbdebug = 0 if (not defined $pbdebug);
     19print join(' ',mr_kernel_get_modules($opts{'k'},@ARGV))."\n";
  • branches/3.2/MondoRescue/lib/MondoRescue/Kernel.pm

    r3314 r3354  
    55# $Id$
    66#
    7 # Copyright B. Cornec 2008-2014
     7# Copyright B. Cornec 2008-2015
    88# Provided under the GPL v2
    99
     
    1212use strict 'vars';
    1313use Data::Dumper;
     14use File::Basename;
    1415use POSIX "uname";
    1516use lib qw (lib);
     
    8283my $module = "";
    8384my %modlist;
     85my %modpath;
    8486my $void = "";
    8587my @alllivemodules;
     
    106108
    107109# Now computes the dependencies of each module and store them in %modlist
     110# # Some depmods gives a full path, others a relative path to /lib/modules/$ver
    108111open(DEPMOD, "/sbin/depmod -n $ver |") or die "Unable to launch depmod";
    109112while (<DEPMOD>) {
     
    112115    chomp($void);
    113116    $void =~ s/\s+//;
     117    $module = "/lib/modules/$ver/$module" if ($module !~ /^\/lib\/modules/);
     118    # Now module is a full path whatever depmod version
     119    $void = join(' ',map { "/lib/modules/$ver/".$_ } split(/ /,$void)) if ($void !~ /^\/lib\/modules/);
     120    # Now void is a full path of modules whatever depmod version
    114121    $modlist{$module} = $void;
     122    my $m = basename($module,".ko",".o",".ko.gz",".ko.bz",".ko.xz",".o.gz",".o.bz",".o.xz");
     123    $modpath{$m} = $module;
    115124    pb_log(2,"Depmod on $module gives $void\n");
    116125}
     
    127136foreach my $m (@allmodules) {
    128137    pb_log(1,"Analyzing $m\n");
    129     open(MODINFO, "/sbin/modinfo -n -k $ver $m 2>/dev/null |") or die "Unable to launch modinfo";
     138    if (not defined $modpath{$m}) {
     139        pb_log(1,"WARNING: No modpath for module $m\n");
     140        next;
     141    }
     142    pb_log(2,"$m has a modpath of $modpath{$m}\n");
     143    open(MODINFO, "/sbin/modinfo -n $modpath{$m} 2>/dev/null |") or die "Unable to launch modinfo";
    130144    $module = <MODINFO>;
    131145    close(MODINFO);
     
    137151    ($void,$lib,$modulep,$kernelv,$modpath) = split(/\//,$module,5);
    138152    next if (not defined $modpath);
    139     if (not defined $modlist{$modpath}) {
    140         pb_log(0,"No modlist found for $modpath\n");
     153    if (not defined $modlist{$module}) {
     154        pb_log(0,"No modlist found for $module\n");
    141155        next;
    142156    }
    143     $modulepath = "/$lib/$modulep/$kernelv";
    144     pb_log(2,"modpath: $modulepath/$modpath\n");
    145     push @allmodpaths,"$modulepath/$modpath",map { "$modulepath/".$_ } split(/ /,$modlist{$modpath});
     157    pb_log(2,"modpath: $module\n");
     158    push @allmodpaths,$module,split(/ /,$modlist{$module});
    146159}
    147160pb_log(1,"all modpaths: ".join(' ',@allmodpaths)."\n");
Note: See TracChangeset for help on using the changeset viewer.