Merge "Fix entry handling for 0 length entries."
diff --git a/adb/adb.c b/adb/adb.c
index 41270f9..665e958 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -39,6 +39,8 @@
 #include <sys/capability.h>
 #include <linux/prctl.h>
 #include <sys/mount.h>
+#include <getopt.h>
+#include <selinux/selinux.h>
 #else
 #include "usb_vendors.h"
 #endif
@@ -54,6 +56,7 @@
 
 #if !ADB_HOST
 static const char *adb_device_banner = "device";
+static const char *root_seclabel = NULL;
 #endif
 
 void fatal(const char *fmt, ...)
@@ -1356,6 +1359,12 @@
         D("Local port disabled\n");
     } else {
         char local_name[30];
+        if ((root_seclabel != NULL) && (is_selinux_enabled() > 0)) {
+            // b/12587913: fix setcon to allow const pointers
+            if (setcon((char *)root_seclabel) < 0) {
+                exit(1);
+            }
+        }
         build_local_name(local_name, sizeof(local_name), server_port);
         if(install_listener(local_name, "*smartsocket*", NULL, 0)) {
             exit(1);
@@ -1642,10 +1651,6 @@
     return -1;
 }
 
-#if !ADB_HOST
-int recovery_mode = 0;
-#endif
-
 int main(int argc, char **argv)
 {
 #if ADB_HOST
@@ -1657,9 +1662,26 @@
     /* If adbd runs inside the emulator this will enable adb tracing via
      * adb-debug qemud service in the emulator. */
     adb_qemu_trace_init();
-    if((argc > 1) && (!strcmp(argv[1],"recovery"))) {
-        adb_device_banner = "recovery";
-        recovery_mode = 1;
+    while(1) {
+        int c;
+        int option_index = 0;
+        static struct option opts[] = {
+            {"root_seclabel", required_argument, 0, 's' },
+            {"device_banner", required_argument, 0, 'b' }
+        };
+        c = getopt_long(argc, argv, "", opts, &option_index);
+        if (c == -1)
+            break;
+        switch (c) {
+        case 's':
+            root_seclabel = optarg;
+            break;
+        case 'b':
+            adb_device_banner = optarg;
+            break;
+        default:
+            break;
+        }
     }
 
     start_device_log();
diff --git a/include/cutils/atomic-aarch64.h b/include/cutils/atomic-aarch64.h
index 927379f..4562ad0 100644
--- a/include/cutils/atomic-aarch64.h
+++ b/include/cutils/atomic-aarch64.h
@@ -66,7 +66,7 @@
 extern ANDROID_ATOMIC_INLINE
 void android_memory_store_barrier(void)
 {
-    __asm__ __volatile__ ("dmb isht" : : : "memory");
+    __asm__ __volatile__ ("dmb ishst" : : : "memory");
 }
 #endif
 
diff --git a/libcutils/Android.mk b/libcutils/Android.mk
index f8dda36..c08a50f 100644
--- a/libcutils/Android.mk
+++ b/libcutils/Android.mk
@@ -124,7 +124,7 @@
     endif # !x86
 endif # !arm
 
-LOCAL_C_INCLUDES := $(libcutils_c_includes) $(KERNEL_HEADERS)
+LOCAL_C_INCLUDES := $(libcutils_c_includes)
 LOCAL_STATIC_LIBRARIES := liblog
 LOCAL_CFLAGS += $(targetSmpFlag)
 include $(BUILD_STATIC_LIBRARY)
diff --git a/libsysutils/Android.mk b/libsysutils/Android.mk
index 1d396b2..1451b0d 100644
--- a/libsysutils/Android.mk
+++ b/libsysutils/Android.mk
@@ -16,7 +16,7 @@
 
 LOCAL_MODULE:= libsysutils
 
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
+LOCAL_C_INCLUDES :=
 
 LOCAL_CFLAGS :=
 
diff --git a/rootdir/init.rc b/rootdir/init.rc
index a66a2e4..a32366c 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -442,7 +442,7 @@
     start console
 
 # adbd is controlled via property triggers in init.<platform>.usb.rc
-service adbd /sbin/adbd
+service adbd /sbin/adbd --root_seclabel=u:r:su:s0
     class core
     socket adbd stream 660 system system
     disabled