Loading adb/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ ADB_COMMON_darwin_CFLAGS := \ # CreateFileW(path_wide.c_str()); ADB_COMMON_windows_CFLAGS := \ -DUNICODE=1 -D_UNICODE=1 \ -D_POSIX_SOURCE # libadb # ========================================================= Loading adb/adb.h +0 −4 Original line number Diff line number Diff line Loading @@ -196,10 +196,6 @@ ConnectionState connection_state(atransport* t); extern const char* adb_device_banner; #if !ADB_HOST extern int SHELL_EXIT_NOTIFY_FD; #endif // !ADB_HOST #define CHUNK_SIZE (64 * 1024) #if !ADB_HOST Loading adb/adb_listeners.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include "socket_spec.h" #include "sysdeps.h" #include "sysdeps/memory.h" #include "transport.h" // A listener is an entity which binds to a local port and, upon receiving a connection on that Loading Loading @@ -203,7 +204,7 @@ InstallStatus install_listener(const std::string& local_name, const char* connec } } std::unique_ptr<alistener> listener(new alistener(local_name, connect_to)); auto listener = std::make_unique<alistener>(local_name, connect_to); int resolved = 0; listener->fd = socket_spec_listen(listener->local_name, error, &resolved); Loading adb/commandline.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ #include "services.h" #include "shell_service.h" #include "sysdeps/chrono.h" #include "sysdeps/memory.h" static int install_app(int argc, const char** argv); static int install_multiple_app(int argc, const char** argv); Loading Loading @@ -263,7 +264,7 @@ int read_and_dump(int fd, bool use_shell_protocol = false, char raw_buffer[BUFSIZ]; char* buffer_ptr = raw_buffer; if (use_shell_protocol) { protocol.reset(new ShellProtocol(fd)); protocol = std::make_unique<ShellProtocol>(fd); if (!protocol) { LOG(ERROR) << "failed to allocate memory for ShellProtocol object"; return 1; Loading Loading @@ -630,7 +631,7 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg, args->raw_stdin = raw_stdin; args->escape_char = escape_char; if (use_shell_protocol) { args->protocol.reset(new ShellProtocol(args->write_fd)); args->protocol = std::make_unique<ShellProtocol>(args->write_fd); } if (raw_stdin) stdin_raw_init(); Loading adb/fdevent.cpp +10 −77 Original line number Diff line number Diff line Loading @@ -42,13 +42,6 @@ #include "adb_unique_fd.h" #include "adb_utils.h" #if !ADB_HOST // This socket is used when a subproc shell service exists. // It wakes up the fdevent_loop() and cause the correct handling // of the shell's pseudo-tty master. I.e. force close it. int SHELL_EXIT_NOTIFY_FD = -1; #endif // !ADB_HOST #define FDE_EVENTMASK 0x00ff #define FDE_STATEMASK 0xff00 Loading Loading @@ -294,72 +287,6 @@ static void fdevent_call_fdfunc(fdevent* fde) { fde->func(fde->fd, events, fde->arg); } #if !ADB_HOST #include <sys/ioctl.h> static void fdevent_subproc_event_func(int fd, unsigned ev, void* /* userdata */) { D("subproc handling on fd = %d, ev = %x", fd, ev); CHECK_GE(fd, 0); if (ev & FDE_READ) { int subproc_fd; if(!ReadFdExactly(fd, &subproc_fd, sizeof(subproc_fd))) { LOG(FATAL) << "Failed to read the subproc's fd from " << fd; } auto it = g_poll_node_map.find(subproc_fd); if (it == g_poll_node_map.end()) { D("subproc_fd %d cleared from fd_table", subproc_fd); adb_close(subproc_fd); return; } fdevent* subproc_fde = it->second.fde; if(subproc_fde->fd != subproc_fd) { // Already reallocated? LOG(FATAL) << "subproc_fd(" << subproc_fd << ") != subproc_fde->fd(" << subproc_fde->fd << ")"; return; } subproc_fde->force_eof = 1; int rcount = 0; ioctl(subproc_fd, FIONREAD, &rcount); D("subproc with fd %d has rcount=%d, err=%d", subproc_fd, rcount, errno); if (rcount != 0) { // If there is data left, it will show up in the select(). // This works because there is no other thread reading that // data when in this fd_func(). return; } D("subproc_fde %s", dump_fde(subproc_fde).c_str()); subproc_fde->events |= FDE_READ; if(subproc_fde->state & FDE_PENDING) { return; } subproc_fde->state |= FDE_PENDING; fdevent_call_fdfunc(subproc_fde); } } static 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); } #endif // !ADB_HOST static void fdevent_run_flush() EXCLUDES(run_queue_mutex) { // We need to be careful around reentrancy here, since a function we call can queue up another // function. Loading Loading @@ -400,6 +327,10 @@ static void fdevent_run_setup() { PLOG(FATAL) << "failed to create run queue notify socketpair"; } if (!set_file_block_mode(s[0], false) || !set_file_block_mode(s[1], false)) { PLOG(FATAL) << "failed to make run queue notify socket nonblocking"; } run_queue_notify_fd.reset(s[0]); fdevent* fde = fdevent_create(s[1], fdevent_run_func, nullptr); CHECK(fde != nullptr); Loading @@ -416,7 +347,12 @@ void fdevent_run_on_main_thread(std::function<void()> fn) { // run_queue_notify_fd could still be -1 if we're called before fdevent has finished setting up. // In that case, rely on the setup code to flush the queue without a notification being needed. if (run_queue_notify_fd != -1) { if (adb_write(run_queue_notify_fd.get(), "", 1) != 1) { int rc = adb_write(run_queue_notify_fd.get(), "", 1); // It's possible that we get EAGAIN here, if lots of notifications came in while handling. if (rc == 0) { PLOG(FATAL) << "run queue notify fd was closed?"; } else if (rc == -1 && errno != EAGAIN) { PLOG(FATAL) << "failed to write to run queue notify fd"; } } Loading @@ -424,9 +360,6 @@ void fdevent_run_on_main_thread(std::function<void()> fn) { void fdevent_loop() { set_main_thread(); #if !ADB_HOST fdevent_subproc_setup(); #endif // !ADB_HOST fdevent_run_setup(); while (true) { Loading Loading
adb/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ ADB_COMMON_darwin_CFLAGS := \ # CreateFileW(path_wide.c_str()); ADB_COMMON_windows_CFLAGS := \ -DUNICODE=1 -D_UNICODE=1 \ -D_POSIX_SOURCE # libadb # ========================================================= Loading
adb/adb.h +0 −4 Original line number Diff line number Diff line Loading @@ -196,10 +196,6 @@ ConnectionState connection_state(atransport* t); extern const char* adb_device_banner; #if !ADB_HOST extern int SHELL_EXIT_NOTIFY_FD; #endif // !ADB_HOST #define CHUNK_SIZE (64 * 1024) #if !ADB_HOST Loading
adb/adb_listeners.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include "socket_spec.h" #include "sysdeps.h" #include "sysdeps/memory.h" #include "transport.h" // A listener is an entity which binds to a local port and, upon receiving a connection on that Loading Loading @@ -203,7 +204,7 @@ InstallStatus install_listener(const std::string& local_name, const char* connec } } std::unique_ptr<alistener> listener(new alistener(local_name, connect_to)); auto listener = std::make_unique<alistener>(local_name, connect_to); int resolved = 0; listener->fd = socket_spec_listen(listener->local_name, error, &resolved); Loading
adb/commandline.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ #include "services.h" #include "shell_service.h" #include "sysdeps/chrono.h" #include "sysdeps/memory.h" static int install_app(int argc, const char** argv); static int install_multiple_app(int argc, const char** argv); Loading Loading @@ -263,7 +264,7 @@ int read_and_dump(int fd, bool use_shell_protocol = false, char raw_buffer[BUFSIZ]; char* buffer_ptr = raw_buffer; if (use_shell_protocol) { protocol.reset(new ShellProtocol(fd)); protocol = std::make_unique<ShellProtocol>(fd); if (!protocol) { LOG(ERROR) << "failed to allocate memory for ShellProtocol object"; return 1; Loading Loading @@ -630,7 +631,7 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg, args->raw_stdin = raw_stdin; args->escape_char = escape_char; if (use_shell_protocol) { args->protocol.reset(new ShellProtocol(args->write_fd)); args->protocol = std::make_unique<ShellProtocol>(args->write_fd); } if (raw_stdin) stdin_raw_init(); Loading
adb/fdevent.cpp +10 −77 Original line number Diff line number Diff line Loading @@ -42,13 +42,6 @@ #include "adb_unique_fd.h" #include "adb_utils.h" #if !ADB_HOST // This socket is used when a subproc shell service exists. // It wakes up the fdevent_loop() and cause the correct handling // of the shell's pseudo-tty master. I.e. force close it. int SHELL_EXIT_NOTIFY_FD = -1; #endif // !ADB_HOST #define FDE_EVENTMASK 0x00ff #define FDE_STATEMASK 0xff00 Loading Loading @@ -294,72 +287,6 @@ static void fdevent_call_fdfunc(fdevent* fde) { fde->func(fde->fd, events, fde->arg); } #if !ADB_HOST #include <sys/ioctl.h> static void fdevent_subproc_event_func(int fd, unsigned ev, void* /* userdata */) { D("subproc handling on fd = %d, ev = %x", fd, ev); CHECK_GE(fd, 0); if (ev & FDE_READ) { int subproc_fd; if(!ReadFdExactly(fd, &subproc_fd, sizeof(subproc_fd))) { LOG(FATAL) << "Failed to read the subproc's fd from " << fd; } auto it = g_poll_node_map.find(subproc_fd); if (it == g_poll_node_map.end()) { D("subproc_fd %d cleared from fd_table", subproc_fd); adb_close(subproc_fd); return; } fdevent* subproc_fde = it->second.fde; if(subproc_fde->fd != subproc_fd) { // Already reallocated? LOG(FATAL) << "subproc_fd(" << subproc_fd << ") != subproc_fde->fd(" << subproc_fde->fd << ")"; return; } subproc_fde->force_eof = 1; int rcount = 0; ioctl(subproc_fd, FIONREAD, &rcount); D("subproc with fd %d has rcount=%d, err=%d", subproc_fd, rcount, errno); if (rcount != 0) { // If there is data left, it will show up in the select(). // This works because there is no other thread reading that // data when in this fd_func(). return; } D("subproc_fde %s", dump_fde(subproc_fde).c_str()); subproc_fde->events |= FDE_READ; if(subproc_fde->state & FDE_PENDING) { return; } subproc_fde->state |= FDE_PENDING; fdevent_call_fdfunc(subproc_fde); } } static 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); } #endif // !ADB_HOST static void fdevent_run_flush() EXCLUDES(run_queue_mutex) { // We need to be careful around reentrancy here, since a function we call can queue up another // function. Loading Loading @@ -400,6 +327,10 @@ static void fdevent_run_setup() { PLOG(FATAL) << "failed to create run queue notify socketpair"; } if (!set_file_block_mode(s[0], false) || !set_file_block_mode(s[1], false)) { PLOG(FATAL) << "failed to make run queue notify socket nonblocking"; } run_queue_notify_fd.reset(s[0]); fdevent* fde = fdevent_create(s[1], fdevent_run_func, nullptr); CHECK(fde != nullptr); Loading @@ -416,7 +347,12 @@ void fdevent_run_on_main_thread(std::function<void()> fn) { // run_queue_notify_fd could still be -1 if we're called before fdevent has finished setting up. // In that case, rely on the setup code to flush the queue without a notification being needed. if (run_queue_notify_fd != -1) { if (adb_write(run_queue_notify_fd.get(), "", 1) != 1) { int rc = adb_write(run_queue_notify_fd.get(), "", 1); // It's possible that we get EAGAIN here, if lots of notifications came in while handling. if (rc == 0) { PLOG(FATAL) << "run queue notify fd was closed?"; } else if (rc == -1 && errno != EAGAIN) { PLOG(FATAL) << "failed to write to run queue notify fd"; } } Loading @@ -424,9 +360,6 @@ void fdevent_run_on_main_thread(std::function<void()> fn) { void fdevent_loop() { set_main_thread(); #if !ADB_HOST fdevent_subproc_setup(); #endif // !ADB_HOST fdevent_run_setup(); while (true) { Loading