source: MondoRescue/branches/3.2/MondoRescue/lib/MondoRescue/Kernel.pm@ 3249

Last change on this file since 3249 was 3249, checked in by Bruno Cornec, 10 years ago
  • create function mr_kernel_get_modules in MondoRescue::Kernel.pm from code previously in get-modules.pl which now just calls it
File size: 3.8 KB
RevLine 
[3219]1#!/usr/bin/perl -w
2#
3# Subroutines related to Kernel brought by the MondoRescue project
4#
5# $Id$
6#
7# Copyright B. Cornec 2008-2014
8# Provided under the GPL v2
9
10package MondoRescue::Kernel;
11
12use strict 'vars';
13use Data::Dumper;
[3249]14use POSIX "uname";
[3219]15use lib qw (lib);
16use ProjectBuilder::Base;
17use ProjectBuilder::Conf;
18use MondoRescue::Base;
19use MondoRescue::Inventory;
20
21# Inherit from the "Exporter" module which handles exporting functions.
22
23use Exporter;
24
25# Export, by default, all the functions into the namespace of
26# any code which uses this module.
27
28our @ISA = qw(Exporter);
[3249]29our @EXPORT = qw(mr_kernel_get_version mr_kernel_get_modules);
[3219]30
31=pod
32
33=head1 NAME
34
35MondoRescue::Kernel, part of the mondorescue.org
36
37=head1 DESCRIPTION
38
39This modules provides low level functions for Kernel support in the Mondorescue project
40
41=head1 USAGE
42
43=over 4
44
45=item B<mr_kernel_get_version>
46
47This function checks the kernel and returns back its version
48
49=cut
50
51sub mr_kernel_get_version {
52
53my ($os,$ver,$kernelver,$rest);
54
55# By default we don't know how it works for other OSes
56$kernelver = "unknown";
57
[3249]58my ($sysname, $nodename, $release, $version, $machine ) = uname();
59$kernelver = $release if (defined $release);
[3219]60
61return($kernelver);
62}
63
[3249]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);
135}
136
[3219]137=back
138
139=head1 WEB SITES
140
141The main Web site of the project is available at L<http://www.mondorescue.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.mondorescue.org/>.
142
143=head1 USER MAILING LIST
144
145The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
146
147=head1 AUTHORS
148
149The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
150
151=head1 COPYRIGHT
152
153This module is distributed under the GPL v2.0 license
154described in the file C<COPYING> included with the distribution.
155
156=cut
157
1581;
159
Note: See TracBrowser for help on using the repository browser.