Skip to content

Conversation

@larsmartens
Copy link

This pull request addresses critical issues observed in the AdGuard certificate module logs, ensuring proper functionality and compatibility with the Android 14/15 APEX CA directory.


Context and Observed Issues

I noticed that the module often simply didn't apply the changes and, after examining the logs, identified the same errors as in this timing-related issue, as well as another one related to unmounting:

  1. Timing Issues:

    • The script attempted operations before the zygote64 process was initialized, causing the module to stall in an indefinite loop:
    • This was due to race conditions where the system was not ready for the operations the module tried to perform.
  2. Temporary Directory Cleanup Issues:

    • Errors occurred during the unmounting and removal of the temporary directory:
      rmdir: '/data/local/tmp/adg-ca-copy': Device or resource busy
      
    • This was caused by lingering processes keeping the directory in use, leading to improper cleanup.

Fixes Implemented

  1. Timing Fix for zygote64 Initialization

    • Added a loop to wait for the zygote64 process before proceeding with critical operations.
    • Ensures that the module executes only after the system is ready, eliminating timing-related stalls.
  2. Enhancements for Android 14 APEX CA Directory Handling

    • Improved cleanup logic for the temporary directory:
      • Replaced rm -f with rm -rf for proper directory removal.
      • Added a loop to retry unmounting until successful, addressing the "Device or resource busy" error.
    • Introduced a reusable TEMP_DIR variable for improved readability and easier future maintenance.

Testing

  • Verified the script now waits for zygote64 to initialize before performing operations.
  • Tested directory creation, mounting, and cleanup, ensuring all resources are properly managed without errors.
  • Checked compatibility on Android 15 with APEX CA directories.

Impact

  • Reliability: Resolves timing issues for a smooth initialization process.
  • Compatibility: Supports Android 14's APEX CA structure effectively.

Added a loop to wait for the zygote64 process before executing critical certificate operations. This prevents race conditions during module initialization and ensures compatibility with the system boot sequence.
…cleanup and safety checks


Updated the script to enhance temporary directory management for handling Android 14 APEX CA storage:
- Changed `rm -f` to `rm -rf` to ensure proper cleanup of temporary directories.
- Replaced hardcoded paths with a reusable `TEMP_DIR` variable for clarity and maintainability.
- Added a loop to ensure safe unmounting of the temporary directory, preventing "Device or resource busy" errors.
@Loukious
Copy link

Loukious commented Feb 7, 2025

For some reason this cause my phone to be stuck on boot screen. Using KernelSU-Next with Zygisk Next.

@chengnan049
Copy link

I thought only administrators had the permission to approve, and I was curious so I clicked it. Sorry about that

@chengnan049
Copy link

For some reason this cause my phone to be stuck on boot screen. Using KernelSU-Next with Zygisk Next.

Same to me, OnePlus Ace 3,KernelSU by 5ec1cff

@sovzzz
Copy link

sovzzz commented Apr 6, 2025

For some reason this cause my phone to be stuck on boot screen. Using KernelSU-Next with Zygisk Next.

It is a question of nonsense, cause magisk modules is only designed for magisk. Ksu has its own rules, even though it might be compatible with some magisk modules.

@chengnan049
Copy link

For some reason this cause my phone to be stuck on boot screen. Using KernelSU-Next with Zygisk Next.

It is a question of nonsense, cause magisk modules is only designed for magisk. Ksu has its own rules, even though it might be compatible with some magisk modules.

Almost all incompatibilities are caused by modules not being designed according to standard templates.

@sfionov
Copy link
Member

sfionov commented Jul 4, 2025

Hello! There's a lot issues with this PR.

First, it will definitely hang on 32-bit devices, and in case that umount permanently fails.

Second, it does some refactoring, not only targets issues.

And at last, if we assume that on some configurations, zygote is being spawned while running this script, not before, then additional research is needed about parent process on that configuration. If it is PID 1, then simply evaluating $(pgrep zygote64) after PID 1's mount, not before in for, should help fix the race.

P.S. KernelSU issues are not relevant to this PR since they are present on master too, see #62

@sfionov sfionov self-requested a review July 29, 2025 13:10
Copy link
Member

@sfionov sfionov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment

@CanerKaraca23
Copy link

See my previous comment

Seems unvisible.

@CanerKaraca23
Copy link

@larsmartens hey, can you rebase with Android 16 support?

@chengnan049
Copy link

@larsmartens hey, can you rebase with Android 16 support?

You can use https://github.com/ys1231/MoveCertificate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants