Make tmpfs path static strings

This commit is contained in:
topjohnwu 2023-10-29 00:47:28 -07:00
parent 67cc36268e
commit 19a4e11645
5 changed files with 21 additions and 27 deletions

View File

@ -411,27 +411,25 @@ static void daemon_entry() {
poll_loop();
}
string find_magisk_tmp() {
const char *get_magisk_tmp() {
static const char *path = nullptr;
if (path == nullptr) {
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;
path = "/debug_ramdisk";
} else if (access("/sbin/" INTLROOT, F_OK) == 0) {
path = "/sbin";
} else {
path = "";
}
}
return "";
return path;
}
int connect_daemon(int req, bool create) {
int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
sockaddr_un addr = {.sun_family = AF_LOCAL};
string tmp = find_magisk_tmp();
strcpy(addr.sun_path, (tmp + "/" MAIN_SOCKET).data());
const char *tmp = get_magisk_tmp();
ssprintf(addr.sun_path, sizeof(addr.sun_path), "%s/" MAIN_SOCKET, tmp);
if (connect(fd, (sockaddr *) &addr, sizeof(addr))) {
if (!create || getuid() != AID_ROOT) {
LOGE("No daemon is currently running!\n");
@ -441,7 +439,7 @@ int connect_daemon(int req, bool create) {
char buf[64];
xreadlink("/proc/self/exe", buf, sizeof(buf));
if (tmp.empty() || !str_starts(buf, tmp)) {
if (tmp[0] == '\0' || !str_starts(buf, tmp)) {
LOGE("Start daemon on magisk tmpfs\n");
close(fd);
return -1;

View File

@ -129,9 +129,9 @@ int magisk_main(int argc, char *argv[]) {
write_int(fd, do_reboot);
return read_int(fd);
} else if (argv[1] == "--path"sv) {
string path = find_magisk_tmp();
if (!path.empty()) {
printf("%s\n", path.data());
const char *path = get_magisk_tmp();
if (path[0] != '\0') {
printf("%s\n", path);
return 0;
}
return 1;

View File

@ -71,7 +71,7 @@ extern int app_process_32;
extern int app_process_64;
extern std::vector<module_info> *module_list;
std::string find_magisk_tmp();
const char *get_magisk_tmp();
int connect_daemon(int req, bool create = false);
// Poll control

View File

@ -3,7 +3,6 @@
#include <string>
#define JAVA_PACKAGE_NAME "com.topjohnwu.magisk"
#define LOGFILE "/cache/magisk.log"
#define SECURE_DIR "/data/adb"
#define MODULEROOT SECURE_DIR "/modules"
#define MODULEUPGRADE SECURE_DIR "/modules_update"

View File

@ -61,9 +61,8 @@ done
# Stop zygote (and previous setup if exists)
magisk --stop 2>/dev/null
stop
if [ -d /dev/avd-magisk ]; then
umount -l /dev/avd-magisk 2>/dev/null
rm -rf /dev/avd-magisk 2>/dev/null
if [ -d /debug_ramdisk ]; then
umount -l /debug_ramdisk 2>/dev/null
fi
# Make sure boot completed props are not set to 1
@ -108,11 +107,10 @@ elif [ -e /sbin ]; then
rm -rf /dev/sysroot
else
# Android Q+ without sbin
MAGISKTMP=/dev/avd-magisk
mkdir /dev/avd-magisk
MAGISKTMP=/debug_ramdisk
# If a file name 'magisk' is in current directory, mount will fail
rm -f magisk
mount -t tmpfs -o 'mode=0755' magisk /dev/avd-magisk
mount -t tmpfs -o 'mode=0755' magisk /debug_ramdisk
fi
# Magisk stuff
@ -138,7 +136,6 @@ else
fi
ln -s ./magisk $MAGISKTMP/su
ln -s ./magisk $MAGISKTMP/resetprop
ln -s ./magisk $MAGISKTMP/magiskhide
ln -s ./magiskpolicy $MAGISKTMP/supolicy
mkdir -p $MAGISKTMP/.magisk/mirror