mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Improve APK installation and add logging
This commit is contained in:
parent
18f6ead891
commit
558f95cf7e
@ -648,6 +648,7 @@ core_only:
|
|||||||
// Install Magisk Manager if exists
|
// Install Magisk Manager if exists
|
||||||
if (access(MANAGERAPK, F_OK) == 0) {
|
if (access(MANAGERAPK, F_OK) == 0) {
|
||||||
rename(MANAGERAPK, "/data/magisk.apk");
|
rename(MANAGERAPK, "/data/magisk.apk");
|
||||||
|
setfilecon("/data/magisk.apk", "u:object_r:su_file:s0");
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep(5);
|
sleep(5);
|
||||||
int apk_res = -1, pid;
|
int apk_res = -1, pid;
|
||||||
@ -656,11 +657,16 @@ core_only:
|
|||||||
"/system/bin", "com.android.commands.pm.Pm",
|
"/system/bin", "com.android.commands.pm.Pm",
|
||||||
"install", "-r", "/data/magisk.apk", NULL);
|
"install", "-r", "/data/magisk.apk", NULL);
|
||||||
if (pid != -1) {
|
if (pid != -1) {
|
||||||
|
int err = 0;
|
||||||
|
while (fdgets(buf, PATH_MAX, apk_res) > 0) {
|
||||||
|
LOGD("apk_install: %s", buf);
|
||||||
|
err |= strstr(buf, "Error:") != NULL;
|
||||||
|
}
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
fdgets(buf, PATH_MAX, apk_res);
|
|
||||||
close(apk_res);
|
close(apk_res);
|
||||||
// Keep trying until pm is started
|
// Keep trying until pm is started
|
||||||
if (strstr(buf, "Error:") == NULL)
|
if (err)
|
||||||
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,12 @@ static int is_num(const char *s) {
|
|||||||
ssize_t fdgets(char *buf, const size_t size, int fd) {
|
ssize_t fdgets(char *buf, const size_t size, int fd) {
|
||||||
ssize_t len = 0;
|
ssize_t len = 0;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
while (read(fd, buf + len, 1) >= 0 && len < size - 1) {
|
while (len < size - 1) {
|
||||||
|
int ret = read(fd, buf + len, 1);
|
||||||
|
if (ret < 0)
|
||||||
|
return -1;
|
||||||
|
if (ret == 0)
|
||||||
|
break;
|
||||||
if (buf[len] == '\0' || buf[len++] == '\n') {
|
if (buf[len] == '\0' || buf[len++] == '\n') {
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user