@@ -7,41 +7,59 @@ log() {
77 echo " $( date ' +%m-%d %H:%M:%S ' ) " " $@ " >> $MODDIR /log.txt
88}
99
10- inject_into_zygote (){
10+ has_mount () {
11+ local pid=" $1 "
12+ grep -q " $APEX_CERT_DIR " " /proc/$pid /mountinfo"
13+ }
14+
15+ monitor_zygote (){
1116
12- log " Injecting into Zygote"
17+ (
18+ while true ; do
1319
14- # Collect all zygote PIDs (both 32‑ and 64‑bit)
15- zygote_pids=" "
16- for name in zygote zygote64; do
17- for p in $( pidof $name 2> /dev/null) ; do
18- zygote_pids=" $zygote_pids $p "
20+ # Collect all zygote PIDs (both 32‑ and 64‑bit)
21+ zygote_pids=" "
22+ for name in zygote zygote64; do
23+ for p in $( pidof $name 2> /dev/null) ; do
24+ zygote_pids=" $zygote_pids $p "
25+ done
1926 done
20- done
2127
22- log " Zygote PIDs: $zygote_pids "
28+ for zp in $zygote_pids ; do
29+
30+ # if our bind isn’t present, re-apply it
31+ if ! has_mount " $pid " ; then
2332
24- for zp in $zygote_pids ; do
25- log " zygote PID: $ zp"
33+ # Get active children
34+ children= $( echo " $ zp" | xargs -n1 ps -o pid -P | grep -v PID )
2635
27- log " Injecting into $zp "
28- /system/bin/nsenter --mount=/proc/$zp /ns/mnt -- /bin/mount --bind $APEX_CERT_DIR $APEX_CERT_DIR
36+ # Fallback for old Android ps (columns: USER PID PPID ...):
37+ if [ -z " $children " ]; then
38+ children=$( ps \
39+ | awk -v PPID=$zp ' $3==PPID { print $2 }' )
40+ fi
2941
30- # Get active children
31- children=$( echo " $zp " | xargs -n1 ps -o pid -P | grep -v PID)
42+ # After a crash, zygote is a bit unstable, so waiting to settle.
43+ if [ " $( echo " $children " | wc -l) " -lt 5 ]; then
44+ /system/bin/sleep 1s
45+ continue
46+ fi
3247
33- # Fallback for old Android ps (columns: USER PID PPID ...):
34- if [ -z " $children " ]; then
35- children=$( ps \
36- | awk -v PPID=$zp ' $3==PPID { print $2 }' )
37- fi
48+ log " Injecting into zygote ($zp )"
49+ /system/bin/nsenter --mount=/proc/$zp /ns/mnt -- /bin/mount --rbind $SYS_CERT_DIR $APEX_CERT_DIR
3850
39- for pid in $children ; do
40- log " Injecting into child: $pid "
41- /system/bin/nsenter --mount=/proc/$pid /ns/mnt -- /bin/mount --bind $APEX_CERT_DIR $APEX_CERT_DIR
4251
52+ for pid in $children ; do
53+ if ! has_mount " $pid " ; then
54+ log " Injecting into child $pid "
55+ /system/bin/nsenter --mount=/proc/$pid /ns/mnt -- /bin/mount --rbind $SYS_CERT_DIR $APEX_CERT_DIR
56+ fi
57+ done
58+ fi
4359 done
60+ sleep 5
4461 done
62+ )&
4563}
4664
4765main (){
@@ -65,7 +83,7 @@ main(){
6583 chmod 644 $SYS_CERT_DIR /*
6684 chcon u:object_r:system_security_cacerts_file:s0 $SYS_CERT_DIR /*
6785
68- inject_into_zygote
86+ monitor_zygote
6987 else
7088 # /system certs are automatically mounted by Magisk due to collection in post-fs-data
7189 log " No conscrypt"
0 commit comments