merge in master-release history after reset to d2e4281204da89a77c9c9743e5cf54a1c3e42a4a
diff --git a/adb/commandline.c b/adb/commandline.c
index e0345a8..5df5796 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -110,9 +110,10 @@
         "  adb push [-p] <local> <remote>\n"
         "                               - copy file/dir to device\n"
         "                                 ('-p' to display the transfer progress)\n"
-        "  adb pull [-p] <remote> [<local>]\n"
+        "  adb pull [-p] [-a] <remote> [<local>]\n"
         "                               - copy file/dir from device\n"
         "                                 ('-p' to display the transfer progress)\n"
+        "                                 ('-a' means copy timestamp and mode)\n"
         "  adb sync [ <directory> ]     - copy host->device only if changed\n"
         "                                 (-l means list but don't copy)\n"
         "                                 (see 'adb help all')\n"
@@ -927,12 +928,19 @@
 }
 
 
-static void parse_push_pull_args(char** arg, int narg, char const** path1, char const** path2,
-                                 int* show_progress) {
+static void parse_push_pull_args(char **arg, int narg, char const **path1, char const **path2,
+                                 int *show_progress, int *copy_attrs) {
     *show_progress = 0;
+    *copy_attrs = 0;
 
-    if ((narg > 0) && !strcmp(*arg, "-p")) {
-        *show_progress = 1;
+    while (narg > 0) {
+        if (!strcmp(*arg, "-p")) {
+            *show_progress = 1;
+        } else if (!strcmp(*arg, "-a")) {
+            *copy_attrs = 1;
+        } else {
+            break;
+        }
         ++arg;
         --narg;
     }
@@ -1396,9 +1404,10 @@
 
     if(!strcmp(argv[0], "push")) {
         int show_progress = 0;
+        int copy_attrs = 0; // unused
         const char* lpath = NULL, *rpath = NULL;
 
-        parse_push_pull_args(&argv[1], argc - 1, &lpath, &rpath, &show_progress);
+        parse_push_pull_args(&argv[1], argc - 1, &lpath, &rpath, &show_progress, &copy_attrs);
 
         if ((lpath != NULL) && (rpath != NULL)) {
             return do_sync_push(lpath, rpath, 0 /* no verify APK */, show_progress);
@@ -1409,12 +1418,13 @@
 
     if(!strcmp(argv[0], "pull")) {
         int show_progress = 0;
+        int copy_attrs = 0;
         const char* rpath = NULL, *lpath = ".";
 
-        parse_push_pull_args(&argv[1], argc - 1, &rpath, &lpath, &show_progress);
+        parse_push_pull_args(&argv[1], argc - 1, &rpath, &lpath, &show_progress, &copy_attrs);
 
         if (rpath != NULL) {
-            return do_sync_pull(rpath, lpath, show_progress);
+            return do_sync_pull(rpath, lpath, show_progress, copy_attrs);
         }
 
         return usage();
diff --git a/adb/file_sync_client.c b/adb/file_sync_client.c
index 8fad50e..a178995 100644
--- a/adb/file_sync_client.c
+++ b/adb/file_sync_client.c
@@ -139,7 +139,8 @@
 
 static syncsendbuf send_buffer;
 
-int sync_readtime(int fd, const char *path, unsigned *timestamp)
+int sync_readtime(int fd, const char *path, unsigned int *timestamp,
+                  unsigned int *mode)
 {
     syncmsg msg;
     int len = strlen(path);
@@ -161,6 +162,7 @@
     }
 
     *timestamp = ltohl(msg.stat.time);
+    *mode = ltohl(msg.stat.mode);
     return 0;
 }
 
@@ -237,7 +239,7 @@
     if (show_progress) {
         // Determine local file size.
         struct stat st;
-        if (lstat(path, &st)) {
+        if (fstat(lfd, &st)) {
             fprintf(stderr,"cannot stat '%s': %s\n", path, strerror(errno));
             return -1;
         }
@@ -931,8 +933,21 @@
     return 0;
 }
 
+static int set_time_and_mode(const char *lpath, unsigned int time, unsigned int mode)
+{
+    struct timeval times[2] = { {time, 0}, {time, 0} };
+    int r1 = utimes(lpath, times);
+
+    /* use umask for permissions */
+    mode_t mask=umask(0000);
+    umask(mask);
+    int r2 = chmod(lpath, mode & ~mask);
+
+    return r1 ? : r2;
+}
+
 static int copy_remote_dir_local(int fd, const char *rpath, const char *lpath,
-                                 int checktimestamps)
+                                 int copy_attrs)
 {
     copyinfo *filelist = 0;
     copyinfo *ci, *next;
@@ -962,26 +977,6 @@
         return -1;
     }
 
-#if 0
-    if (checktimestamps) {
-        for (ci = filelist; ci != 0; ci = ci->next) {
-            if (sync_start_readtime(fd, ci->dst)) {
-                return 1;
-            }
-        }
-        for (ci = filelist; ci != 0; ci = ci->next) {
-            unsigned int timestamp, mode, size;
-            if (sync_finish_readtime(fd, &timestamp, &mode, &size))
-                return 1;
-            if (size == ci->size) {
-                /* for links, we cannot update the atime/mtime */
-                if ((S_ISREG(ci->mode & mode) && timestamp == ci->time) ||
-                    (S_ISLNK(ci->mode & mode) && timestamp >= ci->time))
-                    ci->flag = 1;
-            }
-        }
-    }
-#endif
     for (ci = filelist; ci != 0; ci = next) {
         next = ci->next;
         if (ci->flag == 0) {
@@ -989,6 +984,10 @@
             if (sync_recv(fd, ci->src, ci->dst, 0 /* no show progress */)) {
                 return 1;
             }
+
+            if (copy_attrs && set_time_and_mode(ci->dst, ci->time, ci->mode)) {
+               return 1;
+            }
             pulled++;
         } else {
             skipped++;
@@ -1003,9 +1002,9 @@
     return 0;
 }
 
-int do_sync_pull(const char *rpath, const char *lpath, int show_progress)
+int do_sync_pull(const char *rpath, const char *lpath, int show_progress, int copy_attrs)
 {
-    unsigned mode;
+    unsigned mode, time;
     struct stat st;
 
     int fd;
@@ -1016,7 +1015,7 @@
         return 1;
     }
 
-    if(sync_readmode(fd, rpath, &mode)) {
+    if(sync_readtime(fd, rpath, &time, &mode)) {
         return 1;
     }
     if(mode == 0) {
@@ -1047,13 +1046,15 @@
         if (sync_recv(fd, rpath, lpath, show_progress)) {
             return 1;
         } else {
+            if (copy_attrs && set_time_and_mode(lpath, time, mode))
+                return 1;
             END();
             sync_quit(fd);
             return 0;
         }
     } else if(S_ISDIR(mode)) {
         BEGIN();
-        if (copy_remote_dir_local(fd, rpath, lpath, 0)) {
+        if (copy_remote_dir_local(fd, rpath, lpath, copy_attrs)) {
             return 1;
         } else {
             END();
diff --git a/adb/file_sync_service.h b/adb/file_sync_service.h
index 3e7e096..8ea239e 100644
--- a/adb/file_sync_service.h
+++ b/adb/file_sync_service.h
@@ -80,7 +80,7 @@
 int do_sync_ls(const char *path);
 int do_sync_push(const char *lpath, const char *rpath, int verifyApk, int show_progress);
 int do_sync_sync(const char *lpath, const char *rpath, int listonly);
-int do_sync_pull(const char *rpath, const char *lpath, int show_progress);
+int do_sync_pull(const char *rpath, const char *lpath, int show_progress, int pullTime);
 
 #define SYNC_DATA_MAX (64*1024)
 
diff --git a/debuggerd/Android.mk b/debuggerd/Android.mk
index f6d8f0c..8be3541 100644
--- a/debuggerd/Android.mk
+++ b/debuggerd/Android.mk
@@ -20,8 +20,7 @@
 LOCAL_CFLAGS := \
 	-Wall \
 	-Wno-array-bounds \
-	-Werror \
-	-Wno-unused-parameter \
+	-Werror
 
 ifeq ($(ARCH_ARM_HAVE_VFP),true)
 LOCAL_CFLAGS_arm += -DWITH_VFP
@@ -55,7 +54,7 @@
 LOCAL_SRC_FILES_x86_64 := x86_64/crashglue.S
 LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
 LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS += -fstack-protector-all -Wno-unused-parameter -Wno-free-nonheap-object
+LOCAL_CFLAGS += -fstack-protector-all -Werror -Wno-free-nonheap-object
 #LOCAL_FORCE_STATIC_EXECUTABLE := true
 LOCAL_SHARED_LIBRARIES := libcutils liblog libc
 
@@ -76,6 +75,7 @@
 LOCAL_CFLAGS_arm += -DWITH_VFP_D32
 endif # ARCH_ARM_HAVE_VFP_D32
 endif # ARCH_ARM_HAVE_VFP == true
+LOCAL_CFLAGS += -Werror
 
 LOCAL_SRC_FILES_arm64 := arm64/vfp.S
 LOCAL_MODULE_TARGET_ARCH += arm64
diff --git a/debuggerd/arm64/machine.cpp b/debuggerd/arm64/machine.cpp
index 7159228..2413d5e 100644
--- a/debuggerd/arm64/machine.cpp
+++ b/debuggerd/arm64/machine.cpp
@@ -82,8 +82,6 @@
   io.iov_base = &r;
   io.iov_len = sizeof(r);
 
-  bool only_in_tombstone = !IS_AT_FAULT(scope_flags);
-
   if (ptrace(PTRACE_GETREGSET, tid, (void*) NT_PRSTATUS, (void*) &io) == -1) {
     _LOG(log, scope_flags, "ptrace error: %s\n", strerror(errno));
     return;
diff --git a/debuggerd/crasher.c b/debuggerd/crasher.c
index 3e3ab5a..01ce0be 100644
--- a/debuggerd/crasher.c
+++ b/debuggerd/crasher.c
@@ -6,13 +6,18 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/cdefs.h>
 #include <sys/ptrace.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <unistd.h>
 
-#include <cutils/log.h>
 #include <cutils/sockets.h>
+#include <log/log.h>
+
+#ifndef __unused
+#define __unused __attribute__((__unused__))
+#endif
 
 extern const char* __progname;
 
@@ -26,7 +31,7 @@
     }
 }
 
-static int smash_stack(int i) {
+static int smash_stack(int i __unused) {
     printf("crasher: deliberately corrupting stack...\n");
     // Unless there's a "big enough" buffer on the stack, gcc
     // doesn't bother inserting checks.
@@ -47,11 +52,6 @@
     overflow_stack(&buf);
 }
 
-static void test_call1()
-{
-    *((int*) 32) = 1;
-}
-
 static void *noisy(void *x)
 {
     char c = (uintptr_t) x;
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c
index 7f49ae9..f98268e 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.c
@@ -100,10 +100,11 @@
     char sig_name[13];
     char part_name[9];
     bool is_optional;
-} images[3] = {
+} images[4] = {
     {"boot.img", "boot.sig", "boot", false},
     {"recovery.img", "recovery.sig", "recovery", true},
     {"system.img", "system.sig", "system", false},
+    {"tos.img", "tos.sig", "tos", true},
 };
 
 void get_my_path(char *path);
@@ -120,6 +121,8 @@
         fn = "recovery.img";
     } else if(!strcmp(item,"system")) {
         fn = "system.img";
+    } else if(!strcmp(item,"tos")) {
+        fn = "tos.img";
     } else if(!strcmp(item,"userdata")) {
         fn = "userdata.img";
     } else if(!strcmp(item,"cache")) {
@@ -285,7 +288,7 @@
             "\n"
             "commands:\n"
             "  update <filename>                        reflash device from update.zip\n"
-            "  flashall                                 flash boot + recovery + system\n"
+            "  flashall                                 flash boot, system, and if found, recovery, tos\n"
             "  flash <partition> [ <filename> ]         write a file to a flash partition\n"
             "  erase <partition>                        erase a flash partition\n"
             "  format <partition>                       format a flash partition \n"
@@ -657,7 +660,7 @@
 
     fd = open(fname, O_RDONLY | O_BINARY);
     if (fd < 0) {
-        die("cannot open '%s'\n", fname);
+        return -1;
     }
 
     return load_buf_fd(usb, fd, buf);
diff --git a/include/log/log_read.h b/include/log/log_read.h
index bd9de12..54d71a4 100644
--- a/include/log/log_read.h
+++ b/include/log/log_read.h
@@ -33,6 +33,9 @@
     uint32_t tv_sec; // good to Feb 5 2106
     uint32_t tv_nsec;
 
+    static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
+    static const uint32_t tv_nsec_max = 999999999UL;
+
     log_time(const timespec &T)
     {
         tv_sec = T.tv_sec;
diff --git a/init/builtins.c b/init/builtins.c
index a857c98..a9cd1bd 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -196,6 +196,8 @@
 {
     if (!(svc->flags & SVC_DISABLED)) {
         service_start(svc, NULL);
+    } else {
+        svc->flags |= SVC_DISABLED_START;
     }
 }
 
@@ -238,6 +240,21 @@
     return write_file("/proc/sys/kernel/domainname", args[1]);
 }
 
+int do_enable(int nargs, char **args)
+{
+    struct service *svc;
+    svc = service_find_by_name(args[1]);
+    if (svc) {
+        svc->flags &= ~(SVC_DISABLED | SVC_RC_DISABLED);
+        if (svc->flags & SVC_DISABLED_START) {
+            service_start(svc, NULL);
+        }
+    } else {
+        return -1;
+    }
+    return 0;
+}
+
 int do_exec(int nargs, char **args)
 {
     return -1;
diff --git a/init/devices.c b/init/devices.c
index 80c6d75..5d7ad3b 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -699,7 +699,7 @@
 
 static void handle_device_event(struct uevent *uevent)
 {
-    if (!strcmp(uevent->action,"add") || !strcmp(uevent->action, "change"))
+    if (!strcmp(uevent->action,"add") || !strcmp(uevent->action, "change") || !strcmp(uevent->action, "online"))
         fixup_sys_perms(uevent->path);
 
     if (!strncmp(uevent->subsystem, "block", 5)) {
diff --git a/init/init.c b/init/init.c
index 0884236..fc20198 100644
--- a/init/init.c
+++ b/init/init.c
@@ -164,7 +164,7 @@
          * state and immediately takes it out of the restarting
          * state if it was in there
          */
-    svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART));
+    svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART|SVC_DISABLED_START));
     svc->time_started = 0;
 
         /* running processes require no additional work -- if
@@ -364,7 +364,7 @@
 {
     /* The service is still SVC_RUNNING until its process exits, but if it has
      * already exited it shoudn't attempt a restart yet. */
-    svc->flags &= (~SVC_RESTARTING);
+    svc->flags &= ~(SVC_RESTARTING | SVC_DISABLED_START);
 
     if ((how != SVC_DISABLED) && (how != SVC_RESET) && (how != SVC_RESTART)) {
         /* Hrm, an illegal flag.  Default to SVC_DISABLED */
diff --git a/init/init.h b/init/init.h
index 736b75b..c241912 100644
--- a/init/init.h
+++ b/init/init.h
@@ -74,6 +74,7 @@
                                  so it can be restarted with its class */
 #define SVC_RC_DISABLED 0x80  /* Remember if the disabled flag was set in the rc script */
 #define SVC_RESTART     0x100 /* Use to safely restart (stop, wait, start) a service */
+#define SVC_DISABLED_START 0x200 /* a start was requested but it was disabled at the time */
 
 #define NR_SVC_SUPP_GIDS 12    /* twelve supplementary groups */
 
diff --git a/init/init_parser.c b/init/init_parser.c
index f49e698..02e5bdc 100644
--- a/init/init_parser.c
+++ b/init/init_parser.c
@@ -98,6 +98,7 @@
         if (!strcmp(s, "omainname")) return K_domainname;
         break;
     case 'e':
+        if (!strcmp(s, "nable")) return K_enable;
         if (!strcmp(s, "xec")) return K_exec;
         if (!strcmp(s, "xport")) return K_export;
         break;
diff --git a/init/keywords.h b/init/keywords.h
index 97fe50c..6625330 100644
--- a/init/keywords.h
+++ b/init/keywords.h
@@ -6,6 +6,7 @@
 int do_class_stop(int nargs, char **args);
 int do_class_reset(int nargs, char **args);
 int do_domainname(int nargs, char **args);
+int do_enable(int nargs, char **args);
 int do_exec(int nargs, char **args);
 int do_export(int nargs, char **args);
 int do_hostname(int nargs, char **args);
@@ -55,6 +56,7 @@
     KEYWORD(critical,    OPTION,  0, 0)
     KEYWORD(disabled,    OPTION,  0, 0)
     KEYWORD(domainname,  COMMAND, 1, do_domainname)
+    KEYWORD(enable,      COMMAND, 1, do_enable)
     KEYWORD(exec,        COMMAND, 1, do_exec)
     KEYWORD(export,      COMMAND, 2, do_export)
     KEYWORD(group,       OPTION,  0, 0)
diff --git a/init/readme.txt b/init/readme.txt
index 42a09cb..613a9e9 100644
--- a/init/readme.txt
+++ b/init/readme.txt
@@ -178,6 +178,16 @@
 domainname <name>
    Set the domain name.
 
+enable <servicename>
+   Turns a disabled service into an enabled one as if the service did not
+   specify disabled.
+   If the service is supposed to be running, it will be started now.
+   Typically used when the bootloader sets a variable that indicates a specific
+   service should be started when needed. E.g.
+     on property:ro.boot.myfancyhardware=1
+        enable my_fancy_service_for_my_fancy_hardware
+
+
 insmod <path>
    Install the module at <path>
 
diff --git a/libcutils/Android.mk b/libcutils/Android.mk
index 635695a..405761c 100644
--- a/libcutils/Android.mk
+++ b/libcutils/Android.mk
@@ -77,7 +77,7 @@
 LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c
 LOCAL_LDLIBS := -lpthread
 LOCAL_STATIC_LIBRARIES := liblog
-LOCAL_CFLAGS += $(hostSmpFlag)
+LOCAL_CFLAGS += $(hostSmpFlag) -Werror
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 
@@ -88,14 +88,14 @@
 LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c
 LOCAL_LDLIBS := -lpthread
 LOCAL_STATIC_LIBRARIES := lib64log
-LOCAL_CFLAGS += $(hostSmpFlag) -m64
+LOCAL_CFLAGS += $(hostSmpFlag) -m64 -Werror
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 # Tests for host
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := tst_str_parms
-LOCAL_CFLAGS += -DTEST_STR_PARMS
+LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror
 LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c
 LOCAL_STATIC_LIBRARIES := liblog
 LOCAL_MODULE_TAGS := optional
@@ -135,7 +135,7 @@
 
 LOCAL_C_INCLUDES := $(libcutils_c_includes)
 LOCAL_STATIC_LIBRARIES := liblog
-LOCAL_CFLAGS += $(targetSmpFlag)
+LOCAL_CFLAGS += $(targetSmpFlag) -Werror
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
@@ -144,13 +144,13 @@
 # liblog symbols present in libcutils.
 LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog
 LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_CFLAGS += $(targetSmpFlag)
+LOCAL_CFLAGS += $(targetSmpFlag) -Werror
 LOCAL_C_INCLUDES := $(libcutils_c_includes)
 include $(BUILD_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
 LOCAL_MODULE := tst_str_parms
-LOCAL_CFLAGS += -DTEST_STR_PARMS
+LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror
 LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_MODULE_TAGS := optional
diff --git a/libcutils/ashmem-host.c b/libcutils/ashmem-host.c
index f03e130..7873964 100644
--- a/libcutils/ashmem-host.c
+++ b/libcutils/ashmem-host.c
@@ -19,20 +19,24 @@
  * an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version.
  */
 
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
 #include <errno.h>
-#include <time.h>
+#include <fcntl.h>
 #include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
 
 #include <cutils/ashmem.h>
 
-int ashmem_create_region(const char *ignored, size_t size)
+#ifndef __unused
+#define __unused __attribute__((__unused__))
+#endif
+
+int ashmem_create_region(const char *ignored __unused, size_t size)
 {
 	static const char txt[] = "abcdefghijklmnopqrstuvwxyz"
 				  "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -78,17 +82,17 @@
 	return -1;
 }
 
-int ashmem_set_prot_region(int fd, int prot)
+int ashmem_set_prot_region(int fd __unused, int prot __unused)
 {
 	return 0;
 }
 
-int ashmem_pin_region(int fd, size_t offset, size_t len)
+int ashmem_pin_region(int fd __unused, size_t offset __unused, size_t len __unused)
 {
 	return ASHMEM_NOT_PURGED;
 }
 
-int ashmem_unpin_region(int fd, size_t offset, size_t len)
+int ashmem_unpin_region(int fd __unused, size_t offset __unused, size_t len __unused)
 {
 	return ASHMEM_IS_UNPINNED;
 }
diff --git a/libcutils/cpu_info.c b/libcutils/cpu_info.c
index 23dda8a..21fa1dc 100644
--- a/libcutils/cpu_info.c
+++ b/libcutils/cpu_info.c
@@ -1,5 +1,4 @@
-/* libs/cutils/cpu_info.c
-**
+/*
 ** Copyright 2007, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -15,11 +14,12 @@
 ** limitations under the License.
 */
 
-#include <cutils/cpu_info.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
+#include <cutils/cpu_info.h>
+
 // we cache the serial number here.
 // this is also used as a fgets() line buffer when we are reading /proc/cpuinfo
 static char serial_number[100] = { 0 };
@@ -31,7 +31,6 @@
         FILE* file;
         char* chp, *end;
         char* whitespace;
-        int length;
         
         // read serial number from /proc/cpuinfo
         file = fopen("proc/cpuinfo", "r");
diff --git a/libcutils/dlmalloc_stubs.c b/libcutils/dlmalloc_stubs.c
index c327a55..6dca911 100644
--- a/libcutils/dlmalloc_stubs.c
+++ b/libcutils/dlmalloc_stubs.c
@@ -15,20 +15,22 @@
  */
 
 #include "../../../bionic/libc/bionic/dlmalloc.h"
-#include "cutils/log.h"
+#include "log/log.h"
+
+#define UNUSED __attribute__((__unused__))
 
 /*
  * Stubs for functions defined in bionic/libc/bionic/dlmalloc.c. These
  * are used in host builds, as the host libc will not contain these
  * functions.
  */
-void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*),
-                          void* arg)
+void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*) UNUSED,
+                          void* arg UNUSED)
 {
   ALOGW("Called host unimplemented stub: dlmalloc_inspect_all");
 }
 
-int dlmalloc_trim(size_t unused)
+int dlmalloc_trim(size_t unused UNUSED)
 {
   ALOGW("Called host unimplemented stub: dlmalloc_trim");
   return 0;
diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c
index 5d90a01..67e101d 100644
--- a/libcutils/iosched_policy.c
+++ b/libcutils/iosched_policy.c
@@ -1,5 +1,4 @@
 /*
-**
 ** Copyright 2007-2014, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -15,12 +14,12 @@
 ** limitations under the License.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #ifdef HAVE_SCHED_H
 
@@ -30,6 +29,9 @@
 /* #include <linux/ioprio.h> */
 extern int ioprio_set(int which, int who, int ioprio);
 extern int ioprio_get(int which, int who);
+#define __android_unused
+#else
+#define __android_unused __attribute__((__unused__))
 #endif
 
 enum {
@@ -41,7 +43,7 @@
 #define CLASS_SHIFT 13
 #define IOPRIO_NORM 4
 
-int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio) {
+int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) {
 #ifdef HAVE_ANDROID_OS
     if (ioprio_set(WHO_PROCESS, pid, ioprio | (clazz << CLASS_SHIFT))) {
         return -1;
@@ -50,7 +52,7 @@
     return 0;
 }
 
-int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio) {
+int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) {
 #ifdef HAVE_ANDROID_OS
     int rc;
 
diff --git a/libcutils/partition_utils.c b/libcutils/partition_utils.c
index 10539fa..823b162 100644
--- a/libcutils/partition_utils.c
+++ b/libcutils/partition_utils.c
@@ -14,12 +14,13 @@
  * limitations under the License.
  */
 
-#include <sys/types.h>
-#include <unistd.h>
 #include <fcntl.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h> /* for BLKGETSIZE */
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
 #include <cutils/properties.h>
 
 static int only_one_char(char *buf, int len, char c)
@@ -39,7 +40,7 @@
 int partition_wiped(char *source)
 {
     char buf[4096];
-    int fd, ret, wiped;
+    int fd, ret;
 
     if ((fd = open(source, O_RDONLY)) < 0) {
         return 0;
diff --git a/libcutils/process_name.c b/libcutils/process_name.c
index a6ab951..9c3dfb8 100644
--- a/libcutils/process_name.c
+++ b/libcutils/process_name.c
@@ -14,25 +14,27 @@
  * limitations under the License.
  */
 
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
+#if defined(HAVE_PRCTL)
+#include <sys/prctl.h>
+#endif
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
 #include <cutils/process_name.h>
 #ifdef HAVE_ANDROID_OS
 #include <cutils/properties.h>
 #endif
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#if defined(HAVE_PRCTL)
-#include <sys/prctl.h>
-#endif
 
 #define PROCESS_NAME_DEVICE "/sys/qemu_trace/process_name"
 
 static const char* process_name = "unknown";
+#ifdef HAVE_ANDROID_OS
 static int running_in_emulator = -1;
+#endif
 
 void set_process_name(const char* new_name) {
 #ifdef HAVE_ANDROID_OS
diff --git a/libcutils/qtaguid.c b/libcutils/qtaguid.c
index 899a7b4..00e211c 100644
--- a/libcutils/qtaguid.c
+++ b/libcutils/qtaguid.c
@@ -1,5 +1,4 @@
-/* libcutils/qtaguid.c
-**
+/*
 ** Copyright 2011, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
@@ -146,7 +145,7 @@
 
 int qtaguid_deleteTagData(int tag, uid_t uid) {
     char lineBuf[CTRL_MAX_INPUT_LEN];
-    int fd, cnt = 0, res = 0;
+    int cnt = 0, res = 0;
     uint64_t kTag = (uint64_t)tag << 32;
 
     ALOGV("Deleting tag data with tag %" PRIx64 "{%d,0} for uid %d", kTag, tag, uid);
@@ -164,8 +163,6 @@
 }
 
 int qtaguid_setPacifier(int on) {
-    int param_fd;
-    int res;
     const char *value;
 
     value = on ? "Y" : "N";
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 7c65843..fa0792f 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -1,6 +1,4 @@
-
-/* libs/cutils/sched_policy.c
-**
+/*
 ** Copyright 2007, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -18,14 +16,17 @@
 
 #define LOG_TAG "SchedPolicy"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include <cutils/sched_policy.h>
-#include <cutils/log.h>
+#include <log/log.h>
+
+#define UNUSED __attribute__((__unused__))
 
 /* Re-map SP_DEFAULT to the system default policy, and leave other values unchanged.
  * Call this any place a SchedPolicy is used as an input parameter.
@@ -337,12 +338,12 @@
 
 /* Stubs for non-Android targets. */
 
-int set_sched_policy(int tid, SchedPolicy policy)
+int set_sched_policy(int tid UNUSED, SchedPolicy policy UNUSED)
 {
     return 0;
 }
 
-int get_sched_policy(int tid, SchedPolicy *policy)
+int get_sched_policy(int tid UNUSED, SchedPolicy *policy)
 {
     *policy = SP_SYSTEM_DEFAULT;
     return 0;
diff --git a/libcutils/socket_inaddr_any_server.c b/libcutils/socket_inaddr_any_server.c
index 7d5dab4..f70d56b 100644
--- a/libcutils/socket_inaddr_any_server.c
+++ b/libcutils/socket_inaddr_any_server.c
@@ -1,5 +1,4 @@
-/* libs/cutils/socket_inaddr_any_server.c
-**
+/*
 ** Copyright 2006, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -15,13 +14,11 @@
 ** limitations under the License.
 */
 
-#include <cutils/sockets.h>
-
+#include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stddef.h>
 
 #ifndef HAVE_WINSOCK
 #include <sys/socket.h>
@@ -30,13 +27,14 @@
 #include <netinet/in.h>
 #endif
 
+#include <cutils/sockets.h>
+
 #define LISTEN_BACKLOG 4
 
 /* open listen() port on any interface */
 int socket_inaddr_any_server(int port, int type)
 {
     struct sockaddr_in addr;
-    size_t alen;
     int s, n;
 
     memset(&addr, 0, sizeof(addr));
diff --git a/libcutils/socket_local_client.c b/libcutils/socket_local_client.c
index 5310516..ddcc2da 100644
--- a/libcutils/socket_local_client.c
+++ b/libcutils/socket_local_client.c
@@ -14,13 +14,13 @@
  * limitations under the License.
  */
 
-#include <cutils/sockets.h>
-
+#include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stddef.h>
+
+#include <cutils/sockets.h>
 
 #ifdef HAVE_WINSOCK
 
@@ -128,7 +128,6 @@
 {
     struct sockaddr_un addr;
     socklen_t alen;
-    size_t namelen;
     int err;
 
     err = socket_make_sockaddr_un(name, namespaceId, &addr, &alen);
diff --git a/libcutils/socket_loopback_client.c b/libcutils/socket_loopback_client.c
index cb82c5e..9aed7b7 100644
--- a/libcutils/socket_loopback_client.c
+++ b/libcutils/socket_loopback_client.c
@@ -1,5 +1,4 @@
-/* libs/cutils/socket_loopback_client.c
-**
+/*
 ** Copyright 2006, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -15,13 +14,11 @@
 ** limitations under the License.
 */
 
-#include <cutils/sockets.h>
-
+#include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stddef.h>
 
 #ifndef HAVE_WINSOCK
 #include <sys/socket.h>
@@ -30,6 +27,8 @@
 #include <netinet/in.h>
 #endif
 
+#include <cutils/sockets.h>
+
 /* Connect to port on the loopback IP interface. type is
  * SOCK_STREAM or SOCK_DGRAM. 
  * return is a file descriptor or -1 on error
@@ -37,7 +36,6 @@
 int socket_loopback_client(int port, int type)
 {
     struct sockaddr_in addr;
-    socklen_t alen;
     int s;
 
     memset(&addr, 0, sizeof(addr));
diff --git a/libcutils/socket_loopback_server.c b/libcutils/socket_loopback_server.c
index 3208488..5175e9c 100644
--- a/libcutils/socket_loopback_server.c
+++ b/libcutils/socket_loopback_server.c
@@ -1,5 +1,4 @@
-/* libs/cutils/socket_loopback_server.c
-**
+/*
 ** Copyright 2006, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -15,13 +14,11 @@
 ** limitations under the License.
 */
 
-#include <cutils/sockets.h>
-
+#include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stddef.h>
 
 #define LISTEN_BACKLOG 4
 
@@ -32,11 +29,12 @@
 #include <netinet/in.h>
 #endif
 
+#include <cutils/sockets.h>
+
 /* open listen() port on loopback interface */
 int socket_loopback_server(int port, int type)
 {
     struct sockaddr_in addr;
-    size_t alen;
     int s, n;
 
     memset(&addr, 0, sizeof(addr));
diff --git a/libcutils/socket_network_client.c b/libcutils/socket_network_client.c
index a64006c..c52013d 100644
--- a/libcutils/socket_network_client.c
+++ b/libcutils/socket_network_client.c
@@ -1,5 +1,4 @@
-/* libs/cutils/socket_network_client.c
-**
+/*
 ** Copyright 2006, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -15,13 +14,11 @@
 ** limitations under the License.
 */
 
-#include <cutils/sockets.h>
-
+#include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stddef.h>
 
 #ifndef HAVE_WINSOCK
 #include <sys/socket.h>
@@ -31,6 +28,7 @@
 #include <netdb.h>
 #endif
 
+#include <cutils/sockets.h>
 
 /* Connect to port on the IP interface. type is
  * SOCK_STREAM or SOCK_DGRAM. 
@@ -40,7 +38,6 @@
 {
     struct hostent *hp;
     struct sockaddr_in addr;
-    socklen_t alen;
     int s;
 
     hp = gethostbyname(host);
diff --git a/libcutils/sockets.c b/libcutils/sockets.c
index b5a1b3d..15ede2b 100644
--- a/libcutils/sockets.c
+++ b/libcutils/sockets.c
@@ -14,15 +14,18 @@
  * limitations under the License.
  */
 
-#include <cutils/log.h>
 #include <cutils/sockets.h>
+#include <log/log.h>
 
 #ifdef HAVE_ANDROID_OS
 /* For the socket trust (credentials) check */
 #include <private/android_filesystem_config.h>
+#define __android_unused
+#else
+#define __android_unused __attribute__((__unused__))
 #endif
 
-bool socket_peer_is_trusted(int fd)
+bool socket_peer_is_trusted(int fd __android_unused)
 {
 #ifdef HAVE_ANDROID_OS
     struct ucred cr;
diff --git a/libcutils/str_parms.c b/libcutils/str_parms.c
index d2b97e8..dfe8c4b 100644
--- a/libcutils/str_parms.c
+++ b/libcutils/str_parms.c
@@ -25,10 +25,9 @@
 #include <string.h>
 
 #include <cutils/hashmap.h>
-#include <cutils/log.h>
 #include <cutils/memory.h>
-
 #include <cutils/str_parms.h>
+#include <log/log.h>
 
 #define UNUSED __attribute__((unused))
 
@@ -378,8 +377,6 @@
 
 int main(void)
 {
-    struct str_parms *str_parms;
-
     test_str_parms_str("");
     test_str_parms_str(";");
     test_str_parms_str("=");
diff --git a/libcutils/threads.c b/libcutils/threads.c
index 42cc928..bf182f0 100644
--- a/libcutils/threads.c
+++ b/libcutils/threads.c
@@ -1,5 +1,4 @@
-/* libs/cutils/threads.c
-**
+/*
 ** Copyright (C) 2007, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -14,13 +13,12 @@
 ** See the License for the specific language governing permissions and 
 ** limitations under the License.
 */
+
 #include <cutils/threads.h>
 
 #ifdef HAVE_PTHREADS
 void*  thread_store_get( thread_store_t*  store )
 {
-    const pthread_key_t  k = store->tls;
-
     if (!store->has_tls)
         return NULL;
 
diff --git a/libcutils/trace.c b/libcutils/trace.c
index 9754a44..f57aac2 100644
--- a/libcutils/trace.c
+++ b/libcutils/trace.c
@@ -28,7 +28,7 @@
 #include <cutils/trace.h>
 
 #define LOG_TAG "cutils-trace"
-#include <cutils/log.h>
+#include <log/log.h>
 
 volatile int32_t        atrace_is_ready      = 0;
 int                     atrace_marker_fd     = -1;
@@ -86,7 +86,6 @@
 static bool atrace_is_app_tracing_enabled()
 {
     bool sys_debuggable = false;
-    bool proc_debuggable = false;
     char value[PROPERTY_VALUE_MAX];
     bool result = false;
 
diff --git a/liblog/logprint.c b/liblog/logprint.c
index a7480d5..3bc9f5a 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -938,88 +938,3 @@
 
     return ret;
 }
-
-
-
-void logprint_run_tests()
-{
-#if 0
-
-    fprintf(stderr, "tests disabled\n");
-
-#else
-
-    int err;
-    const char *tag;
-    AndroidLogFormat *p_format;
-
-    p_format = android_log_format_new();
-
-    fprintf(stderr, "running tests\n");
-
-    tag = "random";
-
-    android_log_addFilterRule(p_format,"*:i");
-
-    assert (ANDROID_LOG_INFO == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
-    android_log_addFilterRule(p_format, "*");
-    assert (ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
-    android_log_addFilterRule(p_format, "*:v");
-    assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
-    android_log_addFilterRule(p_format, "*:i");
-    assert (ANDROID_LOG_INFO == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
-
-    android_log_addFilterRule(p_format, "random");
-    assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
-    android_log_addFilterRule(p_format, "random:v");
-    assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
-    android_log_addFilterRule(p_format, "random:d");
-    assert (ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
-    android_log_addFilterRule(p_format, "random:w");
-    assert (ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
-
-    android_log_addFilterRule(p_format, "crap:*");
-    assert (ANDROID_LOG_VERBOSE== filterPriForTag(p_format, "crap"));
-    assert(android_log_shouldPrintLine(p_format, "crap", ANDROID_LOG_VERBOSE) > 0);
-
-    // invalid expression
-    err = android_log_addFilterRule(p_format, "random:z");
-    assert (err < 0);
-    assert (ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
-    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
-
-    // Issue #550946
-    err = android_log_addFilterString(p_format, " ");
-    assert(err == 0);
-    assert(ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
-
-    // note trailing space
-    err = android_log_addFilterString(p_format, "*:s random:d ");
-    assert(err == 0);
-    assert(ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
-
-    err = android_log_addFilterString(p_format, "*:s random:z");
-    assert(err < 0);
-
-
-#if 0
-    char *ret;
-    char defaultBuffer[512];
-
-    ret = android_log_formatLogLine(p_format,
-        defaultBuffer, sizeof(defaultBuffer), 0, ANDROID_LOG_ERROR, 123,
-        123, 123, "random", "nofile", strlen("Hello"), "Hello", NULL);
-#endif
-
-
-    fprintf(stderr, "tests complete\n");
-#endif
-}
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 92b68ac..c6f981f 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -21,6 +21,7 @@
 #include <log/log.h>
 #include <log/logger.h>
 #include <log/log_read.h>
+#include <log/logprint.h>
 
 // enhanced version of LOG_FAILURE_RETRY to add support for EAGAIN and
 // non-syscall libs. Since we are only using this in the emergency of
@@ -612,3 +613,72 @@
 
     android_logger_list_close(logger_list);
 }
+
+static bool checkPriForTag(AndroidLogFormat *p_format, const char *tag, android_LogPriority pri) {
+    return android_log_shouldPrintLine(p_format, tag, pri)
+        && !android_log_shouldPrintLine(p_format, tag, (android_LogPriority)(pri - 1));
+}
+
+TEST(liblog, filterRule) {
+    static const char tag[] = "random";
+
+    AndroidLogFormat *p_format = android_log_format_new();
+
+    android_log_addFilterRule(p_format,"*:i");
+
+    EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_INFO));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
+    android_log_addFilterRule(p_format, "*");
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
+    android_log_addFilterRule(p_format, "*:v");
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
+    android_log_addFilterRule(p_format, "*:i");
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_INFO));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
+
+    android_log_addFilterRule(p_format, tag);
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
+    android_log_addFilterRule(p_format, "random:v");
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
+    android_log_addFilterRule(p_format, "random:d");
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
+    android_log_addFilterRule(p_format, "random:w");
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
+
+    android_log_addFilterRule(p_format, "crap:*");
+    EXPECT_TRUE (checkPriForTag(p_format, "crap", ANDROID_LOG_VERBOSE));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, "crap", ANDROID_LOG_VERBOSE) > 0);
+
+    // invalid expression
+    EXPECT_TRUE (android_log_addFilterRule(p_format, "random:z") < 0);
+    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
+    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
+
+    // Issue #550946
+    EXPECT_TRUE(android_log_addFilterString(p_format, " ") == 0);
+    EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
+
+    // note trailing space
+    EXPECT_TRUE(android_log_addFilterString(p_format, "*:s random:d ") == 0);
+    EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
+
+    EXPECT_TRUE(android_log_addFilterString(p_format, "*:s random:z") < 0);
+
+#if 0 // bitrot, seek update
+    char defaultBuffer[512];
+
+    android_log_formatLogLine(p_format,
+        defaultBuffer, sizeof(defaultBuffer), 0, ANDROID_LOG_ERROR, 123,
+        123, 123, tag, "nofile", strlen("Hello"), "Hello", NULL);
+
+    fprintf(stderr, "%s\n", defaultBuffer);
+#endif
+
+    android_log_format_free(p_format);
+}
diff --git a/libsysutils/Android.mk b/libsysutils/Android.mk
index 1451b0d..246f954 100644
--- a/libsysutils/Android.mk
+++ b/libsysutils/Android.mk
@@ -18,7 +18,7 @@
 
 LOCAL_C_INCLUDES :=
 
-LOCAL_CFLAGS :=
+LOCAL_CFLAGS := -Werror
 
 LOCAL_SHARED_LIBRARIES := libcutils liblog
 
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index 6976eba..1c9c70a 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -109,7 +109,7 @@
             if (ifaddr->ifa_family == AF_INET) {
                 struct in_addr *addr4 = (struct in_addr *) RTA_DATA(rta);
                 if (RTA_PAYLOAD(rta) < sizeof(*addr4)) {
-                    SLOGE("Short IPv4 address (%d bytes) in %s",
+                    SLOGE("Short IPv4 address (%zu bytes) in %s",
                           RTA_PAYLOAD(rta), msgtype);
                     continue;
                 }
@@ -117,7 +117,7 @@
             } else if (ifaddr->ifa_family == AF_INET6) {
                 struct in6_addr *addr6 = (struct in6_addr *) RTA_DATA(rta);
                 if (RTA_PAYLOAD(rta) < sizeof(*addr6)) {
-                    SLOGE("Short IPv6 address (%d bytes) in %s",
+                    SLOGE("Short IPv6 address (%zu bytes) in %s",
                           RTA_PAYLOAD(rta), msgtype);
                     continue;
                 }
@@ -152,7 +152,7 @@
             }
 
             if (RTA_PAYLOAD(rta) < sizeof(*cacheinfo)) {
-                SLOGE("Short IFA_CACHEINFO (%d vs. %d bytes) in %s",
+                SLOGE("Short IFA_CACHEINFO (%zu vs. %zu bytes) in %s",
                       RTA_PAYLOAD(rta), sizeof(cacheinfo), msgtype);
                 continue;
             }
@@ -174,7 +174,6 @@
 }
 
 /*
-<<<<<<< HEAD
  * Parse a RTM_NEWNDUSEROPT message.
  */
 bool NetlinkEvent::parseNdUserOptMessage(struct nduseroptmsg *msg, int len) {
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
index ab1b856..488dd0e 100644
--- a/libusbhost/usbhost.c
+++ b/libusbhost/usbhost.c
@@ -263,11 +263,12 @@
                 D("%s subdirectory %s: index: %d\n", (event->mask & IN_CREATE) ?
                         "new" : "gone", path, i);
                 if (i > 0 && i < MAX_USBFS_WD_COUNT) {
+                    int local_ret = 0;
                     if (event->mask & IN_CREATE) {
-                        ret = inotify_add_watch(context->fd, path,
+                        local_ret = inotify_add_watch(context->fd, path,
                                 IN_CREATE | IN_DELETE);
-                        if (ret >= 0)
-                            context->wds[i] = ret;
+                        if (local_ret >= 0)
+                            context->wds[i] = local_ret;
                         done = find_existing_devices_bus(path, context->cb_added,
                                 context->data);
                     } else if (event->mask & IN_DELETE) {
diff --git a/logcat/Android.mk b/logcat/Android.mk
index b5e27eb..f46a4de 100644
--- a/logcat/Android.mk
+++ b/logcat/Android.mk
@@ -7,7 +7,9 @@
 
 LOCAL_SHARED_LIBRARIES := liblog
 
-LOCAL_MODULE:= logcat
+LOCAL_MODULE := logcat
+
+LOCAL_CFLAGS := -Werror
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 995a42e..ea46345 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -281,8 +281,6 @@
     return 0;
 }
 
-extern "C" void logprint_run_tests(void);
-
 int main(int argc, char **argv)
 {
     int err;
@@ -306,11 +304,6 @@
 
     g_logformat = android_log_format_new();
 
-    if (argc == 2 && 0 == strcmp(argv[1], "--test")) {
-        logprint_run_tests();
-        exit(0);
-    }
-
     if (argc == 2 && 0 == strcmp(argv[1], "--help")) {
         android::show_help(argv[0]);
         exit(0);
@@ -496,9 +489,6 @@
                     android::g_logRotateSizeKBytes
                                 = DEFAULT_LOG_ROTATE_SIZE_KBYTES;
                 } else {
-                    long logRotateSize;
-                    char *lastDigit;
-
                     if (!isdigit(optarg[0])) {
                         fprintf(stderr,"Invalid parameter to -r\n");
                         android::show_help(argv[0]);
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index b07cc8b..2e8ae8b 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -392,7 +392,7 @@
     ASSERT_EQ(4, count);
 }
 
-static void caught_blocking(int signum)
+static void caught_blocking(int /*signum*/)
 {
     unsigned long long v = 0xDEADBEEFA55A0000ULL;
 
@@ -461,7 +461,7 @@
     EXPECT_EQ(1, signals);
 }
 
-static void caught_blocking_tail(int signum)
+static void caught_blocking_tail(int /*signum*/)
 {
     unsigned long long v = 0xA55ADEADBEEF0000ULL;
 
@@ -532,7 +532,7 @@
     EXPECT_EQ(1, signals);
 }
 
-static void caught_blocking_clear(int signum)
+static void caught_blocking_clear(int /*signum*/)
 {
     unsigned long long v = 0xDEADBEEFA55C0000ULL;
 
diff --git a/logd/Android.mk b/logd/Android.mk
index 0235478..9f4c64f 100644
--- a/logd/Android.mk
+++ b/logd/Android.mk
@@ -25,7 +25,7 @@
     libcutils \
     libutils
 
-LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Werror
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp
index 1f3fd0e..9d7d152 100644
--- a/logd/CommandListener.cpp
+++ b/logd/CommandListener.cpp
@@ -208,7 +208,6 @@
                                          int argc, char **argv) {
     setname();
     uid_t uid = cli->getUid();
-    gid_t gid = cli->getGid();
     if (clientHasLogCredentials(cli)) {
         uid = AID_ROOT;
     }
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index 6ff4d3a..8186cea 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -103,7 +103,7 @@
     // truncated message to the logs.
 
     logbuf->log(log_id, realtime, cred->uid, cred->pid, tid, msg,
-        (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
+        ((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
     reader->notifyNewLog();
 
     return true;
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index f44f567..81c9bab 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -31,6 +31,7 @@
         , mSizes(0)
         , mElements(0)
         , name(name)
+        , mGone(false)
 { }
 
 #ifdef DO_NOT_ERROR_IF_PIDSTATISTICS_USES_A_COPY_CONSTRUCTOR
@@ -41,6 +42,7 @@
         , mElementsTotal(copy->mElementsTotal)
         , mSizes(copy->mSizes)
         , mElements(copy->mElements)
+        , mGone(copy->mGone)
 { }
 #endif
 
@@ -48,6 +50,20 @@
     free(name);
 }
 
+bool PidStatistics::pidGone() {
+    if (mGone) {
+        return true;
+    }
+    if (pid == gone) {
+        return true;
+    }
+    if (kill(pid, 0) && (errno != EPERM)) {
+        mGone = true;
+        return true;
+    }
+    return false;
+}
+
 void PidStatistics::setName(char *new_name) {
     free(name);
     name = new_name;
@@ -63,7 +79,7 @@
 bool PidStatistics::subtract(unsigned short size) {
     mSizes -= size;
     --mElements;
-    return (mElements == 0) && kill(pid, 0) && (errno != EPERM);
+    return (mElements == 0) && pidGone();
 }
 
 void PidStatistics::addTotal(size_t size, size_t element) {
@@ -76,7 +92,7 @@
 // must call free to release return value
 char *PidStatistics::pidToName(pid_t pid) {
     char *retval = NULL;
-    if (pid != PidStatistics::gone) {
+    if (pid != gone) {
         char buffer[512];
         snprintf(buffer, sizeof(buffer), "/proc/%u/cmdline", pid);
         int fd = open(buffer, O_RDONLY);
@@ -376,8 +392,8 @@
 
     dgram_qlen_statistics = false;
     for(unsigned short bucket = 0; dgram_qlen(bucket); ++bucket) {
-        mMinimum[bucket].tv_sec = (uint32_t)-1;
-        mMinimum[bucket].tv_nsec = 999999999UL;
+        mMinimum[bucket].tv_sec = mMinimum[bucket].tv_sec_max;
+        mMinimum[bucket].tv_nsec = mMinimum[bucket].tv_nsec_max;
     }
 }
 
@@ -423,7 +439,7 @@
 }
 
 unsigned long long LogStatistics::minimum(unsigned short bucket) {
-    if (mMinimum[bucket].tv_sec == LONG_MAX) {
+    if (mMinimum[bucket].tv_sec == mMinimum[bucket].tv_sec_max) {
         return 0;
     }
     return mMinimum[bucket].nsec();
@@ -659,8 +675,7 @@
                             sizes, sizesTotal);
 
             android::String8 pd("");
-            pd.appendFormat("%u%c", pid,
-                            (kill(pid, 0) && (errno != EPERM)) ? '?' : ' ');
+            pd.appendFormat("%u%c", pid, p->pidGone() ? '?' : ' ');
 
             string.appendFormat("\n%-7s%-*s %-7s%s",
                                 line ? "" : android_log_id_to_name(i),
@@ -765,14 +780,15 @@
             spaces = 0;
 
             uid_t u = up->getUid();
-            pid_t p = (*pt)->getPid();
+            PidStatistics *pp = *pt;
+            pid_t p = pp->getPid();
 
             intermediate = string.format(oneline
                                              ? ((p == PidStatistics::gone)
                                                  ? "%d/?"
-                                                 : "%d/%d")
+                                                 : "%d/%d%c")
                                              : "%d",
-                                         u, p);
+                                         u, p, pp->pidGone() ? '?' : '\0');
             string.appendFormat(first ? "\n%-12s" : "%-12s",
                                 intermediate.string());
             intermediate.clear();
@@ -809,8 +825,8 @@
             size_t gone_els = 0;
 
             for(; pt != up->end(); ++pt) {
-                PidStatistics *pp = *pt;
-                pid_t p = pp->getPid();
+                pp = *pt;
+                p = pp->getPid();
 
                 // If a PID no longer has any current logs, and is not
                 // active anymore, skip & report totals for gone.
@@ -822,7 +838,7 @@
                     continue;
                 }
                 els = pp->elements();
-                bool gone = kill(p, 0) && (errno != EPERM);
+                bool gone = pp->pidGone();
                 if (gone && (els == 0)) {
                     // ToDo: garbage collection: move this statistical bucket
                     //       from its current UID/PID to UID/? (races and
diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h
index cd6ef7b..3733137 100644
--- a/logd/LogStatistics.h
+++ b/logd/LogStatistics.h
@@ -37,6 +37,7 @@
     size_t mElements;
 
     char *name;
+    bool mGone;
 
 public:
     static const pid_t gone = (pid_t) -1;
@@ -46,6 +47,7 @@
     ~PidStatistics();
 
     pid_t getPid() const { return pid; }
+    bool pidGone();
     char *getName() const { return name; }
     void setName(char *name);
 
diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp
index 731aff6..5b51b1f 100644
--- a/logd/tests/logd_test.cpp
+++ b/logd/tests/logd_test.cpp
@@ -196,8 +196,6 @@
 
     cp = strstr(cp, "Minimum time between log events per dgram_qlen:");
 
-    char *log_events_per_span = cp;
-
     if (cp) {
         while (*cp && (*cp != '\n')) {
             ++cp;
@@ -462,7 +460,7 @@
             dump_log_msg("user", &msg, 3, -1);
         }
 
-        alarm(0);
+        alarm(old_alarm);
         sigaction(SIGALRM, &old_sigaction, NULL);
 
         close(fd);
diff --git a/logwrapper/Android.mk b/logwrapper/Android.mk
index 917bf37..61b4659 100644
--- a/logwrapper/Android.mk
+++ b/logwrapper/Android.mk
@@ -11,6 +11,7 @@
 LOCAL_SHARED_LIBRARIES := libcutils liblog
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CFLAGS := -Werror
 include $(BUILD_STATIC_LIBRARY)
 
 # ========================================================
@@ -22,6 +23,7 @@
 LOCAL_WHOLE_STATIC_LIBRARIES := liblogwrap
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CFLAGS := -Werror
 include $(BUILD_SHARED_LIBRARY)
 
 # ========================================================
@@ -31,4 +33,5 @@
 LOCAL_SRC_FILES:= logwrapper.c
 LOCAL_MODULE := logwrapper
 LOCAL_STATIC_LIBRARIES := liblog liblogwrap libcutils
+LOCAL_CFLAGS := -Werror
 include $(BUILD_EXECUTABLE)
diff --git a/logwrapper/logwrap.c b/logwrapper/logwrap.c
index 4ca1db4..d47c9b5 100644
--- a/logwrapper/logwrap.c
+++ b/logwrapper/logwrap.c
@@ -104,8 +104,6 @@
 static int add_line_to_linear_buf(struct beginning_buf *b_buf,
                                    char *line, ssize_t line_len)
 {
-    size_t new_len;
-    char *new_buf;
     int full = 0;
 
     if ((line_len + b_buf->used_len) > b_buf->buf_size) {
@@ -124,7 +122,6 @@
 {
     ssize_t free_len;
     ssize_t needed_space;
-    char *new_buf;
     int cnt;
 
     if (e_buf->buf == NULL) {
@@ -192,7 +189,6 @@
 {
     char *line_start;
     char c;
-    int line_len;
     int i;
 
     line_start = buf;
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index b8fe716..eff24c3 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -91,3 +91,5 @@
 /sys/devices/virtual/input/input*   enable      0660  root   input
 /sys/devices/virtual/input/input*   poll_delay  0660  root   input
 /sys/devices/virtual/usb_composite/*   enable      0664  root   system
+/sys/devices/system/cpu/cpu*   cpufreq/scaling_max_freq   0664  system system
+/sys/devices/system/cpu/cpu*   cpufreq/scaling_min_freq   0664  system system