mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-03 15:05:32 +00:00
Add boot_complete trigger back
Samsung does not like running cmd before system services are started. Instead of failing, it will enter an infinite wait on binder. Move APK installation to boot complete to make sure pm can be run without blocking process.
This commit is contained in:
parent
5203886f0b
commit
24f5bc98d8
@ -700,13 +700,22 @@ void late_start(int client) {
|
||||
exec_common_script("service");
|
||||
|
||||
// Core only mode
|
||||
if (access(DISABLEFILE, F_OK) == 0)
|
||||
goto core_only;
|
||||
if (access(DISABLEFILE, F_OK) != 0) {
|
||||
LOGI("* Running module service scripts\n");
|
||||
exec_module_script("service", module_list);
|
||||
}
|
||||
|
||||
LOGI("* Running module service scripts\n");
|
||||
exec_module_script("service", module_list);
|
||||
// All boot stage done, cleanup
|
||||
module_list.clear();
|
||||
module_list.shrink_to_fit();
|
||||
}
|
||||
|
||||
void boot_complete(int client) {
|
||||
LOGI("** boot_complete triggered\n");
|
||||
// ack
|
||||
write_int(client, 0);
|
||||
close(client);
|
||||
|
||||
core_only:
|
||||
if (access(MANAGERAPK, F_OK) == 0) {
|
||||
// Install Magisk Manager if exists
|
||||
rename(MANAGERAPK, "/data/magisk.apk");
|
||||
@ -721,16 +730,4 @@ core_only:
|
||||
install_apk("/data/magisk.apk");
|
||||
}
|
||||
}
|
||||
|
||||
// All boot stage done, cleanup
|
||||
module_list.clear();
|
||||
}
|
||||
|
||||
void boot_complete(int client) {
|
||||
LOGI("** boot_complete triggered\n");
|
||||
// ack
|
||||
write_int(client, 0);
|
||||
close(client);
|
||||
|
||||
unlink(BOOTCOUNT);
|
||||
}
|
||||
|
@ -516,12 +516,15 @@ void MagiskInit::setup_rootfs() {
|
||||
fprintf(rc, "%s", line.data());
|
||||
return true;
|
||||
});
|
||||
char pfd_svc[8], ls_svc[8];
|
||||
gen_rand_str(pfd_svc, sizeof(pfd_svc));
|
||||
do {
|
||||
gen_rand_str(ls_svc, sizeof(ls_svc));
|
||||
} while (strcmp(pfd_svc, ls_svc) == 0);
|
||||
fprintf(rc, magiskrc, pfd_svc, pfd_svc, ls_svc);
|
||||
char pfd_svc[8], ls_svc[8], bc_svc[8];
|
||||
// Make sure to be unique
|
||||
pfd_svc[0] = 'a';
|
||||
ls_svc[0] = '0';
|
||||
bc_svc[0] = 'A';
|
||||
gen_rand_str(pfd_svc + 1, sizeof(pfd_svc) - 1);
|
||||
gen_rand_str(ls_svc + 1, sizeof(ls_svc) - 1);
|
||||
gen_rand_str(bc_svc + 1, sizeof(bc_svc) - 1);
|
||||
fprintf(rc, magiskrc, pfd_svc, pfd_svc, ls_svc, bc_svc, bc_svc);
|
||||
fclose(rc);
|
||||
clone_attr("/init.rc", "/init.p.rc");
|
||||
rename("/init.p.rc", "/init.rc");
|
||||
|
@ -32,15 +32,13 @@ static const char magiskrc[] =
|
||||
" oneshot\n"
|
||||
"\n"
|
||||
|
||||
#if 0
|
||||
"on property:sys.boot_completed=1\n"
|
||||
" start magisk_bc\n"
|
||||
" start %s\n"
|
||||
"\n"
|
||||
|
||||
"service magisk_bc /sbin/magisk --boot-complete\n"
|
||||
"service %s /sbin/magisk --boot-complete\n"
|
||||
" user root\n"
|
||||
" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n"
|
||||
" seclabel u:r:" SEPOL_PROC_DOMAIN ":s0\n"
|
||||
" oneshot\n"
|
||||
;
|
||||
#endif
|
||||
"\n"
|
||||
;
|
||||
|
@ -101,21 +101,16 @@ void migrate_img(const char *img) {
|
||||
|
||||
static const char install_script[] =
|
||||
"APK=%s;"
|
||||
"while true; do"
|
||||
" OUT=`pm install -r $APK 2>&1`;"
|
||||
" log -t Magisk \"apk_install: $OUT\";"
|
||||
" if echo \"$OUT\" | grep -qE \"Can't|Error:\"; then"
|
||||
" sleep 5;"
|
||||
" continue;"
|
||||
" fi;"
|
||||
" break;"
|
||||
"done;"
|
||||
"log -t Magisk \"apk_install: $APK\";"
|
||||
"log -t Magisk \"apk_install: `pm install -r $APK 2>&1`\";"
|
||||
"rm -f $APK;";
|
||||
|
||||
void install_apk(const char *apk) {
|
||||
setfilecon(apk, "u:object_r:" SEPOL_FILE_DOMAIN ":s0");
|
||||
LOGI("apk_install: %s\n", apk);
|
||||
exec_t exec { .pre_exec = set_path };
|
||||
exec_t exec {
|
||||
.pre_exec = set_path,
|
||||
.fork = fork_no_zombie
|
||||
};
|
||||
char cmds[sizeof(install_script) + 4096];
|
||||
sprintf(cmds, install_script, apk);
|
||||
exec_command_sync(exec, "/system/bin/sh", "-c", cmds);
|
||||
|
@ -49,20 +49,16 @@ int fork_no_zombie() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool rand_init = false;
|
||||
|
||||
void gen_rand_str(char *buf, int len) {
|
||||
const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
int urandom;
|
||||
if (access("/dev/urandom", R_OK) == 0) {
|
||||
urandom = xopen("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
} else {
|
||||
mknod("/urandom", S_IFCHR | 0666, makedev(1, 9));
|
||||
urandom = xopen("/urandom", O_RDONLY | O_CLOEXEC);
|
||||
unlink("/urandom");
|
||||
constexpr const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
if (!rand_init) {
|
||||
srand(time(nullptr));
|
||||
rand_init = true;
|
||||
}
|
||||
xxread(urandom, buf, len - 1);
|
||||
close(urandom);
|
||||
for (int i = 0; i < len - 1; ++i) {
|
||||
buf[i] = base[buf[i] % (sizeof(base) - 1)];
|
||||
buf[i] = base[rand() % (sizeof(base) - 1)];
|
||||
}
|
||||
buf[len - 1] = '\0';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user