mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-11 18:54:30 +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");
|
exec_common_script("service");
|
||||||
|
|
||||||
// Core only mode
|
// Core only mode
|
||||||
if (access(DISABLEFILE, F_OK) == 0)
|
if (access(DISABLEFILE, F_OK) != 0) {
|
||||||
goto core_only;
|
LOGI("* Running module service scripts\n");
|
||||||
|
exec_module_script("service", module_list);
|
||||||
|
}
|
||||||
|
|
||||||
LOGI("* Running module service scripts\n");
|
// All boot stage done, cleanup
|
||||||
exec_module_script("service", module_list);
|
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) {
|
if (access(MANAGERAPK, F_OK) == 0) {
|
||||||
// Install Magisk Manager if exists
|
// Install Magisk Manager if exists
|
||||||
rename(MANAGERAPK, "/data/magisk.apk");
|
rename(MANAGERAPK, "/data/magisk.apk");
|
||||||
@ -721,16 +730,4 @@ core_only:
|
|||||||
install_apk("/data/magisk.apk");
|
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());
|
fprintf(rc, "%s", line.data());
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
char pfd_svc[8], ls_svc[8];
|
char pfd_svc[8], ls_svc[8], bc_svc[8];
|
||||||
gen_rand_str(pfd_svc, sizeof(pfd_svc));
|
// Make sure to be unique
|
||||||
do {
|
pfd_svc[0] = 'a';
|
||||||
gen_rand_str(ls_svc, sizeof(ls_svc));
|
ls_svc[0] = '0';
|
||||||
} while (strcmp(pfd_svc, ls_svc) == 0);
|
bc_svc[0] = 'A';
|
||||||
fprintf(rc, magiskrc, pfd_svc, pfd_svc, ls_svc);
|
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);
|
fclose(rc);
|
||||||
clone_attr("/init.rc", "/init.p.rc");
|
clone_attr("/init.rc", "/init.p.rc");
|
||||||
rename("/init.p.rc", "/init.rc");
|
rename("/init.p.rc", "/init.rc");
|
||||||
|
@ -32,15 +32,13 @@ static const char magiskrc[] =
|
|||||||
" oneshot\n"
|
" oneshot\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
||||||
#if 0
|
|
||||||
"on property:sys.boot_completed=1\n"
|
"on property:sys.boot_completed=1\n"
|
||||||
" start magisk_bc\n"
|
" start %s\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
||||||
"service magisk_bc /sbin/magisk --boot-complete\n"
|
"service %s /sbin/magisk --boot-complete\n"
|
||||||
" user root\n"
|
" user root\n"
|
||||||
" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n"
|
" seclabel u:r:" SEPOL_PROC_DOMAIN ":s0\n"
|
||||||
" oneshot\n"
|
" oneshot\n"
|
||||||
;
|
"\n"
|
||||||
#endif
|
|
||||||
;
|
;
|
||||||
|
@ -101,21 +101,16 @@ void migrate_img(const char *img) {
|
|||||||
|
|
||||||
static const char install_script[] =
|
static const char install_script[] =
|
||||||
"APK=%s;"
|
"APK=%s;"
|
||||||
"while true; do"
|
"log -t Magisk \"apk_install: $APK\";"
|
||||||
" OUT=`pm install -r $APK 2>&1`;"
|
"log -t Magisk \"apk_install: `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;"
|
|
||||||
"rm -f $APK;";
|
"rm -f $APK;";
|
||||||
|
|
||||||
void install_apk(const char *apk) {
|
void install_apk(const char *apk) {
|
||||||
setfilecon(apk, "u:object_r:" SEPOL_FILE_DOMAIN ":s0");
|
setfilecon(apk, "u:object_r:" SEPOL_FILE_DOMAIN ":s0");
|
||||||
LOGI("apk_install: %s\n", apk);
|
exec_t exec {
|
||||||
exec_t exec { .pre_exec = set_path };
|
.pre_exec = set_path,
|
||||||
|
.fork = fork_no_zombie
|
||||||
|
};
|
||||||
char cmds[sizeof(install_script) + 4096];
|
char cmds[sizeof(install_script) + 4096];
|
||||||
sprintf(cmds, install_script, apk);
|
sprintf(cmds, install_script, apk);
|
||||||
exec_command_sync(exec, "/system/bin/sh", "-c", cmds);
|
exec_command_sync(exec, "/system/bin/sh", "-c", cmds);
|
||||||
|
@ -49,20 +49,16 @@ int fork_no_zombie() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool rand_init = false;
|
||||||
|
|
||||||
void gen_rand_str(char *buf, int len) {
|
void gen_rand_str(char *buf, int len) {
|
||||||
const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
constexpr const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
int urandom;
|
if (!rand_init) {
|
||||||
if (access("/dev/urandom", R_OK) == 0) {
|
srand(time(nullptr));
|
||||||
urandom = xopen("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
rand_init = true;
|
||||||
} else {
|
|
||||||
mknod("/urandom", S_IFCHR | 0666, makedev(1, 9));
|
|
||||||
urandom = xopen("/urandom", O_RDONLY | O_CLOEXEC);
|
|
||||||
unlink("/urandom");
|
|
||||||
}
|
}
|
||||||
xxread(urandom, buf, len - 1);
|
|
||||||
close(urandom);
|
|
||||||
for (int i = 0; i < len - 1; ++i) {
|
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';
|
buf[len - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user