static int create_subproc_thread(const char *name, bool pty = false) {
    const char *arg0, *arg1;
    if (name == 0 || *name == 0) {
        arg0 = "-"; arg1 = 0;
    } else {
        arg0 = "-c"; arg1 = name;
    }

    pid_t pid = -1;
    int ret_fd;
    if (pty) {
        ret_fd = create_subproc_pty(SHELL_COMMAND, arg0, arg1, &pid);
    } else {
        ret_fd = create_subproc_raw(SHELL_COMMAND, arg0, arg1, &pid);
    }
    D("create_subproc ret_fd=%d pid=%d\n", ret_fd, pid);

    stinfo* sti = reinterpret_cast<stinfo*>(malloc(sizeof(stinfo)));
    if(sti == 0) fatal("cannot allocate stinfo");
    sti->func = subproc_waiter_service;
    sti->cookie = (void*) (uintptr_t) pid;
    sti->fd = ret_fd;

    if (!adb_thread_create(service_bootstrap_func, sti)) {
        free(sti);
        adb_close(ret_fd);
        fprintf(stderr, "cannot create service thread\n");
        return -1;
    }

    D("service thread started, fd=%d pid=%d\n", ret_fd, pid);
    return ret_fd;
}
예제 #2
0
static int create_subproc_thread(const char *name, const subproc_mode mode)
{
    stinfo *sti;
    adb_thread_t t;
    int ret_fd;
    pid_t pid = -1;

    const char* shell_command;
    struct stat st;

    const char *arg0, *arg1;
    if (name == 0 || *name == 0) {
        arg0 = "-"; arg1 = 0;
    } else {
        arg0 = "-c"; arg1 = name;
    }

    char value[PROPERTY_VALUE_MAX];
    property_get("persist.sys.adb.shell", value, "");
    if (value[0] != '\0' && stat(value, &st) == 0) {
        shell_command = value;
    }
    else if (stat(ALTERNATE_SHELL_COMMAND, &st) == 0) {
        shell_command = ALTERNATE_SHELL_COMMAND;
    }
    else {
        shell_command = SHELL_COMMAND;
    }

    switch (mode) {
    case SUBPROC_PTY:
        ret_fd = create_subproc_pty(shell_command, arg0, arg1, &pid);
        break;
    case SUBPROC_RAW:
        ret_fd = create_subproc_raw(shell_command, arg0, arg1, &pid);
        break;
    default:
        fprintf(stderr, "invalid subproc_mode %d\n", mode);
        return -1;
    }
    D("create_subproc ret_fd=%d pid=%d\n", ret_fd, pid);

    sti = malloc(sizeof(stinfo));
    if(sti == 0) fatal("cannot allocate stinfo");
    sti->func = subproc_waiter_service;
    sti->cookie = (void*) (uintptr_t) pid;
    sti->fd = ret_fd;

    if (adb_thread_create(&t, service_bootstrap_func, sti)) {
        free(sti);
        adb_close(ret_fd);
        fprintf(stderr, "cannot create service thread\n");
        return -1;
    }

    D("service thread started, fd=%d pid=%d\n", ret_fd, pid);
    return ret_fd;
}
예제 #3
0
static int create_subproc_thread(const char *name, const subproc_mode mode)
{
    adb_thread_t t;
    int ret_fd;
    pid_t pid = -1;

    long mem_free = 0;
    read_meminfo(&mem_free);
    XLOGW("read_meminfo() mem_free=%ld\n", mem_free);

    const char *arg0, *arg1;
    if (name == 0 || *name == 0) {
        arg0 = "-"; arg1 = 0;
    } else {
        arg0 = "-c"; arg1 = name;
    }

    switch (mode) {
    case SUBPROC_PTY:
        ret_fd = create_subproc_pty(SHELL_COMMAND, arg0, arg1, &pid);
        break;
    case SUBPROC_RAW:
        ret_fd = create_subproc_raw(SHELL_COMMAND, arg0, arg1, &pid);
        break;
    default:
        fprintf(stderr, "invalid subproc_mode %d\n", mode);
        return -1;
    }
    D("create_subproc ret_fd=%d pid=%d\n", ret_fd, pid);
    XLOGW("create_subproc ret_fd=%d pid=%d\n", ret_fd, pid);

    if ( sti == 0 )
    {
    sti = malloc(sizeof(stinfo));
    if(sti == 0) fatal("cannot allocate stinfo");
    sti->func = subproc_waiter_service;
    sti->cookie = (void*) (uintptr_t) pid;
    sti->fd = ret_fd;

    if (adb_thread_create(&t, service_bootstrap_func, sti)) {
        XLOGW("adb_thread_create() errno=%d\n", errno);
        free(sti);
        adb_close(ret_fd);
        fprintf(stderr, "cannot create service thread\n");
        return -1;
    }
    }

    D("service thread started, fd=%d pid=%d\n", ret_fd, pid);
    return ret_fd;
}