|
12 | 12 |
|
13 | 13 | using namespace std; |
14 | 14 |
|
15 | | -static vector<string> rc_list; |
16 | | - |
17 | 15 | #define NEW_INITRC_DIR "/system/etc/init/hw" |
18 | 16 | #define INIT_RC "init.rc" |
19 | 17 |
|
@@ -43,7 +41,7 @@ static bool unxz(out_stream &strm, rust::Slice<const uint8_t> bytes) { |
43 | 41 | } |
44 | 42 |
|
45 | 43 | // When return true, run patch_fissiond |
46 | | -static bool patch_rc_scripts(const char *src_path, const char *tmp_path, bool writable) { |
| 44 | +bool MagiskInit::patch_rc_scripts(const char *src_path, const char *tmp_path, bool writable) const noexcept { |
47 | 45 | auto src_dir = xopen_dir(src_path); |
48 | 46 | if (!src_dir) return false; |
49 | 47 | int src_fd = dirfd(src_dir.get()); |
@@ -95,12 +93,7 @@ static bool patch_rc_scripts(const char *src_path, const char *tmp_path, bool wr |
95 | 93 | fprintf(dest.get(), "\n"); |
96 | 94 |
|
97 | 95 | // Inject custom rc scripts |
98 | | - for (auto &script : rc_list) { |
99 | | - // Replace template arguments of rc scripts with dynamic paths |
100 | | - replace_all(script, "${MAGISKTMP}", tmp_path); |
101 | | - fprintf(dest.get(), "\n%s\n", script.data()); |
102 | | - } |
103 | | - rc_list.clear(); |
| 96 | + rust::inject_custom_rc(rc_list, fileno(dest.get()), tmp_path); |
104 | 97 |
|
105 | 98 | // Inject Magisk rc scripts |
106 | 99 | rust::inject_magisk_rc(fileno(dest.get()), tmp_path); |
@@ -175,34 +168,6 @@ void MagiskInit::patch_fissiond(const char *tmp_path) noexcept { |
175 | 168 | } |
176 | 169 | } |
177 | 170 |
|
178 | | -static void load_overlay_rc(const char *overlay) { |
179 | | - auto dir = open_dir(overlay); |
180 | | - if (!dir) return; |
181 | | - |
182 | | - int dfd = dirfd(dir.get()); |
183 | | - // Do not allow overwrite init.rc |
184 | | - unlinkat(dfd, INIT_RC, 0); |
185 | | - |
186 | | - // '/' + name + '\0' |
187 | | - char buf[NAME_MAX + 2]; |
188 | | - buf[0] = '/'; |
189 | | - for (dirent *entry; (entry = xreaddir(dir.get()));) { |
190 | | - if (!str_ends(entry->d_name, ".rc")) { |
191 | | - continue; |
192 | | - } |
193 | | - strscpy(buf + 1, entry->d_name, sizeof(buf) - 1); |
194 | | - if (access(buf, F_OK) == 0) { |
195 | | - LOGD("Replace rc script [%s]\n", entry->d_name); |
196 | | - } else { |
197 | | - LOGD("Found rc script [%s]\n", entry->d_name); |
198 | | - int rc = xopenat(dfd, entry->d_name, O_RDONLY | O_CLOEXEC); |
199 | | - rc_list.push_back(full_read(rc)); |
200 | | - close(rc); |
201 | | - unlinkat(dfd, entry->d_name, 0); |
202 | | - } |
203 | | - } |
204 | | -} |
205 | | - |
206 | 171 | static void recreate_sbin(const char *mirror, bool use_bind_mount) { |
207 | 172 | auto dp = xopen_dir(mirror); |
208 | 173 | int src = dirfd(dp.get()); |
@@ -316,6 +281,8 @@ void MagiskInit::patch_ro_root() noexcept { |
316 | 281 | mv_path(ROOTOVL "/sbin", "."); |
317 | 282 | } |
318 | 283 |
|
| 284 | + handle_modules_rc(ROOTOVL); |
| 285 | + |
319 | 286 | // Patch init.rc |
320 | 287 | bool p; |
321 | 288 | if (access(NEW_INITRC_DIR "/" INIT_RC, F_OK) == 0) { |
@@ -356,6 +323,8 @@ void MagiskInit::patch_rw_root() noexcept { |
356 | 323 | rm_rf("/data/overlay.d"); |
357 | 324 | rm_rf("/.backup"); |
358 | 325 |
|
| 326 | + handle_modules_rc("/"); |
| 327 | + |
359 | 328 | // Patch init.rc |
360 | 329 | if (patch_rc_scripts("/", "/sbin", true)) |
361 | 330 | patch_fissiond("/sbin"); |
|
0 commit comments