adb: Fix command-line parser.

This fixes the command-line parser to accept both "daemon server"
and "server nodaemon". Before the patch, the second string would
ignore the "nodaemon" flag.

Fixes b/2191598

Change-Id: Ie922b3e7bf57a6e334fc448cec33fb340ca6abc4
diff --git a/commandline.c b/commandline.c
index 3600e5a..5ed1b52 100644
--- a/commandline.c
+++ b/commandline.c
@@ -683,6 +683,7 @@
     char buf[4096];
     int no_daemon = 0;
     int is_daemon = 0;
+    int is_server = 0;
     int persist = 0;
     int r;
     int quote;
@@ -719,7 +720,9 @@
 
     /* modifiers and flags */
     while(argc > 0) {
-        if(!strcmp(argv[0],"nodaemon")) {
+        if(!strcmp(argv[0],"server")) {
+            is_server = 1;
+        } else if(!strcmp(argv[0],"nodaemon")) {
             no_daemon = 1;
         } else if (!strcmp(argv[0], "fork-server")) {
             /* this is a special flag used only when the ADB client launches the ADB Server */
@@ -766,7 +769,7 @@
     adb_set_transport(ttype, serial);
     adb_set_tcp_specifics(server_port);
 
-    if ((argc > 0) && (!strcmp(argv[0],"server"))) {
+    if (is_server) {
         if (no_daemon || is_daemon) {
             r = adb_main(is_daemon, server_port);
         } else {