static int jdwp_control_init( JdwpControl* control, const char* sockname, int socknamelen ) { struct sockaddr_un addr; socklen_t addrlen; int s; int maxpath = sizeof(addr.sun_path); int pathlen = socknamelen; if (pathlen >= maxpath) { D( "vm debug control socket name too long (%d extra chars)\n", pathlen+1-maxpath ); return -1; } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; memcpy(addr.sun_path, sockname, socknamelen); s = socket( AF_UNIX, SOCK_STREAM, 0 ); if (s < 0) { D( "could not create vm debug control socket. %d: %s\n", errno, strerror(errno)); return -1; } addrlen = (pathlen + sizeof(addr.sun_family)); if (bind(s, (struct sockaddr*)&addr, addrlen) < 0) { D( "could not bind vm debug control socket: %d: %s\n", errno, strerror(errno) ); adb_close(s); return -1; } if ( listen(s, 4) < 0 ) { D("listen failed in jdwp control socket: %d: %s\n", errno, strerror(errno)); adb_close(s); return -1; } control->listen_socket = s; control->fde = fdevent_create(s, jdwp_control_event, control); if (control->fde == NULL) { D( "could not create fdevent for jdwp control socket\n" ); adb_close(s); return -1; } /* only wait for incoming connections */ fdevent_add(control->fde, FDE_READ); close_on_exec(s); D("jdwp control socket started (%d)\n", control->listen_socket); return 0; }
explicit JdwpProcess(int socket) { this->socket = socket; this->fde = fdevent_create(socket, jdwp_process_event, this); if (!this->fde) { LOG(FATAL) << "could not create fdevent for new JDWP process"; } /* start by waiting for the PID */ fdevent_add(this->fde, FDE_READ); }
void fdevent_subproc_setup() { int s[2]; if(adb_socketpair(s)) { FATAL("cannot create shell-exit socket-pair\n"); } SHELL_EXIT_NOTIFY_FD = s[0]; fdevent *fde; fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL); if(!fde) FATAL("cannot create fdevent for shell-exit handler\n"); fdevent_add(fde, FDE_READ); }
void fdevent_subproc_setup() { int s[2]; if(adb_socketpair(s)) { PLOG(FATAL) << "cannot create shell-exit socket-pair"; } D("fdevent_subproc: socket pair (%d, %d)", s[0], s[1]); SHELL_EXIT_NOTIFY_FD = s[0]; fdevent *fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL); CHECK(fde != nullptr) << "cannot create fdevent for shell-exit handler"; fdevent_add(fde, FDE_READ); }
void adbd_auth_init(void) { int fd = android_get_control_socket("adbd"); if (fd == -1) { PLOG(ERROR) << "Failed to get adbd socket"; return; } if (listen(fd, 4) == -1) { PLOG(ERROR) << "Failed to listen on '" << fd << "'"; return; } listener_fde = fdevent_create(fd, adbd_auth_listener, nullptr); fdevent_add(listener_fde, FDE_READ); }
void fdevent_subproc_setup() { int s[2]; if (adb_socketpair(s)) { FATAL("cannot create shell-exit socket-pair"); } ADB_LOGD(ADB_FDEV, "socketpair: (%d,%d)", s[0], s[1]); SHELL_EXIT_NOTIFY_FD = s[0]; fdevent *fde; fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL); if (!fde) { FATAL("cannot create fdevent for shell-exit handler"); } fdevent_add(fde, FDE_READ); }
void fdevent_subproc_setup() { printf("function = %s, file = %s, line = %u \n", __FUNCTION__, __FILE__, __LINE__); int s[2]; if(adb_socketpair(s)) { FATAL("cannot create shell-exit socket-pair\n"); } SHELL_EXIT_NOTIFY_FD = s[0]; fdevent *fde; printf("function = %s, file = %s, line = %u before fdevent_create\n", __FUNCTION__, __FILE__, __LINE__); fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL); if(!fde) FATAL("cannot create fdevent for shell-exit handler\n"); printf("function = %s, file = %s, line = %u before fdevent_add\n", __FUNCTION__, __FILE__, __LINE__); fdevent_add(fde, FDE_READ); }
static void adbd_auth_listener(int fd, unsigned events, void* data) { int s = adb_socket_accept(fd, nullptr, nullptr); if (s < 0) { PLOG(ERROR) << "Failed to accept"; return; } if (framework_fd >= 0) { LOG(WARNING) << "adb received framework auth socket connection again"; framework_disconnected(); } framework_fd = s; framework_fde = fdevent_create(framework_fd, adbd_auth_event, nullptr); fdevent_add(framework_fde, FDE_READ); if (needs_retry) { needs_retry = false; send_auth_request(usb_transport); } }
static JdwpProcess* jdwp_process_alloc( int socket ) { JdwpProcess* proc = reinterpret_cast<JdwpProcess*>( calloc(1, sizeof(*proc))); if (proc == NULL) { D("not enough memory to create new JDWP process\n"); return NULL; } proc->socket = socket; proc->pid = -1; proc->next = proc; proc->prev = proc; proc->fde = fdevent_create( socket, jdwp_process_event, proc ); if (proc->fde == NULL) { D("could not create fdevent for new JDWP process\n" ); free(proc); return NULL; } proc->fde->state |= FDE_DONT_CLOSE; proc->in_len = 0; proc->out_count = 0; /* append to list */ proc->next = &_jdwp_list; proc->prev = proc->next->prev; proc->prev->next = proc; proc->next->prev = proc; /* start by waiting for the PID */ fdevent_add(proc->fde, FDE_READ); return proc; }