Thus spake Bernard Li ([EMAIL PROTECTED]):
Hey Brian:

If this looks good, I can check it in.

It prefers the kernel file which matches the running kernel verison, otherwise, 
it picks the first good kernel file.

On SuSE, I could not really find a kernel file in / or /boot which is a kernel 
file (according to the is_kernel() subroutine), do you think the following file 
will work?

Yes.

We may end up with numerous tests in the "is_kernel" routine.  Go ahead
and check it in, and we'll modify as we learn.

-Brian


% file vmlinuz
vmlinuz: Linux/i386 Kernel, Setup Version 0x203, bzImage

Cheers,

Bernard

________________________________

From: Brian Elliott Finley on behalf of Brian Elliott Finley
Sent: Sat 14/01/2006 23:43
To: Bernard Li
Cc: SIS Devel
Subject: Re: [systemimager-commits] r3395 - branches/3.6.x/lib/SystemImager



Bernard,

May I suggest a test for the file type, instead of a test for the file
name?  There is no requirement that a useable kernel file start with
"vmlinuz".

   [EMAIL PROTECTED]/boot% file vmlinu[xz]-2.4.21-27.0.4.EL
   vmlinux-2.4.21-27.0.4.EL: ELF 32-bit LSB executable, Intel 80386, version 1 
(SYSV), statically linked, stripped
   vmlinuz-2.4.21-27.0.4.EL: x86 boot sector


May I suggest the creation of a new function called, "is_kernel", and do
any relevant kernel validation tests in there.  We can then call it from
inside the "foreach (@files) {" loop below.

See the attached test script for an example function.

Cheers, -Brian






Thus spake Bernard Li ([EMAIL PROTECTED]):
Author: bli
Date: 2006-01-08 04:44:52 -0600 (Sun, 08 Jan 2006)
New Revision: 3395

Modified:
  branches/3.6.x/lib/SystemImager/UseYourOwnKernel.pm
Log:
Make sure that the kernel file starts with "vmlinuz".  On RHEL3u5, /boot has 
two similiarly named files which fit the original criteria:
/boot/vmlinux-2.4.21-32.EL
/boot/vmlinuz-2.4.21-32.EL


Modified: branches/3.6.x/lib/SystemImager/UseYourOwnKernel.pm
===================================================================
--- branches/3.6.x/lib/SystemImager/UseYourOwnKernel.pm        2006-01-07 
05:07:02 UTC (rev 3394)
+++ branches/3.6.x/lib/SystemImager/UseYourOwnKernel.pm        2006-01-08 
10:44:52 UTC (rev 3395)
@@ -184,18 +184,18 @@
        foreach my $dir (@dirs) {
#
-                # Check each binary to see if it contains the uname string
+                # Check each binary to see if it contains vmlinuz and the 
uname string
                #
                opendir(DIR, $dir) || die("Can't opendir $dir: $!");
                        my @files = readdir(DIR);
                closedir DIR;

                foreach (@files) {
-
-                        my $file = "$dir/$_";
+                        my $kernel = $_;
+                        my $file = "$dir/$kernel";
                        next unless( (-B $file) and (! -d $file) );
                        my $kernel_release = _get_kernel_release($file);
-                        return $file if( defined($kernel_release) and 
($kernel_release eq $uname_r) );
+                        return $file if( defined($kernel_release) and 
($kernel_release eq $uname_r) and ($kernel =~ /^vmlinuz/) );
                }
        }




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
systemimager-commits mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/systemimager-commits

--
Brian Elliott Finley
Mobile:  630.631.6621



Content-Description: UseYourOwnKernel.pm.patch
Index: lib/SystemImager/UseYourOwnKernel.pm
===================================================================
--- lib/SystemImager/UseYourOwnKernel.pm        (revision 3402)
+++ lib/SystemImager/UseYourOwnKernel.pm        (working copy)
@@ -169,8 +169,27 @@
        return 1;
}

+#
+# Usage: my $is_this_file_a_kernel = is_kernel( $kernel );
+#
+sub is_kernel {

+        my $file = shift;

+        if( ! -B $file ) { return undef; }
+        if( -d $file )   { return undef; }
+
+        my $cmd = "file -b $file";
+        open(INPUT,"$cmd|") or die("Couldn't run $cmd to get INPUT");
+        my ($input) = (<INPUT>);
+        unless( $input =~ m/boot sector/ ) { return undef; }
+        close(INPUT);
+
+        #
+        # If we've made it down to here, then we consider it a kernel. -BEF-
+        return 1;
+}
+
#
# Usage:
#       my $kernel_file = _choose_kernel_file( $uname_r );
@@ -178,13 +197,14 @@
sub _choose_kernel_file($) {

        my $uname_r = shift;
-
        my @dirs = ('/boot', '/');
+        my @kernels;

        foreach my $dir (@dirs) {
# - # Check each binary to see if it contains vmlinuz and the uname string
+                # Check each binary to see if it is a kernel file.  Preference 
given to the file with
+                # the running kernel version, otherwise, the first available 
good kernel file is used.
                #
                opendir(DIR, $dir) || die("Can't opendir $dir: $!");
                        my @files = readdir(DIR);
@@ -193,10 +213,20 @@
                foreach (@files) {
                        my $kernel = $_;
                        my $file = "$dir/$kernel";
-                        next unless( (-B $file) and (! -d $file) );
-                        my $kernel_release = _get_kernel_release($file);
-                        return $file if( defined($kernel_release) and 
($kernel_release eq $uname_r) and ($kernel =~ /^vmlinuz/) );
+                        if ( is_kernel($file) ) {
+                                my $kernel_release = 
_get_kernel_release($file);
+                                if ( defined($kernel_release) and 
($kernel_release eq $uname_r) ) {
+                                        return $file;
+                                } else {
+                                        push(@kernels, $file);
+                                }
+                        }
                }
+
+                # If cannot find kernel with name matching running version, 
return the first good one
+                if (@kernels) {
+                        return pop(@kernels);
+                }
        }

        return undef;


--
Brian Elliott Finley
Mobile:  630.631.6621


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sisuite-devel mailing list
Sisuite-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sisuite-devel

Reply via email to