Split adb_main.cpp into client and daemon.

The name "client" is somewhat misleading as it also contains the host
side adb server, but it's a part of the client binary.

Change-Id: I128b7bab213e330eb21b5010cd1fec5f7a62c8af
diff --git a/adb/usb_osx.cpp b/adb/usb_osx.cpp
index 0d0b3ad..af65130 100644
--- a/adb/usb_osx.cpp
+++ b/adb/usb_osx.cpp
@@ -401,11 +401,18 @@
     return NULL;
 }
 
+static void usb_cleanup() {
+    DBG("usb_cleanup\n");
+    close_usb_devices();
+    if (currentRunLoop)
+        CFRunLoopStop(currentRunLoop);
+}
 
-static int initialized = 0;
 void usb_init() {
-    if (!initialized)
-    {
+    static bool initialized = false;
+    if (!initialized) {
+        atexit(usb_cleanup);
+
         adb_mutex_init(&start_lock, NULL);
         adb_cond_init(&start_cond, NULL);
 
@@ -421,18 +428,10 @@
         adb_mutex_destroy(&start_lock);
         adb_cond_destroy(&start_cond);
 
-        initialized = 1;
+        initialized = true;
     }
 }
 
-void usb_cleanup()
-{
-    DBG("usb_cleanup\n");
-    close_usb_devices();
-    if (currentRunLoop)
-        CFRunLoopStop(currentRunLoop);
-}
-
 int usb_write(usb_handle *handle, const void *buf, int len)
 {
     IOReturn    result;