use /debug_ramdisk

This commit is contained in:
5ec1cff
2024-01-02 18:03:17 +08:00
parent 28f77fa5e2
commit 5c8a67657c
13 changed files with 33 additions and 65 deletions

View File

@@ -37,13 +37,7 @@ enum TracingState {
std::string monitor_stop_reason;
constexpr char SOCKET_NAME[] = "init_monitor";
std::string GetControlSocketName() {
auto env = getenv(MAGIC_ENV);
if (env == nullptr) return SOCKET_NAME;
return std::string(SOCKET_NAME) + env;
}
constexpr char SOCKET_NAME[] = TMP_PATH "/init_monitor";
struct EventLoop;
@@ -141,9 +135,8 @@ struct SocketHandler : public EventHandler {
.sun_family = AF_UNIX,
.sun_path={0},
};
auto socket_name = GetControlSocketName();
strcpy(addr.sun_path + 1, socket_name.c_str());
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path + 1) + 1;
strcpy(addr.sun_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");
return false;
@@ -542,12 +535,7 @@ static void updateStatus() {
}
static bool prepare_environment() {
auto path = getenv(MAGIC_PATH_ENV);
if (path == nullptr) {
LOGE("path is null, is MAGIC_PATH_ENV specified?");
return false;
}
prop_path = std::string(path) + "/module.prop";
prop_path = 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) {
@@ -618,9 +606,8 @@ void send_control_command(Command cmd) {
.sun_family = AF_UNIX,
.sun_path={0},
};
auto socket_name = GetControlSocketName();
strcpy(addr.sun_path + 1, socket_name.c_str());
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path + 1) + 1;
strcpy(addr.sun_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) {
err(EXIT_FAILURE, "send");