Skip to content

Commit aa64d44

Browse files
committed
Support inject rc
1 parent c8a16b0 commit aa64d44

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

native/src/init/rootdir.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ static void load_overlay_rc(const char *overlay) {
203203
}
204204
}
205205

206+
static void handle_module_rc() {
207+
if (auto dir = xopen_dir("/data/" PREINITMIRR); dir) {
208+
char path[PATH_MAX];
209+
for (dirent *entry; (entry = readdir(dir.get()));) {
210+
if (entry->d_name == "."sv || entry->d_name == ".."sv || entry->d_type != DT_DIR)
211+
continue;
212+
sprintf(path, "/data/%s/%s", PREINITMIRR, entry->d_name);
213+
load_overlay_rc(path);
214+
}
215+
}
216+
}
217+
206218
static void recreate_sbin(const char *mirror, bool use_bind_mount) {
207219
auto dp = xopen_dir(mirror);
208220
int src = dirfd(dp.get());
@@ -316,6 +328,8 @@ void MagiskInit::patch_ro_root() noexcept {
316328
mv_path(ROOTOVL "/sbin", ".");
317329
}
318330

331+
handle_module_rc();
332+
319333
// Patch init.rc
320334
bool p;
321335
if (access(NEW_INITRC_DIR "/" INIT_RC, F_OK) == 0) {
@@ -356,6 +370,8 @@ void MagiskInit::patch_rw_root() noexcept {
356370
rm_rf("/data/overlay.d");
357371
rm_rf("/.backup");
358372

373+
handle_module_rc();
374+
359375
// Patch init.rc
360376
if (patch_rc_scripts("/", "/sbin", true))
361377
patch_fissiond("/sbin");

scripts/util_functions.sh

+20-3
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,22 @@ copy_preinit_files() {
584584
cat $r
585585
echo
586586
done > $PREINITDIR/sepolicy.rule
587+
588+
# Copy all enabled rc
589+
find "$PREINITDIR" -mindepth 1 -type d 2>/dev/null | while read -r dir; do
590+
rm -rf "${dir:?}"
591+
done
592+
for d in /data/adb/modules*/*; do
593+
local MODDIR=${d%/*}
594+
local MODID=$(basename "$MODDIR")
595+
[ -f "$MODDIR"/disable ] && continue
596+
[ -f "$MODDIR"/remove ] && continue
597+
[ -f "$MODDIR"/update ] && continue
598+
find "$MODDIR" -mindepth 1 -type f -name "*.rc" | while read -r file; do
599+
mkdir -p "$PREINITDIR/$MODID"
600+
cp "$file" "$PREINITDIR/$MODID/"
601+
done
602+
done
587603
}
588604

589605
#################
@@ -719,9 +735,10 @@ install_module() {
719735
cp -af $MODPATH/module.prop /data/adb/modules/$MODID/module.prop
720736
fi
721737

722-
# Copy over custom sepolicy rules
723-
if [ -f $MODPATH/sepolicy.rule ]; then
724-
ui_print "- Installing custom sepolicy rules"
738+
rc=$(find "$MODPATH" -mindepth 1 -type f -name "*.rc" -print -quit)
739+
# Copy over custom sepolicy rules and rc
740+
if [ -f $MODPATH/sepolicy.rule ] || [ -n "$rc" ]; then
741+
ui_print "- Installing custom sepolicy rules or rc script"
725742
copy_preinit_files
726743
fi
727744

0 commit comments

Comments
 (0)