Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b140f20 authored by Josh Gao's avatar Josh Gao Committed by android-build-merger
Browse files

Merge "adbd: improve thread names." am: 39071a51

am: bc3d3625

Change-Id: I5c64bbe5e535b87162cedd8cf28dad3c1174c44d
parents af8315d4 bc3d3625
Loading
Loading
Loading
Loading
+21 −18
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@
#include "transport.h"

struct stinfo {
    const char* service_name;
    void (*func)(int fd, void *cookie);
    int fd;
    void *cookie;
@@ -65,7 +66,7 @@ struct stinfo {

static void service_bootstrap_func(void* x) {
    stinfo* sti = reinterpret_cast<stinfo*>(x);
    adb_thread_setname(android::base::StringPrintf("service %d", sti->fd));
    adb_thread_setname(android::base::StringPrintf("%s svc %d", sti->service_name, sti->fd));
    sti->func(sti->fd, sti->cookie);
    free(sti);
}
@@ -160,8 +161,7 @@ static bool reboot_service_impl(int fd, const char* arg) {
    return true;
}

void reboot_service(int fd, void* arg)
{
void reboot_service(int fd, void* arg) {
    if (reboot_service_impl(fd, static_cast<const char*>(arg))) {
        // Don't return early. Give the reboot command time to take effect
        // to avoid messing up scripts which do "adb reboot && adb wait-for-device"
@@ -236,8 +236,7 @@ static int ShellService(const std::string& args, const atransport* transport) {

#endif  // !ADB_HOST

static int create_service_thread(void (*func)(int, void *), void *cookie)
{
static int create_service_thread(const char* service_name, void (*func)(int, void*), void* cookie) {
    int s[2];
    if (adb_socketpair(s)) {
        printf("cannot create service socket pair\n");
@@ -258,6 +257,7 @@ static int create_service_thread(void (*func)(int, void *), void *cookie)
    if (sti == nullptr) {
        fatal("cannot allocate stinfo");
    }
    sti->service_name = service_name;
    sti->func = func;
    sti->cookie = cookie;
    sti->fd = s[1];
@@ -281,7 +281,7 @@ int service_to_fd(const char* name, const atransport* transport) {
    } else if(!strncmp("dev:", name, 4)) {
        ret = unix_open(name + 4, O_RDWR | O_CLOEXEC);
    } else if(!strncmp(name, "framebuffer:", 12)) {
        ret = create_service_thread(framebuffer_service, 0);
        ret = create_service_thread("fb", framebuffer_service, nullptr);
    } else if (!strncmp(name, "jdwp:", 5)) {
        ret = create_jdwp_connection_fd(atoi(name+5));
    } else if(!strncmp(name, "shell", 5)) {
@@ -289,17 +289,17 @@ int service_to_fd(const char* name, const atransport* transport) {
    } else if(!strncmp(name, "exec:", 5)) {
        ret = StartSubprocess(name + 5, nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
    } else if(!strncmp(name, "sync:", 5)) {
        ret = create_service_thread(file_sync_service, NULL);
        ret = create_service_thread("sync", file_sync_service, nullptr);
    } else if(!strncmp(name, "remount:", 8)) {
        ret = create_service_thread(remount_service, NULL);
        ret = create_service_thread("remount", remount_service, nullptr);
    } else if(!strncmp(name, "reboot:", 7)) {
        void* arg = strdup(name + 7);
        if (arg == NULL) return -1;
        ret = create_service_thread(reboot_service, arg);
        ret = create_service_thread("reboot", reboot_service, arg);
    } else if(!strncmp(name, "root:", 5)) {
        ret = create_service_thread(restart_root_service, NULL);
        ret = create_service_thread("root", restart_root_service, nullptr);
    } else if(!strncmp(name, "unroot:", 7)) {
        ret = create_service_thread(restart_unroot_service, NULL);
        ret = create_service_thread("unroot", restart_unroot_service, nullptr);
    } else if(!strncmp(name, "backup:", 7)) {
        ret = StartSubprocess(android::base::StringPrintf("/system/bin/bu backup %s",
                                                          (name + 7)).c_str(),
@@ -312,17 +312,20 @@ int service_to_fd(const char* name, const atransport* transport) {
        if (sscanf(name + 6, "%d", &port) != 1) {
            return -1;
        }
        ret = create_service_thread(restart_tcp_service, (void *) (uintptr_t) port);
        ret = create_service_thread("tcp", restart_tcp_service, reinterpret_cast<void*>(port));
    } else if(!strncmp(name, "usb:", 4)) {
        ret = create_service_thread(restart_usb_service, NULL);
        ret = create_service_thread("usb", restart_usb_service, nullptr);
    } else if (!strncmp(name, "reverse:", 8)) {
        ret = reverse_service(name + 8);
    } else if(!strncmp(name, "disable-verity:", 15)) {
        ret = create_service_thread(set_verity_enabled_state_service, (void*)0);
        ret = create_service_thread("verity-on", set_verity_enabled_state_service,
                                    reinterpret_cast<void*>(0));
    } else if(!strncmp(name, "enable-verity:", 15)) {
        ret = create_service_thread(set_verity_enabled_state_service, (void*)1);
        ret = create_service_thread("verity-off", set_verity_enabled_state_service,
                                    reinterpret_cast<void*>(1));
    } else if (!strcmp(name, "reconnect")) {
        ret = create_service_thread(reconnect_service, const_cast<atransport*>(transport));
        ret = create_service_thread("reconnect", reconnect_service,
                                    const_cast<atransport*>(transport));
#endif
    }
    if (ret >= 0) {
@@ -484,14 +487,14 @@ asocket* host_service_to_socket(const char* name, const char* serial, TransportI
            return nullptr;
        }

        int fd = create_service_thread(wait_for_state, sinfo.get());
        int fd = create_service_thread("wait", wait_for_state, sinfo.get());
        if (fd != -1) {
            sinfo.release();
        }
        return create_local_socket(fd);
    } else if (!strncmp(name, "connect:", 8)) {
        char* host = strdup(name + 8);
        int fd = create_service_thread(connect_service, host);
        int fd = create_service_thread("connect", connect_service, host);
        if (fd == -1) {
            free(host);
        }
+1 −2
Original line number Diff line number Diff line
@@ -435,8 +435,7 @@ int Subprocess::OpenPtyChildFd(const char* pts_name, unique_fd* error_sfd) {
void Subprocess::ThreadHandler(void* userdata) {
    Subprocess* subprocess = reinterpret_cast<Subprocess*>(userdata);

    adb_thread_setname(android::base::StringPrintf(
            "shell srvc %d", subprocess->pid()));
    adb_thread_setname(android::base::StringPrintf("shell svc %d", subprocess->pid()));

    D("passing data streams for PID %d", subprocess->pid());
    subprocess->PassDataStreams();