Merge "Update debuggerd to use libbacktrace."
diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c
index 20c08d2..fa7fd98 100644
--- a/adb/framebuffer_service.c
+++ b/adb/framebuffer_service.c
@@ -55,13 +55,13 @@
 void framebuffer_service(int fd, void *cookie)
 {
     struct fbinfo fbinfo;
-    unsigned int i;
+    unsigned int i, bsize;
     char buf[640];
     int fd_screencap;
     int w, h, f;
     int fds[2];
 
-    if (pipe(fds) < 0) goto done;
+    if (pipe(fds) < 0) goto pipefail;
 
     pid_t pid = fork();
     if (pid < 0) goto done;
@@ -164,17 +164,19 @@
     if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;
 
     /* write data */
-    for(i = 0; i < fbinfo.size; i += sizeof(buf)) {
-      if(readx(fd_screencap, buf, sizeof(buf))) goto done;
-      if(writex(fd, buf, sizeof(buf))) goto done;
+    for(i = 0; i < fbinfo.size; i += bsize) {
+      bsize = sizeof(buf);
+      if (i + bsize > fbinfo.size)
+        bsize = fbinfo.size - i;
+      if(readx(fd_screencap, buf, bsize)) goto done;
+      if(writex(fd, buf, bsize)) goto done;
     }
-    if(readx(fd_screencap, buf, fbinfo.size % sizeof(buf))) goto done;
-    if(writex(fd, buf, fbinfo.size % sizeof(buf))) goto done;
 
 done:
     TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));
 
     close(fds[0]);
     close(fds[1]);
+pipefail:
     close(fd);
 }
diff --git a/libbacktrace/Android.mk b/libbacktrace/Android.mk
index f7b084d..4197bbb 100644
--- a/libbacktrace/Android.mk
+++ b/libbacktrace/Android.mk
@@ -63,38 +63,6 @@
 include $(BUILD_SHARED_LIBRARY)
 
 #----------------------------------------------------------------------------
-# The host libbacktrace library using libcorkscrew
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES += \
-	corkscrew.c \
-	common.c \
-	demangle.c \
-	map_info.c \
-
-LOCAL_CFLAGS += \
-	-Wall \
-	-Wno-unused-parameter \
-	-Werror \
-	-std=gnu99 \
-
-LOCAL_SHARED_LIBRARIES := \
-	liblog \
-	libcorkscrew \
-	libgccdemangle \
-	liblog \
-
-LOCAL_LDLIBS += \
-	-ldl \
-	-lrt \
-
-LOCAL_MODULE := libbacktrace
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-#----------------------------------------------------------------------------
 # libbacktrace test library, all optimizations turned off
 #----------------------------------------------------------------------------
 include $(CLEAR_VARS)
@@ -137,6 +105,38 @@
 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
 
 #----------------------------------------------------------------------------
+# The host libbacktrace library using libcorkscrew
+#----------------------------------------------------------------------------
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES += \
+	corkscrew.c \
+	common.c \
+	demangle.c \
+	map_info.c \
+
+LOCAL_CFLAGS += \
+	-Wall \
+	-Wno-unused-parameter \
+	-Werror \
+	-std=gnu99 \
+
+LOCAL_SHARED_LIBRARIES := \
+	liblog \
+	libcorkscrew \
+	libgccdemangle \
+	liblog \
+
+LOCAL_LDLIBS += \
+	-ldl \
+	-lrt \
+
+LOCAL_MODULE := libbacktrace
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_SHARED_LIBRARY)
+
+#----------------------------------------------------------------------------
 # libbacktrace host test library, all optimizations turned off
 #----------------------------------------------------------------------------
 include $(CLEAR_VARS)
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 88dee10..0d53ae1 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -16,6 +16,9 @@
     # This should occur before anything else (e.g. ueventd) is started.
     setcon u:r:init:s0
 
+    # Set the security context of /adb_keys if present.
+    restorecon /adb_keys
+
     start ueventd
 
 # create mountpoints
@@ -208,6 +211,10 @@
     mkdir /data/local 0751 root root
     mkdir /data/misc/media 0700 media media
 
+    # Set security context of any pre-existing /data/misc/adb/adb_keys file.
+    restorecon /data/misc/adb
+    restorecon /data/misc/adb/adb_keys
+
     # For security reasons, /data/local/tmp should always be empty.
     # Do not place files or directories in /data/local/tmp
     mkdir /data/local/tmp 0771 shell shell
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index 2cf0265..a60cfc5 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -5,6 +5,8 @@
 /dev/tty                  0666   root       root
 /dev/random               0666   root       root
 /dev/urandom              0666   root       root
+# Make HW RNG readable by group system to let EntropyMixer read it.
+/dev/hw_random            0440   root       system
 /dev/ashmem               0666   root       root
 /dev/binder               0666   root       root