summaryrefslogtreecommitdiffstats
path: root/adb
diff options
context:
space:
mode:
Diffstat (limited to 'adb')
-rw-r--r--adb/adb.c6
-rw-r--r--adb/jdwp_service.c27
-rw-r--r--adb/sockets.c14
-rw-r--r--adb/usb_vendors.c5
4 files changed, 42 insertions, 10 deletions
diff --git a/adb/adb.c b/adb/adb.c
index d9f96df..0da7218 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -302,8 +302,10 @@ void handle_packet(apacket *p, atransport *t)
{
asocket *s;
- D("handle_packet() %d\n", p->msg.command);
-
+ D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0],
+ ((char*) (&(p->msg.command)))[1],
+ ((char*) (&(p->msg.command)))[2],
+ ((char*) (&(p->msg.command)))[3]);
print_packet("recv", p);
switch(p->msg.command){
diff --git a/adb/jdwp_service.c b/adb/jdwp_service.c
index 0c26f7b..296f718 100644
--- a/adb/jdwp_service.c
+++ b/adb/jdwp_service.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
/* here's how these things work.
@@ -320,6 +321,7 @@ jdwp_process_event( int socket, unsigned events, void* _proc )
struct iovec iov;
char dummy = '!';
char buffer[sizeof(struct cmsghdr) + sizeof(int)];
+ int flags;
iov.iov_base = &dummy;
iov.iov_len = 1;
@@ -337,10 +339,27 @@ jdwp_process_event( int socket, unsigned events, void* _proc )
cmsg->cmsg_type = SCM_RIGHTS;
((int*)CMSG_DATA(cmsg))[0] = fd;
+ flags = fcntl(proc->socket,F_GETFL,0);
+
+ if (flags == -1) {
+ D("failed to get cntl flags for socket %d: %s\n",
+ proc->pid, strerror(errno));
+ goto CloseProcess;
+
+ }
+
+ if (fcntl(proc->socket, F_SETFL, flags & ~O_NONBLOCK) == -1) {
+ D("failed to remove O_NONBLOCK flag for socket %d: %s\n",
+ proc->pid, strerror(errno));
+ goto CloseProcess;
+ }
+
for (;;) {
ret = sendmsg(proc->socket, &msg, 0);
- if (ret >= 0)
+ if (ret >= 0) {
+ adb_close(fd);
break;
+ }
if (errno == EINTR)
continue;
D("sending new file descriptor to JDWP %d failed: %s\n",
@@ -354,6 +373,12 @@ jdwp_process_event( int socket, unsigned events, void* _proc )
for (n = 1; n < proc->out_count; n++)
proc->out_fds[n-1] = proc->out_fds[n];
+ if (fcntl(proc->socket, F_SETFL, flags) == -1) {
+ D("failed to set O_NONBLOCK flag for socket %d: %s\n",
+ proc->pid, strerror(errno));
+ goto CloseProcess;
+ }
+
if (--proc->out_count == 0)
fdevent_del( proc->fde, FDE_WRITE );
}
diff --git a/adb/sockets.c b/adb/sockets.c
index 9f1b598..43925e4 100644
--- a/adb/sockets.c
+++ b/adb/sockets.c
@@ -65,8 +65,11 @@ asocket *find_local_socket(unsigned id)
asocket *result = NULL;
adb_mutex_lock(&socket_list_lock);
- for(s = local_socket_list.next; s != &local_socket_list && !result; s = s->next) {
- if(s->id == id) result = s;
+ for (s = local_socket_list.next; s != &local_socket_list; s = s->next) {
+ if (s->id == id) {
+ result = s;
+ break;
+ }
}
adb_mutex_unlock(&socket_list_lock);
@@ -366,7 +369,7 @@ static void local_socket_event_func(int fd, unsigned ev, void *_s)
asocket *create_local_socket(int fd)
{
asocket *s = calloc(1, sizeof(asocket));
- if(s == 0) fatal("cannot allocate socket");
+ if (s == NULL) fatal("cannot allocate socket");
install_local_socket(s);
s->fd = fd;
s->enqueue = local_socket_enqueue;
@@ -482,7 +485,7 @@ asocket *create_remote_socket(unsigned id, atransport *t)
asocket *s = calloc(1, sizeof(aremotesocket));
adisconnect* dis = &((aremotesocket*)s)->disconnect;
- if(s == 0) fatal("cannot allocate socket");
+ if (s == NULL) fatal("cannot allocate socket");
s->id = id;
s->enqueue = remote_socket_enqueue;
s->ready = remote_socket_ready;
@@ -761,8 +764,7 @@ asocket *create_smart_socket(void (*action_cb)(asocket *s, const char *act))
{
D("Creating smart socket \n");
asocket *s = calloc(1, sizeof(asocket));
- if(s == 0) fatal("cannot allocate socket");
- s->id = 0;
+ if (s == NULL) fatal("cannot allocate socket");
s->enqueue = smart_socket_enqueue;
s->ready = smart_socket_ready;
s->close = smart_socket_close;
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
index ebac7f5..bebac2d 100644
--- a/adb/usb_vendors.c
+++ b/adb/usb_vendors.c
@@ -69,6 +69,8 @@
#define VENDOR_ID_PANTECH 0x10A9
// Qualcomm's USB Vendor ID
#define VENDOR_ID_QUALCOMM 0x05c6
+// On-The-Go-Video's USB Vendor ID
+#define VENDOR_ID_OTGV 0x2257
// NEC's USB Vendor ID
#define VENDOR_ID_NEC 0x0409
// Panasonic Mobile Communication's USB Vendor ID
@@ -100,6 +102,7 @@ int builtInVendorIds[] = {
VENDOR_ID_KYOCERA,
VENDOR_ID_PANTECH,
VENDOR_ID_QUALCOMM,
+ VENDOR_ID_OTGV,
VENDOR_ID_NEC,
VENDOR_ID_PMC,
VENDOR_ID_TOSHIBA,
@@ -166,7 +169,7 @@ void usb_vendors_init(void)
/* builds the path to the adb vendor id file. returns 0 if success */
int build_path(char* buff, size_t len, const char* format, const char* home)
{
- if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= len) {
+ if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) {
return 1;
}