More fail proof to magiskinit
This commit is contained in:
parent
39a6bd33ce
commit
742dc137ed
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -385,7 +386,6 @@ static void magisk_init_daemon() {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@ -403,6 +403,14 @@ int main(int argc, char *argv[]) {
|
||||
return dump_magiskrc(argv[3], 0755);
|
||||
}
|
||||
|
||||
// Prevent file descriptor confusion
|
||||
mknod("/null", S_IFCHR | 0666, makedev(1, 3));
|
||||
int null = open("/null", O_RDWR | O_CLOEXEC);
|
||||
unlink("/null");
|
||||
dup3(null, STDIN_FILENO, O_CLOEXEC);
|
||||
dup3(null, STDOUT_FILENO, O_CLOEXEC);
|
||||
dup3(null, STDERR_FILENO, O_CLOEXEC);
|
||||
|
||||
// Extract and link files
|
||||
mkdir("/overlay", 0000);
|
||||
dump_magiskrc("/overlay/init.magisk.rc", 0750);
|
||||
@ -456,6 +464,8 @@ int main(int argc, char *argv[]) {
|
||||
link("/.backup/init", "/init");
|
||||
}
|
||||
|
||||
// Only patch initramfs if not intended to run in recovery (legacy devices)
|
||||
if (access("/etc/recovery.fstab", F_OK) != 0) {
|
||||
int overlay = open("/overlay", O_RDONLY | O_CLOEXEC);
|
||||
mv_dir(overlay, root);
|
||||
|
||||
@ -467,13 +477,13 @@ int main(int argc, char *argv[]) {
|
||||
patch_ramdisk();
|
||||
patch_sepolicy();
|
||||
|
||||
umount("/vendor");
|
||||
|
||||
if (fork_dont_care() == 0) {
|
||||
strcpy(argv[0], "magiskinit");
|
||||
magisk_init_daemon();
|
||||
}
|
||||
}
|
||||
|
||||
umount("/vendor");
|
||||
// Finally, give control back!
|
||||
execv("/init", argv);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user