Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From d855f042ca09a358cebe2d3c1d29d512afd7ebb8 Mon Sep 17 00:00:00 2001 |
| 2 | From: Hilko Bengen <bengen@debian.org> |
| 3 | Date: Wed, 7 Sep 2016 12:58:47 +0300 |
| 4 | Subject: [PATCH] adb: Use local sockets where appropriate |
| 5 | |
| 6 | Upstream-Status: Inappropriate |
| 7 | --- |
| 8 | adb/adb.c | 6 +++++- |
| 9 | adb/adb_client.c | 5 +++-- |
| 10 | adb/transport_local.c | 3 ++- |
| 11 | 3 files changed, 10 insertions(+), 4 deletions(-) |
| 12 | |
| 13 | diff --git a/adb/adb.c b/adb/adb.c |
| 14 | index 10a1e0da26..027edd9359 100644 |
| 15 | --- a/adb/adb.c |
| 16 | +++ b/adb/adb.c |
| 17 | @@ -1230,7 +1230,11 @@ int launch_server(int server_port) |
| 18 | */ |
| 19 | void build_local_name(char* target_str, size_t target_size, int server_port) |
| 20 | { |
| 21 | - snprintf(target_str, target_size, "tcp:%d", server_port); |
| 22 | + if (gListenAll > 0) { |
| 23 | + snprintf(target_str, target_size, "tcp:%d", server_port); |
| 24 | + } else { |
| 25 | + snprintf(target_str, target_size, "local:%d", server_port); |
| 26 | + } |
| 27 | } |
| 28 | |
| 29 | #if !ADB_HOST |
| 30 | diff --git a/adb/adb_client.c b/adb/adb_client.c |
| 31 | index eb1720d22c..a383faefe3 100644 |
| 32 | --- a/adb/adb_client.c |
| 33 | +++ b/adb/adb_client.c |
| 34 | @@ -185,12 +185,12 @@ int _adb_connect(const char *service) |
| 35 | strcpy(__adb_error, "service name too long"); |
| 36 | return -1; |
| 37 | } |
| 38 | - snprintf(tmp, sizeof tmp, "%04x", len); |
| 39 | + snprintf(tmp, sizeof tmp, "%d", __adb_server_port); |
| 40 | |
| 41 | if (__adb_server_name) |
| 42 | fd = socket_network_client(__adb_server_name, __adb_server_port, SOCK_STREAM); |
| 43 | else |
| 44 | - fd = socket_loopback_client(__adb_server_port, SOCK_STREAM); |
| 45 | + fd = socket_local_client(tmp, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); |
| 46 | |
| 47 | if(fd < 0) { |
| 48 | strcpy(__adb_error, "cannot connect to daemon"); |
| 49 | @@ -201,6 +201,7 @@ int _adb_connect(const char *service) |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | + snprintf(tmp, sizeof tmp, "%04x", len); |
| 54 | if(writex(fd, tmp, 4) || writex(fd, service, len)) { |
| 55 | strcpy(__adb_error, "write failure during connection"); |
| 56 | adb_close(fd); |
| 57 | diff --git a/adb/transport_local.c b/adb/transport_local.c |
| 58 | index 948cc15812..71582a8c88 100644 |
| 59 | --- a/adb/transport_local.c |
| 60 | +++ b/adb/transport_local.c |
| 61 | @@ -121,7 +121,8 @@ int local_connect_arbitrary_ports(int console_port, int adb_port) |
| 62 | } |
| 63 | #endif |
| 64 | if (fd < 0) { |
| 65 | - fd = socket_loopback_client(adb_port, SOCK_STREAM); |
| 66 | + snprintf(buf, sizeof buf, "%d", adb_port); |
| 67 | + fd = socket_local_client(buf, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); |
| 68 | } |
| 69 | |
| 70 | if (fd >= 0) { |