mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 16:07:39 +00:00
Faster get magisk tmpfs path
This commit is contained in:
parent
533aeadd38
commit
dd93556ad8
@ -179,9 +179,6 @@ static void handle_request_sync(int client, int code) {
|
|||||||
case MainRequest::CHECK_VERSION_CODE:
|
case MainRequest::CHECK_VERSION_CODE:
|
||||||
write_int(client, MAGISK_VER_CODE);
|
write_int(client, MAGISK_VER_CODE);
|
||||||
break;
|
break;
|
||||||
case MainRequest::GET_PATH:
|
|
||||||
write_string(client, MAGISKTMP.data());
|
|
||||||
break;
|
|
||||||
case MainRequest::START_DAEMON:
|
case MainRequest::START_DAEMON:
|
||||||
rust::get_magiskd().setup_logfile();
|
rust::get_magiskd().setup_logfile();
|
||||||
break;
|
break;
|
||||||
@ -240,7 +237,6 @@ static void handle_request(pollfd *pfd) {
|
|||||||
case MainRequest::BOOT_COMPLETE:
|
case MainRequest::BOOT_COMPLETE:
|
||||||
case MainRequest::ZYGOTE_RESTART:
|
case MainRequest::ZYGOTE_RESTART:
|
||||||
case MainRequest::SQLITE_CMD:
|
case MainRequest::SQLITE_CMD:
|
||||||
case MainRequest::GET_PATH:
|
|
||||||
case MainRequest::DENYLIST:
|
case MainRequest::DENYLIST:
|
||||||
case MainRequest::STOP_DAEMON:
|
case MainRequest::STOP_DAEMON:
|
||||||
if (!is_root) {
|
if (!is_root) {
|
||||||
@ -415,15 +411,26 @@ static void daemon_entry() {
|
|||||||
poll_loop();
|
poll_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string find_magisk_tmp() {
|
||||||
|
if (access("/debug_ramdisk/" INTLROOT, F_OK) == 0) {
|
||||||
|
return "/debug_ramdisk";
|
||||||
|
}
|
||||||
|
if (access("/sbin/" INTLROOT, F_OK) == 0) {
|
||||||
|
return "/sbin";
|
||||||
|
}
|
||||||
|
// Fallback to lookup from mountinfo for manual mount, e.g. avd
|
||||||
|
for (const auto &mount: parse_mount_info("self")) {
|
||||||
|
if (mount.source == "magisk" && mount.root == "/") {
|
||||||
|
return mount.target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
int connect_daemon(int req, bool create) {
|
int connect_daemon(int req, bool create) {
|
||||||
int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||||
sockaddr_un addr = {.sun_family = AF_LOCAL};
|
sockaddr_un addr = {.sun_family = AF_LOCAL};
|
||||||
string tmp;
|
string tmp = find_magisk_tmp();
|
||||||
for (const auto &info: parse_mount_info("self")) {
|
|
||||||
if (info.source == "magisk" && info.root == "/") {
|
|
||||||
tmp = info.target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strcpy(addr.sun_path, (tmp + "/" MAIN_SOCKET).data());
|
strcpy(addr.sun_path, (tmp + "/" MAIN_SOCKET).data());
|
||||||
if (connect(fd, (sockaddr *) &addr, sizeof(addr))) {
|
if (connect(fd, (sockaddr *) &addr, sizeof(addr))) {
|
||||||
if (!create || getuid() != AID_ROOT) {
|
if (!create || getuid() != AID_ROOT) {
|
||||||
|
@ -129,10 +129,12 @@ int magisk_main(int argc, char *argv[]) {
|
|||||||
write_int(fd, do_reboot);
|
write_int(fd, do_reboot);
|
||||||
return read_int(fd);
|
return read_int(fd);
|
||||||
} else if (argv[1] == "--path"sv) {
|
} else if (argv[1] == "--path"sv) {
|
||||||
int fd = connect_daemon(MainRequest::GET_PATH);
|
string path = find_magisk_tmp();
|
||||||
string path = read_string(fd);
|
if (!path.empty()) {
|
||||||
printf("%s\n", path.data());
|
printf("%s\n", path.data());
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
} else if (argc >= 3 && argv[1] == "--install-module"sv) {
|
} else if (argc >= 3 && argv[1] == "--install-module"sv) {
|
||||||
install_module(argv[2]);
|
install_module(argv[2]);
|
||||||
} else if (argv[1] == "--preinit-device"sv) {
|
} else if (argv[1] == "--preinit-device"sv) {
|
||||||
|
@ -25,7 +25,6 @@ enum : int {
|
|||||||
START_DAEMON,
|
START_DAEMON,
|
||||||
CHECK_VERSION,
|
CHECK_VERSION,
|
||||||
CHECK_VERSION_CODE,
|
CHECK_VERSION_CODE,
|
||||||
GET_PATH,
|
|
||||||
STOP_DAEMON,
|
STOP_DAEMON,
|
||||||
|
|
||||||
_SYNC_BARRIER_,
|
_SYNC_BARRIER_,
|
||||||
@ -72,6 +71,7 @@ extern int app_process_32;
|
|||||||
extern int app_process_64;
|
extern int app_process_64;
|
||||||
extern std::vector<module_info> *module_list;
|
extern std::vector<module_info> *module_list;
|
||||||
|
|
||||||
|
std::string find_magisk_tmp();
|
||||||
int connect_daemon(int req, bool create = false);
|
int connect_daemon(int req, bool create = false);
|
||||||
|
|
||||||
// Poll control
|
// Poll control
|
||||||
|
@ -84,9 +84,6 @@ int denylist_cli(int argc, char **argv) {
|
|||||||
else if (argv[1] == "exec"sv && argc > 2) {
|
else if (argv[1] == "exec"sv && argc > 2) {
|
||||||
xunshare(CLONE_NEWNS);
|
xunshare(CLONE_NEWNS);
|
||||||
xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr);
|
xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr);
|
||||||
int fd = connect_daemon(MainRequest::GET_PATH);
|
|
||||||
MAGISKTMP = read_string(fd);
|
|
||||||
close(fd);
|
|
||||||
revert_unmount();
|
revert_unmount();
|
||||||
execvp(argv[2], argv + 2);
|
execvp(argv[2], argv + 2);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user