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(); poll_loop();
} }
string find_magisk_tmp() { const char *get_magisk_tmp() {
if (access("/debug_ramdisk/" INTLROOT, F_OK) == 0) { static const char *path = nullptr;
return "/debug_ramdisk"; if (path == nullptr) {
} if (access("/debug_ramdisk/" INTLROOT, F_OK) == 0) {
if (access("/sbin/" INTLROOT, F_OK) == 0) { path = "/debug_ramdisk";
return "/sbin"; } else if (access("/sbin/" INTLROOT, F_OK) == 0) {
} path = "/sbin";
// Fallback to lookup from mountinfo for manual mount, e.g. avd } else {
for (const auto &mount: parse_mount_info("self")) { path = "";
if (mount.source == "magisk" && mount.root == "/") {
return mount.target;
} }
} }
return ""; return path;
} }
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 = find_magisk_tmp(); const char *tmp = get_magisk_tmp();
strcpy(addr.sun_path, (tmp + "/" MAIN_SOCKET).data()); ssprintf(addr.sun_path, sizeof(addr.sun_path), "%s/" MAIN_SOCKET, tmp);
if (connect(fd, (sockaddr *) &addr, sizeof(addr))) { if (connect(fd, (sockaddr *) &addr, sizeof(addr))) {
if (!create || getuid() != AID_ROOT) { if (!create || getuid() != AID_ROOT) {
LOGE("No daemon is currently running!\n"); LOGE("No daemon is currently running!\n");
@ -441,7 +439,7 @@ int connect_daemon(int req, bool create) {
char buf[64]; char buf[64];
xreadlink("/proc/self/exe", buf, sizeof(buf)); 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"); LOGE("Start daemon on magisk tmpfs\n");
close(fd); close(fd);
return -1; return -1;

View File

@ -129,9 +129,9 @@ 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) {
string path = find_magisk_tmp(); const char *path = get_magisk_tmp();
if (!path.empty()) { if (path[0] != '\0') {
printf("%s\n", path.data()); printf("%s\n", path);
return 0; return 0;
} }
return 1; return 1;

View File

@ -71,7 +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(); const char *get_magisk_tmp();
int connect_daemon(int req, bool create = false); int connect_daemon(int req, bool create = false);
// Poll control // Poll control

View File

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

View File

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