diff options
Diffstat (limited to 'adb/commandline.c')
-rw-r--r-- | adb/commandline.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/adb/commandline.c b/adb/commandline.c index 5f42203..8566066 100644 --- a/adb/commandline.c +++ b/adb/commandline.c @@ -762,6 +762,7 @@ int adb_commandline(int argc, char **argv) int quote; transport_type ttype = kTransportAny; char* serial = NULL; + char* server_port_str = NULL; /* If defined, this should be an absolute path to * the directory containing all of the various system images @@ -777,7 +778,20 @@ int adb_commandline(int argc, char **argv) serial = getenv("ANDROID_SERIAL"); - /* modifiers and flags */ + /* Validate and assign the server port */ + server_port_str = getenv("ANDROID_ADB_SERVER_PORT"); + int server_port = DEFAULT_ADB_PORT; + if (server_port_str && strlen(server_port_str) > 0) { + server_port = (int) strtol(server_port_str, NULL, 0); + if (server_port <= 0) { + fprintf(stderr, + "adb: Env var ANDROID_ADB_SERVER_PORT must be a positive number. Got \"%s\"\n", + server_port_str); + return usage(); + } + } + + /* modifiers and flags */ while(argc > 0) { if(!strcmp(argv[0],"nodaemon")) { no_daemon = 1; @@ -806,7 +820,7 @@ int adb_commandline(int argc, char **argv) if (isdigit(argv[0][2])) { serial = argv[0] + 2; } else { - if(argc < 2) return usage(); + if(argc < 2 || argv[0][2] != '\0') return usage(); serial = argv[1]; argc--; argv++; @@ -824,12 +838,13 @@ int adb_commandline(int argc, char **argv) } adb_set_transport(ttype, serial); + adb_set_tcp_specifics(server_port); if ((argc > 0) && (!strcmp(argv[0],"server"))) { if (no_daemon || is_daemon) { - r = adb_main(is_daemon); + r = adb_main(is_daemon, server_port); } else { - r = launch_server(); + r = launch_server(server_port); } if(r) { fprintf(stderr,"* could not start server *\n"); @@ -894,10 +909,10 @@ top: /* quote empty strings and strings with spaces */ quote = (**argv == 0 || strchr(*argv, ' ')); if (quote) - strcat(buf, "\""); + strcat(buf, "\""); strcat(buf, *argv++); if (quote) - strcat(buf, "\""); + strcat(buf, "\""); } for(;;) { |