Unverified Commit 5763a3d9 authored by LoveSy's avatar LoveSy Committed by GitHub

Support replacing existing .rc by overlay.d

Co-authored-by: 's avatartopjohnwu <topjohnwu@gmail.com>
parent 1b745ae1
...@@ -257,7 +257,7 @@ Since `/` is read-only on system-as-root devices, Magisk provides an overlay sys ...@@ -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
......
...@@ -68,8 +68,18 @@ static void load_overlay_rc(const char *overlay) { ...@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment