Support replacing existing .rc by overlay.d

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
LoveSy 2022-12-26 19:28:10 +08:00 committed by GitHub
parent 1b745ae1a0
commit 5763a3d908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -257,7 +257,7 @@ Since `/` is read-only on system-as-root devices, Magisk provides an overlay sys
Overlay files shall be placed in the `overlay.d` folder in boot image ramdisk, and they follow these rules: Overlay files shall be placed in the `overlay.d` folder in boot image ramdisk, and they follow these rules:
1. All `*.rc` files in `overlay.d` will be read and concatenated **AFTER** `init.rc` 1. Each `*.rc` file (except for `init.rc`) in `overlay.d` will be read and concatenated **AFTER** `init.rc` if it does not exist in the root directory, otherwise it will **REPLACE** the existing one.
2. Existing files can be replaced by files located at the same relative path 2. Existing files can be replaced by files located at the same relative path
3. Files that correspond to a non-existing file will be ignored 3. Files that correspond to a non-existing file will be ignored

View File

@ -68,8 +68,18 @@ static void load_overlay_rc(const char *overlay) {
int dfd = dirfd(dir.get()); int dfd = dirfd(dir.get());
// Do not allow overwrite init.rc // Do not allow overwrite init.rc
unlinkat(dfd, "init.rc", 0); unlinkat(dfd, "init.rc", 0);
// '/' + name + '\0'
char buf[NAME_MAX + 2];
buf[0] = '/';
for (dirent *entry; (entry = xreaddir(dir.get()));) { for (dirent *entry; (entry = xreaddir(dir.get()));) {
if (str_ends(entry->d_name, ".rc")) { if (!str_ends(entry->d_name, ".rc")) {
continue;
}
strscpy(buf + 1, entry->d_name, sizeof(buf) - 1);
if (access(buf, F_OK) == 0) {
LOGD("Replace rc script [%s]\n", entry->d_name);
} else {
LOGD("Found rc script [%s]\n", entry->d_name); LOGD("Found rc script [%s]\n", entry->d_name);
int rc = xopenat(dfd, entry->d_name, O_RDONLY | O_CLOEXEC); int rc = xopenat(dfd, entry->d_name, O_RDONLY | O_CLOEXEC);
rc_list.push_back(full_read(rc)); rc_list.push_back(full_read(rc));