From ce5aa990edaf2ce6a6b351568ecebf217f7cb301 Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 11 Mar 2024 12:48:25 +0800 Subject: [PATCH] ksud: don't patch if it's already patched --- userspace/ksud/src/boot_patch.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/userspace/ksud/src/boot_patch.rs b/userspace/ksud/src/boot_patch.rs index c665cb8185f5..361ca99a98c4 100644 --- a/userspace/ksud/src/boot_patch.rs +++ b/userspace/ksud/src/boot_patch.rs @@ -162,10 +162,13 @@ pub fn patch( .status()?; ensure!(status.success(), "magiskboot unpack failed"); - let status = do_cpio_cmd(&magiskboot, workding_dir.path(), "exists init"); - if status.is_ok() { - // init exist, backup it. - do_cpio_cmd(&magiskboot, workding_dir.path(), "mv init init.real")?; + let is_kernelsu_patched = do_cpio_cmd(&magiskboot, workding_dir.path(), "exists kernelsu.ko").is_ok(); + if !is_kernelsu_patched { + // kernelsu.ko is not exist, backup init if necessary + let status = do_cpio_cmd(&magiskboot, workding_dir.path(), "exists init"); + if status.is_ok() { + do_cpio_cmd(&magiskboot, workding_dir.path(), "mv init init.real")?; + } } do_cpio_cmd(&magiskboot, workding_dir.path(), "add 0755 init init")?;