Blame SOURCES/0003-Ignore-unbootable-kernels-in-lib-modules.patch

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