No hardcode temp dir

This commit is contained in:
Nullptr
2024-01-04 03:44:57 +08:00
parent 32931cf3a8
commit 043cfd93d6
11 changed files with 56 additions and 50 deletions

View File

@@ -7,19 +7,13 @@
#include "socket_utils.h"
namespace zygiskd {
static std::string zygisk_path;
void Init(const char *path) {
LOGI("zygisk path set to %s", path);
zygisk_path = path;
}
int Connect(uint8_t retry) {
int fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
struct sockaddr_un addr{
.sun_family = AF_UNIX,
.sun_path={0},
};
auto socket_path = zygisk_path + kCPSocketName;
auto socket_path = std::string(TMP_PATH) + kCPSocketName;
strcpy(addr.sun_path, socket_path.c_str());
socklen_t socklen = sizeof(addr);

View File

@@ -12,7 +12,7 @@
#endif
constexpr auto kCPSocketName = "/" LP_SELECT("cp32", "cp64") ".sock";
#define TMP_PATH "/debug_ramdisk/zygisksu"
inline static const char* TMP_PATH = getenv("TMP_PATH");
class UniqueFd {
using Fd = int;
@@ -63,8 +63,6 @@ namespace zygiskd {
SystemServerStarted,
};
void Init(const char *path = TMP_PATH);
bool PingHeartbeat();
int RequestLogcatFd();

View File

@@ -12,7 +12,6 @@ void entry(void* handle) {
LOGI("Zygisk library injected, version %s", ZKSU_VERSION);
self_handle = handle;
zygiskd::Init();
if (!zygiskd::PingHeartbeat()) {
LOGE("Zygisk daemon is not running");
return;

View File

@@ -19,7 +19,6 @@ int main(int argc, char **argv) {
return 0;
} else if (argc >= 3 && argv[1] == "trace"sv) {
if (argc >= 4 && argv[3] == "--restart"sv) {
zygiskd::Init();
zygiskd::ZygoteRestart();
}
auto pid = strtol(argv[2], 0, 0);

View File

@@ -37,7 +37,7 @@ enum TracingState {
std::string monitor_stop_reason;
constexpr char SOCKET_NAME[] = TMP_PATH "/init_monitor";
constexpr char SOCKET_NAME[] = "init_monitor";
struct EventLoop;
@@ -136,7 +136,7 @@ struct SocketHandler : public EventHandler {
.sun_family = AF_UNIX,
.sun_path={0},
};
strcpy(addr.sun_path, SOCKET_NAME);
sprintf(addr.sun_path, "%s/%s", TMP_PATH, SOCKET_NAME);
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path);
if (bind(sock_fd_, (struct sockaddr *) &addr, socklen) == -1) {
PLOGE("bind socket");
@@ -544,7 +544,7 @@ static void updateStatus() {
}
static bool prepare_environment() {
prop_path = TMP_PATH "/module.prop";
prop_path = std::string(TMP_PATH) + "/module.prop";
close(open(prop_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644));
auto orig_prop = xopen_file("./module.prop", "r");
if (orig_prop == nullptr) {
@@ -595,7 +595,7 @@ void send_control_command(Command cmd) {
.sun_family = AF_UNIX,
.sun_path={0},
};
strcpy(addr.sun_path, SOCKET_NAME);
sprintf(addr.sun_path, "%s/%s", TMP_PATH, SOCKET_NAME);
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path);
auto nsend = sendto(sockfd, (void *) &cmd, sizeof(cmd), 0, (sockaddr *) &addr, socklen);
if (nsend == -1) {