|
|
78b809 |
From b843c724ee6e3f66991b8bd81a602e2bea0c1625 Mon Sep 17 00:00:00 2001
|
|
|
78b809 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
78b809 |
Date: Wed, 1 Dec 2021 10:28:36 +0000
|
|
|
78b809 |
Subject: [PATCH] Ignore unbootable kernels in /lib/modules
|
|
|
78b809 |
|
|
|
78b809 |
The previous commit didn't ignore zfcpdump kernels if found in
|
|
|
78b809 |
/lib/modules because we didn't apply the kernel filter to those paths.
|
|
|
78b809 |
|
|
|
78b809 |
Also this commit cleans up the code in general, splitting up the
|
|
|
78b809 |
multi-purpose "kernel_filter" function into two parts with clearer
|
|
|
78b809 |
roles.
|
|
|
78b809 |
|
|
|
78b809 |
Fixes: commit 9fbe476d4df0b01568d3668e6121cae7c779c8c7
|
|
|
78b809 |
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2027375
|
|
|
78b809 |
Reported-by: Yongkui Guo
|
|
|
78b809 |
(cherry picked from commit f53868ce875fc17527696a85b48c67fefa3176e7)
|
|
|
78b809 |
---
|
|
|
78b809 |
src/format_ext2_kernel.ml | 44 +++++++++++++++++++++++----------------
|
|
|
78b809 |
1 file changed, 26 insertions(+), 18 deletions(-)
|
|
|
78b809 |
|
|
|
78b809 |
diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml
|
|
|
78b809 |
index ea69ade..79d636b 100644
|
|
|
78b809 |
--- a/src/format_ext2_kernel.ml
|
|
|
78b809 |
+++ b/src/format_ext2_kernel.ml
|
|
|
78b809 |
@@ -38,7 +38,7 @@ let rec build_kernel debug host_cpu copy_kernel kernel =
|
|
|
78b809 |
| None ->
|
|
|
78b809 |
if debug >= 1 then
|
|
|
78b809 |
printf "supermin: kernel: looking for kernels in /lib/modules/*/vmlinuz ...\n%!";
|
|
|
78b809 |
- match find_kernel_from_lib_modules debug with
|
|
|
78b809 |
+ match find_kernel_from_lib_modules debug host_cpu with
|
|
|
78b809 |
| Some k -> k
|
|
|
78b809 |
| None ->
|
|
|
78b809 |
if debug >= 1 then
|
|
|
78b809 |
@@ -89,10 +89,13 @@ and find_kernel_from_env_vars debug =
|
|
|
78b809 |
Some (kernel_env, kernel_name, kernel_version, modpath)
|
|
|
78b809 |
with Not_found -> None
|
|
|
78b809 |
|
|
|
78b809 |
-and find_kernel_from_lib_modules debug =
|
|
|
78b809 |
+and find_kernel_from_lib_modules debug host_cpu =
|
|
|
78b809 |
+ let files = glob "/lib/modules/*/vmlinuz" [GLOB_NOSORT; GLOB_NOESCAPE] in
|
|
|
78b809 |
+ let files = Array.to_list files in
|
|
|
78b809 |
+
|
|
|
78b809 |
+ let files = ignore_unbootable_kernels host_cpu files in
|
|
|
78b809 |
+
|
|
|
78b809 |
let kernels =
|
|
|
78b809 |
- let files = glob "/lib/modules/*/vmlinuz" [GLOB_NOSORT; GLOB_NOESCAPE] in
|
|
|
78b809 |
- let files = Array.to_list files in
|
|
|
78b809 |
let kernels =
|
|
|
78b809 |
filter_map (
|
|
|
78b809 |
fun kernel_file ->
|
|
|
78b809 |
@@ -114,22 +117,22 @@ and find_kernel_from_lib_modules debug =
|
|
|
78b809 |
| [] -> None
|
|
|
78b809 |
|
|
|
78b809 |
and find_kernel_from_boot debug host_cpu =
|
|
|
78b809 |
- let is_arm =
|
|
|
78b809 |
- String.length host_cpu >= 3 &&
|
|
|
78b809 |
- host_cpu.[0] = 'a' && host_cpu.[1] = 'r' && host_cpu.[2] = 'm' in
|
|
|
78b809 |
-
|
|
|
78b809 |
let all_files = Sys.readdir "/boot" in
|
|
|
78b809 |
let all_files = Array.to_list all_files in
|
|
|
78b809 |
|
|
|
78b809 |
(* In original: ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen *)
|
|
|
78b809 |
let patterns = patt_of_cpu host_cpu in
|
|
|
78b809 |
- let files = kernel_filter patterns is_arm all_files in
|
|
|
78b809 |
+ let files = files_matching_globs patterns all_files in
|
|
|
78b809 |
+ let files = ignore_unbootable_kernels host_cpu files in
|
|
|
78b809 |
|
|
|
78b809 |
let files =
|
|
|
78b809 |
if files <> [] then files
|
|
|
78b809 |
- else
|
|
|
78b809 |
+ else (
|
|
|
78b809 |
(* In original: ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen *)
|
|
|
78b809 |
- kernel_filter ["vmlinu?-*"] is_arm all_files in
|
|
|
78b809 |
+ let files = files_matching_globs ["vmlinu?-*"] all_files in
|
|
|
78b809 |
+ let files = ignore_unbootable_kernels host_cpu files in
|
|
|
78b809 |
+ files
|
|
|
78b809 |
+ ) in
|
|
|
78b809 |
|
|
|
78b809 |
let files = List.sort (fun a b -> compare_version b a) files in
|
|
|
78b809 |
let kernels =
|
|
|
78b809 |
@@ -148,13 +151,18 @@ and find_kernel_from_boot debug host_cpu =
|
|
|
78b809 |
| kernel :: _ -> Some kernel
|
|
|
78b809 |
| [] -> None
|
|
|
78b809 |
|
|
|
78b809 |
-and kernel_filter patterns is_arm all_files =
|
|
|
78b809 |
- let files =
|
|
|
78b809 |
- List.filter
|
|
|
78b809 |
- (fun filename ->
|
|
|
78b809 |
- List.exists
|
|
|
78b809 |
- (fun patt -> fnmatch patt filename [FNM_NOESCAPE]) patterns
|
|
|
78b809 |
- ) all_files in
|
|
|
78b809 |
+and files_matching_globs patterns files =
|
|
|
78b809 |
+ List.filter
|
|
|
78b809 |
+ (fun filename ->
|
|
|
78b809 |
+ List.exists
|
|
|
78b809 |
+ (fun patt -> fnmatch patt filename [FNM_NOESCAPE]) patterns
|
|
|
78b809 |
+ ) files
|
|
|
78b809 |
+
|
|
|
78b809 |
+and ignore_unbootable_kernels host_cpu files =
|
|
|
78b809 |
+ let is_arm =
|
|
|
78b809 |
+ String.length host_cpu >= 3 &&
|
|
|
78b809 |
+ host_cpu.[0] = 'a' && host_cpu.[1] = 'r' && host_cpu.[2] = 'm' in
|
|
|
78b809 |
+
|
|
|
78b809 |
let files =
|
|
|
78b809 |
List.filter (fun filename -> find filename "xen" = -1) files in
|
|
|
78b809 |
let files =
|
|
|
78b809 |
--
|
|
|
78b809 |
2.31.1
|
|
|
78b809 |
|