From 4133b906a1d80f7e162e622a22a34092d6a8c80a Mon Sep 17 00:00:00 2001 From: xiangfeidexiaohuo Date: Fri, 5 Apr 2024 22:53:54 +0800 Subject: [PATCH] Revert "ksud: try parse kmi from gki modules if uname is modified" This reverts commit f41d73f7eba2241fdcfadc42e1d43d8e5f285711. Signed-off-by: xiangfeidexiaohuo --- userspace/ksud/src/boot_patch.rs | 39 +++++--------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/userspace/ksud/src/boot_patch.rs b/userspace/ksud/src/boot_patch.rs index 8ce6ee73a186..19c984dff046 100644 --- a/userspace/ksud/src/boot_patch.rs +++ b/userspace/ksud/src/boot_patch.rs @@ -51,48 +51,21 @@ pub fn get_kernel_version() -> Result<(i32, i32, i32)> { } #[cfg(target_os = "android")] -fn parse_kmi(version: &str) -> Result { + +fn parse_kmi() -> Result { + let uname = rustix::system::uname(); + let version = uname.release().to_string_lossy(); let re = Regex::new(r"(.* )?(\d+\.\d+)(\S+)?(android\d+)(.*)")?; let cap = re - .captures(version) + .captures(&version) .ok_or_else(|| anyhow::anyhow!("Failed to get KMI from boot/modules"))?; let android_version = cap.get(4).map_or("", |m| m.as_str()); let kernel_version = cap.get(2).map_or("", |m| m.as_str()); Ok(format!("{android_version}-{kernel_version}")) } -#[cfg(target_os = "android")] -fn parse_kmi_from_uname() -> Result { - let uname = rustix::system::uname(); - let version = uname.release().to_string_lossy(); - parse_kmi(&version) -} - -#[cfg(target_os = "android")] -fn parse_kmi_from_modules() -> Result { - use std::io::BufRead; - // find a *.ko in /vendor/lib/modules - let modfile = std::fs::read_dir("/vendor/lib/modules")? - .filter_map(Result::ok) - .find(|entry| entry.path().extension().map_or(false, |ext| ext == "ko")) - .map(|entry| entry.path()) - .ok_or_else(|| anyhow!("No kernel module found"))?; - let output = Command::new("modinfo").arg(modfile).output()?; - for line in output.stdout.lines().map_while(Result::ok) { - if line.starts_with("vermagic") { - return parse_kmi(&line); - } - } - anyhow::bail!("Parse KMI from modules failed") -} - -#[cfg(target_os = "android")] -pub fn get_current_kmi() -> Result { - parse_kmi_from_uname().or_else(|_| parse_kmi_from_modules()) -} - #[cfg(not(target_os = "android"))] -pub fn get_current_kmi() -> Result { +pub fn parse_kmi() -> Result { bail!("Unsupported platform") }