mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-26 12:47:32 +00:00
Significantly better AVD support
This commit is contained in:
@@ -23,9 +23,9 @@ static bool safe_mode = false;
|
||||
* Setup *
|
||||
*********/
|
||||
|
||||
#define MNT_DIR_IS(dir) (me->mnt_dir == string_view(dir))
|
||||
#define SETMIR(b, part) sprintf(b, "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
|
||||
#define SETBLK(b, part) sprintf(b, "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
|
||||
#define MNT_DIR_IS(dir) (me->mnt_dir == string_view(dir))
|
||||
#define SETMIR(b, part) snprintf(b, sizeof(b), "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
|
||||
#define SETBLK(b, part) snprintf(b, sizeof(b), "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
|
||||
|
||||
#define do_mount_mirror(part, flag) {\
|
||||
SETMIR(buf1, part); \
|
||||
|
@@ -91,6 +91,11 @@ static void handle_request_sync(int client, int code) {
|
||||
case START_DAEMON:
|
||||
setup_logfile(true);
|
||||
break;
|
||||
case STOP_DAEMON:
|
||||
magiskhide_handler(-1, nullptr);
|
||||
write_int(client, 0);
|
||||
// Terminate the daemon!
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +125,7 @@ static void handle_request(int client) {
|
||||
case SQLITE_CMD:
|
||||
case GET_PATH:
|
||||
case MAGISKHIDE:
|
||||
case STOP_DAEMON:
|
||||
if (!is_root) {
|
||||
write_int(client, ROOT_REQUIRED);
|
||||
goto done;
|
||||
|
@@ -28,6 +28,7 @@ Options:
|
||||
|
||||
Advanced Options (Internal APIs):
|
||||
--daemon manually start magisk daemon
|
||||
--stop remove all magisk changes and stop daemon
|
||||
--[init trigger] start service for init trigger
|
||||
Supported init triggers:
|
||||
post-fs-data, service, boot-complete
|
||||
@@ -84,6 +85,10 @@ int magisk_main(int argc, char *argv[]) {
|
||||
int fd = connect_daemon(true);
|
||||
write_int(fd, START_DAEMON);
|
||||
return 0;
|
||||
} else if (argv[1] == "--stop"sv) {
|
||||
int fd = connect_daemon();
|
||||
write_int(fd, STOP_DAEMON);
|
||||
return read_int(fd);
|
||||
} else if (argv[1] == "--post-fs-data"sv) {
|
||||
int fd = connect_daemon(true);
|
||||
write_int(fd, POST_FS_DATA);
|
||||
|
@@ -19,7 +19,8 @@ enum : int {
|
||||
CHECK_VERSION = SYNC_FLAG | 1,
|
||||
CHECK_VERSION_CODE = SYNC_FLAG | 2,
|
||||
GET_PATH = SYNC_FLAG | 3,
|
||||
SUPERUSER = 4,
|
||||
STOP_DAEMON = SYNC_FLAG | 4,
|
||||
SUPERUSER = 5,
|
||||
POST_FS_DATA,
|
||||
LATE_START,
|
||||
BOOT_COMPLETE,
|
||||
|
@@ -25,14 +25,15 @@ void hide_daemon(int pid, int client) {
|
||||
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && str_starts(mentry->mnt_dir, "/" #dir))
|
||||
|
||||
void hide_unmount(int pid) {
|
||||
if (pid > 0 && switch_mnt_ns(pid))
|
||||
return;
|
||||
|
||||
LOGD("hide: handling PID=[%d]\n", pid > 0 ? pid : getpid());
|
||||
if (pid > 0) {
|
||||
if (switch_mnt_ns(pid))
|
||||
return;
|
||||
LOGD("hide: handling PID=[%d]\n", pid);
|
||||
}
|
||||
|
||||
vector<string> targets;
|
||||
|
||||
// Unmount dummy skeletons and /sbin links
|
||||
// Unmount dummy skeletons and MAGISKTMP
|
||||
targets.push_back(MAGISKTMP);
|
||||
parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
|
||||
if (TMPFS_MNT(system) || TMPFS_MNT(vendor) || TMPFS_MNT(product) || TMPFS_MNT(system_ext))
|
||||
|
@@ -25,6 +25,11 @@ using namespace std;
|
||||
}
|
||||
|
||||
void magiskhide_handler(int client, ucred *cred) {
|
||||
if (client < 0) {
|
||||
hide_unmount();
|
||||
return;
|
||||
}
|
||||
|
||||
int req = read_int(client);
|
||||
int res = DAEMON_ERROR;
|
||||
|
||||
|
@@ -126,7 +126,7 @@ int exec_command_sync(exec_t &exec, Args &&...args) {
|
||||
}
|
||||
template <class ...Args>
|
||||
int exec_command_sync(Args &&...args) {
|
||||
exec_t exec{};
|
||||
exec_t exec;
|
||||
return exec_command_sync(exec, args...);
|
||||
}
|
||||
template <class ...Args>
|
||||
|
Reference in New Issue
Block a user