Merge "Lose adb.c and sockets.c to libadb."
diff --git a/adb/adb.c b/adb/adb.c
index f15902b..d1f05e4 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -542,14 +542,6 @@
     put_apacket(p);
 }
 
-#if defined(_WIN32)
-static BOOL WINAPI ctrlc_handler(DWORD type)
-{
-    exit(STATUS_CONTROL_C_EXIT);
-    return TRUE;
-}
-#endif
-
 #if ADB_HOST
 
 int launch_server(int server_port)
diff --git a/adb/adb_listeners.c b/adb/adb_listeners.c
index e9d3c22..76a03eb 100644
--- a/adb/adb_listeners.c
+++ b/adb/adb_listeners.c
@@ -16,8 +16,6 @@
 
 #include "adb_listeners.h"
 
-#include <sys/socket.h>
-
 #include "sysdeps.h"
 
 int gListenAll = 0; /* Not static because it is used in commandline.c. */
diff --git a/adb/adb_main.c b/adb/adb_main.c
index 72168ec..02acae2 100644
--- a/adb/adb_main.c
+++ b/adb/adb_main.c
@@ -20,7 +20,6 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/prctl.h>
 
 #include "adb.h"
 #include "adb_auth.h"
@@ -29,6 +28,7 @@
 
 #if !ADB_HOST
 #include <getopt.h>
+#include <sys/prctl.h>
 
 #include "cutils/properties.h"
 #include "private/android_filesystem_config.h"
@@ -42,6 +42,14 @@
     usb_cleanup();
 }
 
+#if defined(_WIN32)
+static BOOL WINAPI ctrlc_handler(DWORD type)
+{
+    exit(STATUS_CONTROL_C_EXIT);
+    return TRUE;
+}
+#endif
+
 #if ADB_HOST
 #ifdef WORKAROUND_BUG6558362
 #include <sched.h>
@@ -107,14 +115,25 @@
         return false;
     }
 
+    // The properties that affect `adb root` and `adb unroot` are ro.secure and
+    // ro.debuggable. In this context the names don't make the expected behavior
+    // particularly obvious.
+    //
+    // ro.debuggable:
+    //   Allowed to become root, but not necessarily the default. Set to 1 on
+    //   eng and userdebug builds.
+    //
+    // ro.secure:
+    //   Drop privileges by default. Set to 1 on userdebug and user builds.
     property_get("ro.secure", value, "1");
     bool ro_secure = (strcmp(value, "1") == 0);
 
+    property_get("ro.debuggable", value, "");
+    bool ro_debuggable = (strcmp(value, "1") == 0);
+
     // Drop privileges if ro.secure is set...
     bool drop = ro_secure;
 
-    property_get("ro.debuggable", value, "");
-    bool ro_debuggable = (strcmp(value, "1") == 0);
     property_get("service.adb.root", value, "");
     bool adb_root = (strcmp(value, "1") == 0);
     bool adb_unroot = (strcmp(value, "0") == 0);