Use backup init if booted as recovery

This commit is contained in:
topjohnwu 2017-09-13 04:06:39 +08:00
parent ff7c38f8e9
commit 3a2262dfb3

View File

@ -1,3 +1,14 @@
/* magiskinit.c - Workaround for skip_initramfs devices
*
* This code has to be compiled statically to work properly.
*
* Magiskinit will mount sysfs, parse through uevent files to make the system block device,
* then it'll mount the system partition and clone rootfs except files under /system.
* Folders placed in "overlay" will then be overlayed to the root.
* Lastly before giving control back to the real init, it'll patch the root files to load Magisk.
*/
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -287,7 +298,7 @@ int main(int argc, char *argv[]) {
// Recovery mode // Recovery mode
// Revert original init binary // Revert original init binary
unlink("/init"); unlink("/init");
rename("/init_orig", "/init"); rename("/.backup/init", "/init");
} }
execv("/init", argv); execv("/init", argv);