ndk: reverse course on android/log.h
am: 5c967da341

Change-Id: Id8cf37817462359131caaa6ddd786323b8218771
diff --git a/base/logging.cpp b/base/logging.cpp
index cbc3c8a..6357b4b 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -118,27 +118,32 @@
 namespace android {
 namespace base {
 
-static auto& logging_lock = *new std::mutex();
+static std::mutex& LoggingLock() {
+  static auto& logging_lock = *new std::mutex();
+  return logging_lock;
+}
 
+static LogFunction& Logger() {
 #ifdef __ANDROID__
-static auto& gLogger = *new LogFunction(LogdLogger());
+  static auto& logger = *new LogFunction(LogdLogger());
 #else
-static auto& gLogger = *new LogFunction(StderrLogger);
+  static auto& logger = *new LogFunction(StderrLogger);
 #endif
+  return logger;
+}
 
-static auto& gAborter = *new AbortFunction(DefaultAborter);
+static AbortFunction& Aborter() {
+  static auto& aborter = *new AbortFunction(DefaultAborter);
+  return aborter;
+}
+
+static std::string& ProgramInvocationName() {
+  static auto& programInvocationName = *new std::string(getprogname());
+  return programInvocationName;
+}
 
 static bool gInitialized = false;
 static LogSeverity gMinimumLogSeverity = INFO;
-static auto& gProgramInvocationName = *new std::unique_ptr<std::string>();
-
-static const char* ProgramInvocationName() {
-  if (gProgramInvocationName == nullptr) {
-    gProgramInvocationName.reset(new std::string(getprogname()));
-  }
-
-  return gProgramInvocationName->c_str();
-}
 
 #if defined(__linux__)
 void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
@@ -198,7 +203,7 @@
   static_assert(arraysize(log_characters) - 1 == FATAL + 1,
                 "Mismatch in size of log_characters and values in LogSeverity");
   char severity_char = log_characters[severity];
-  fprintf(stderr, "%s %c %s %5d %5d %s:%u] %s\n", ProgramInvocationName(),
+  fprintf(stderr, "%s %c %s %5d %5d %s:%u] %s\n", ProgramInvocationName().c_str(),
           severity_char, timestamp, getpid(), GetThreadId(), file, line, message);
 }
 
@@ -262,7 +267,8 @@
   // Linux to recover this, but we don't have that luxury on the Mac/Windows,
   // and there are a couple of argv[0] variants that are commonly used.
   if (argv != nullptr) {
-    gProgramInvocationName.reset(new std::string(basename(argv[0])));
+    std::lock_guard<std::mutex> lock(LoggingLock());
+    ProgramInvocationName() = basename(argv[0]);
   }
 
   const char* tags = getenv("ANDROID_LOG_TAGS");
@@ -307,13 +313,13 @@
 }
 
 void SetLogger(LogFunction&& logger) {
-  std::lock_guard<std::mutex> lock(logging_lock);
-  gLogger = std::move(logger);
+  std::lock_guard<std::mutex> lock(LoggingLock());
+  Logger() = std::move(logger);
 }
 
 void SetAborter(AbortFunction&& aborter) {
-  std::lock_guard<std::mutex> lock(logging_lock);
-  gAborter = std::move(aborter);
+  std::lock_guard<std::mutex> lock(LoggingLock());
+  Aborter() = std::move(aborter);
 }
 
 static const char* GetFileBasename(const char* file) {
@@ -403,7 +409,7 @@
 
   {
     // Do the actual logging with the lock held.
-    std::lock_guard<std::mutex> lock(logging_lock);
+    std::lock_guard<std::mutex> lock(LoggingLock());
     if (msg.find('\n') == std::string::npos) {
       LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(),
               data_->GetSeverity(), msg.c_str());
@@ -424,7 +430,7 @@
 
   // Abort if necessary.
   if (data_->GetSeverity() == FATAL) {
-    gAborter(msg.c_str());
+    Aborter()(msg.c_str());
   }
 }
 
@@ -434,8 +440,8 @@
 
 void LogMessage::LogLine(const char* file, unsigned int line, LogId id,
                          LogSeverity severity, const char* message) {
-  const char* tag = ProgramInvocationName();
-  gLogger(id, severity, tag, file, line, message);
+  const char* tag = ProgramInvocationName().c_str();
+  Logger()(id, severity, tag, file, line, message);
 }
 
 LogSeverity GetMinimumLogSeverity() {
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index 2d9c2ba..adb041b 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -594,3 +594,7 @@
 
   EXPECT_EQ(CountLineAborter::newline_count, 1U + 1U);  // +1 for final '\n'.
 }
+
+__attribute__((constructor)) void TestLoggingInConstructor() {
+  LOG(ERROR) << "foobar";
+}
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index f970e68..e7f1a07 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1648,8 +1648,7 @@
                     wants_reboot = false;
                     wants_reboot_bootloader = true;
                     skip(1);
-                }
-                if (!strcmp(*argv, "emergency")) {
+                } else if (!strcmp(*argv, "emergency")) {
                     wants_reboot = false;
                     wants_reboot_emergency = true;
                     skip(1);
diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk
index e321c17..956c702 100644
--- a/fs_mgr/Android.mk
+++ b/fs_mgr/Android.mk
@@ -18,11 +18,11 @@
 LOCAL_CLANG := true
 LOCAL_SANITIZE := integer
 LOCAL_SRC_FILES:= \
-    fs_mgr.c \
+    fs_mgr.cpp \
     fs_mgr_dm_ioctl.cpp \
-    fs_mgr_format.c \
-    fs_mgr_fstab.c \
-    fs_mgr_slotselect.c \
+    fs_mgr_format.cpp \
+    fs_mgr_fstab.cpp \
+    fs_mgr_slotselect.cpp \
     fs_mgr_verity.cpp \
     fs_mgr_avb.cpp \
     fs_mgr_avb_ops.cpp
@@ -48,7 +48,7 @@
 include $(CLEAR_VARS)
 LOCAL_CLANG := true
 LOCAL_SANITIZE := integer
-LOCAL_SRC_FILES:= fs_mgr_main.c
+LOCAL_SRC_FILES:= fs_mgr_main.cpp
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
 LOCAL_MODULE:= fs_mgr
 LOCAL_MODULE_TAGS := optional
diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.cpp
similarity index 95%
rename from fs_mgr/fs_mgr.c
rename to fs_mgr/fs_mgr.cpp
index 43fb9ea..207f42b 100644
--- a/fs_mgr/fs_mgr.c
+++ b/fs_mgr/fs_mgr.cpp
@@ -31,6 +31,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <android-base/unique_fd.h>
 #include <cutils/android_reboot.h>
 #include <cutils/partition_utils.h>
 #include <cutils/properties.h>
@@ -94,13 +95,13 @@
     return ret;
 }
 
-static void check_fs(char *blk_device, char *fs_type, char *target)
+static void check_fs(const char *blk_device, char *fs_type, char *target)
 {
     int status;
     int ret;
     long tmpmnt_flags = MS_NOATIME | MS_NOEXEC | MS_NOSUID;
     char tmpmnt_opts[64] = "errors=remount-ro";
-    char *e2fsck_argv[] = {
+    const char *e2fsck_argv[] = {
         E2FSCK_BIN,
 #ifndef TARGET_USES_MKE2FS // "-f" only for old ext4 generation tool
         "-f",
@@ -157,9 +158,12 @@
         } else {
             INFO("Running %s on %s\n", E2FSCK_BIN, blk_device);
 
-            ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv,
+            ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv),
+                                          const_cast<char **>(e2fsck_argv),
                                           &status, true, LOG_KLOG | LOG_FILE,
-                                          true, FSCK_LOG_FILE, NULL, 0);
+                                          true,
+                                          const_cast<char *>(FSCK_LOG_FILE),
+                                          NULL, 0);
 
             if (ret < 0) {
                 /* No need to check for error in fork, we can't really handle it now */
@@ -167,16 +171,18 @@
             }
         }
     } else if (!strcmp(fs_type, "f2fs")) {
-            char *f2fs_fsck_argv[] = {
+            const char *f2fs_fsck_argv[] = {
                     F2FS_FSCK_BIN,
                     "-a",
                     blk_device
             };
         INFO("Running %s -a %s\n", F2FS_FSCK_BIN, blk_device);
 
-        ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv,
+        ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv),
+                                      const_cast<char **>(f2fs_fsck_argv),
                                       &status, true, LOG_KLOG | LOG_FILE,
-                                      true, FSCK_LOG_FILE, NULL, 0);
+                                      true, const_cast<char *>(FSCK_LOG_FILE),
+                                      NULL, 0);
         if (ret < 0) {
             /* No need to check for error in fork, we can't really handle it now */
             ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN);
@@ -228,17 +234,18 @@
             ERROR("Not running %s on %s (executable not in system image)\n",
                   TUNE2FS_BIN, blk_device);
         } else {
-            char* arg1 = NULL;
-            char* arg2 = NULL;
+            const char* arg1 = nullptr;
+            const char* arg2 = nullptr;
             int status = 0;
             int ret = 0;
-            int fd = TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC));
+            android::base::unique_fd fd(
+                TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC)));
             if (fd >= 0) {
                 struct ext4_super_block sb;
                 ret = read_super_block(fd, &sb);
                 if (ret < 0) {
                     ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno));
-                    goto out;
+                    return force_check;
                 }
 
                 int has_quota = (sb.s_feature_ro_compat
@@ -247,7 +254,7 @@
 
                 if (has_quota == want_quota) {
                     INFO("Requested quota status is match on %s\n", blk_device);
-                    goto out;
+                    return force_check;
                 } else if (want_quota) {
                     INFO("Enabling quota on %s\n", blk_device);
                     arg1 = "-Oquota";
@@ -263,21 +270,20 @@
                 return force_check;
             }
 
-            char *tune2fs_argv[] = {
+            const char *tune2fs_argv[] = {
                 TUNE2FS_BIN,
                 arg1,
                 arg2,
                 blk_device,
             };
-            ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv), tune2fs_argv,
+            ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv),
+                                          const_cast<char **>(tune2fs_argv),
                                           &status, true, LOG_KLOG | LOG_FILE,
                                           true, NULL, NULL, 0);
             if (ret < 0) {
                 /* No need to check for error in fork, we can't really handle it now */
                 ERROR("Failed trying to run %s\n", TUNE2FS_BIN);
             }
-      out:
-            close(fd);
         }
     }
     return force_check;
@@ -300,13 +306,14 @@
             int status = 0;
             int ret = 0;
             unsigned long reserved_blocks = 0;
-            int fd = TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC));
+            android::base::unique_fd fd(
+                TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC)));
             if (fd >= 0) {
                 struct ext4_super_block sb;
                 ret = read_super_block(fd, &sb);
                 if (ret < 0) {
                     ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno));
-                    goto out;
+                    return;
                 }
                 reserved_blocks = rec->reserved_size / EXT4_BLOCK_SIZE(&sb);
                 unsigned long reserved_threshold = ext4_blocks_count(&sb) * 0.02;
@@ -317,7 +324,7 @@
 
                 if (ext4_r_blocks_count(&sb) == reserved_blocks) {
                     INFO("Have reserved same blocks\n");
-                    goto out;
+                    return;
                 }
             } else {
                 ERROR("Failed to open '%s': %s\n", blk_device, strerror(errno));
@@ -326,13 +333,14 @@
 
             char buf[16] = {0};
             snprintf(buf, sizeof (buf), "-r %lu", reserved_blocks);
-            char *tune2fs_argv[] = {
+            const char *tune2fs_argv[] = {
                 TUNE2FS_BIN,
                 buf,
                 blk_device,
             };
 
-            ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv), tune2fs_argv,
+            ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv),
+                                          const_cast<char **>(tune2fs_argv),
                                           &status, true, LOG_KLOG | LOG_FILE,
                                           true, NULL, NULL, 0);
 
@@ -340,8 +348,6 @@
                 /* No need to check for error in fork, we can't really handle it now */
                 ERROR("Failed trying to run %s\n", TUNE2FS_BIN);
             }
-      out:
-            close(fd);
         }
     }
 }
@@ -1024,9 +1030,9 @@
     int err = 0;
     int ret = 0;
     int status;
-    char *mkswap_argv[2] = {
+    const char *mkswap_argv[2] = {
         MKSWAP_BIN,
-        NULL
+        nullptr
     };
 
     if (!fstab) {
@@ -1075,7 +1081,8 @@
 
         /* Initialize the swap area */
         mkswap_argv[1] = fstab->recs[i].blk_device;
-        err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), mkswap_argv,
+        err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv),
+                                      const_cast<char **>(mkswap_argv),
                                       &status, true, LOG_KLOG, false, NULL,
                                       NULL, 0);
         if (err) {
diff --git a/fs_mgr/fs_mgr_format.c b/fs_mgr/fs_mgr_format.cpp
similarity index 99%
rename from fs_mgr/fs_mgr_format.c
rename to fs_mgr/fs_mgr_format.cpp
index 7c3b1ed..45298b3 100644
--- a/fs_mgr/fs_mgr_format.c
+++ b/fs_mgr/fs_mgr_format.cpp
@@ -34,8 +34,10 @@
 #include "fs_mgr_priv.h"
 #include "cryptfs.h"
 
+extern "C" {
 extern struct fs_info info;     /* magic global from ext4_utils */
 extern void reset_ext4fs_info();
+}
 
 static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
 {
diff --git a/fs_mgr/fs_mgr_fstab.c b/fs_mgr/fs_mgr_fstab.cpp
similarity index 98%
rename from fs_mgr/fs_mgr_fstab.c
rename to fs_mgr/fs_mgr_fstab.cpp
index b9d5617..23059df 100644
--- a/fs_mgr/fs_mgr_fstab.c
+++ b/fs_mgr/fs_mgr_fstab.cpp
@@ -326,9 +326,10 @@
     }
 
     /* Allocate and init the fstab structure */
-    fstab = calloc(1, sizeof(struct fstab));
+    fstab = static_cast<struct fstab *>(calloc(1, sizeof(struct fstab)));
     fstab->num_entries = entries;
-    fstab->recs = calloc(fstab->num_entries, sizeof(struct fstab_rec));
+    fstab->recs = static_cast<struct fstab_rec *>(
+        calloc(fstab->num_entries, sizeof(struct fstab_rec)));
 
     fseek(fstab_file, 0, SEEK_SET);
 
diff --git a/fs_mgr/fs_mgr_main.c b/fs_mgr/fs_mgr_main.cpp
similarity index 98%
rename from fs_mgr/fs_mgr_main.c
rename to fs_mgr/fs_mgr_main.cpp
index 4bfe202..f2901f3 100644
--- a/fs_mgr/fs_mgr_main.c
+++ b/fs_mgr/fs_mgr_main.cpp
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-#define _GNU_SOURCE
-
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -25,7 +23,7 @@
 #warning "libgen.h must not be included"
 #endif
 
-char *me = "";
+char *me = nullptr;
 
 static void usage(void)
 {
diff --git a/fs_mgr/fs_mgr_slotselect.c b/fs_mgr/fs_mgr_slotselect.cpp
similarity index 100%
rename from fs_mgr/fs_mgr_slotselect.c
rename to fs_mgr/fs_mgr_slotselect.cpp
diff --git a/fs_mgr/fs_mgr_verity.cpp b/fs_mgr/fs_mgr_verity.cpp
index e368a82..f6a14da 100644
--- a/fs_mgr/fs_mgr_verity.cpp
+++ b/fs_mgr/fs_mgr_verity.cpp
@@ -285,7 +285,7 @@
 
     // set next target boundary
     verity_params += strlen(verity_params) + 1;
-    verity_params = (char*)(((unsigned long)verity_params + 7) & ~8);
+    verity_params = (char*)(((uintptr_t)verity_params + 7) & ~7);
     tgt->next = verity_params - buffer;
 
     // send the ioctl to load the verity table
diff --git a/include/sysutils b/include/sysutils
new file mode 120000
index 0000000..1c8e85b
--- /dev/null
+++ b/include/sysutils
@@ -0,0 +1 @@
+../libsysutils/include/sysutils/
\ No newline at end of file
diff --git a/include/utils b/include/utils
new file mode 120000
index 0000000..e8476fd
--- /dev/null
+++ b/include/utils
@@ -0,0 +1 @@
+../libutils/include/utils/
\ No newline at end of file
diff --git a/libcutils/fs.c b/libcutils/fs.c
index 488fdfc..b253b1c 100644
--- a/libcutils/fs.c
+++ b/libcutils/fs.c
@@ -80,7 +80,7 @@
 create:
     create_result = prepare_as_dir
         ? TEMP_FAILURE_RETRY(mkdir(path, mode))
-        : TEMP_FAILURE_RETRY(open(path, O_CREAT | O_CLOEXEC | O_NOFOLLOW | O_RDONLY));
+        : TEMP_FAILURE_RETRY(open(path, O_CREAT | O_CLOEXEC | O_NOFOLLOW | O_RDONLY, 0644));
     if (create_result == -1) {
         if (errno != EEXIST) {
             ALOGE("Failed to %s(%s): %s",
diff --git a/libsysutils/Android.mk b/libsysutils/Android.mk
index 7bf53e3..330d6cb 100644
--- a/libsysutils/Android.mk
+++ b/libsysutils/Android.mk
@@ -21,5 +21,7 @@
         liblog \
         libnl
 
+LOCAL_EXPORT_C_INCLUDE_DIRS := system/core/libsysutils/include
+
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/include/sysutils/FrameworkClient.h b/libsysutils/include/sysutils/FrameworkClient.h
similarity index 100%
rename from include/sysutils/FrameworkClient.h
rename to libsysutils/include/sysutils/FrameworkClient.h
diff --git a/include/sysutils/FrameworkCommand.h b/libsysutils/include/sysutils/FrameworkCommand.h
similarity index 100%
rename from include/sysutils/FrameworkCommand.h
rename to libsysutils/include/sysutils/FrameworkCommand.h
diff --git a/include/sysutils/FrameworkListener.h b/libsysutils/include/sysutils/FrameworkListener.h
similarity index 100%
rename from include/sysutils/FrameworkListener.h
rename to libsysutils/include/sysutils/FrameworkListener.h
diff --git a/include/sysutils/List.h b/libsysutils/include/sysutils/List.h
similarity index 100%
rename from include/sysutils/List.h
rename to libsysutils/include/sysutils/List.h
diff --git a/include/sysutils/NetlinkEvent.h b/libsysutils/include/sysutils/NetlinkEvent.h
similarity index 100%
rename from include/sysutils/NetlinkEvent.h
rename to libsysutils/include/sysutils/NetlinkEvent.h
diff --git a/include/sysutils/NetlinkListener.h b/libsysutils/include/sysutils/NetlinkListener.h
similarity index 100%
rename from include/sysutils/NetlinkListener.h
rename to libsysutils/include/sysutils/NetlinkListener.h
diff --git a/include/sysutils/ServiceManager.h b/libsysutils/include/sysutils/ServiceManager.h
similarity index 100%
rename from include/sysutils/ServiceManager.h
rename to libsysutils/include/sysutils/ServiceManager.h
diff --git a/include/sysutils/SocketClient.h b/libsysutils/include/sysutils/SocketClient.h
similarity index 100%
rename from include/sysutils/SocketClient.h
rename to libsysutils/include/sysutils/SocketClient.h
diff --git a/include/sysutils/SocketClientCommand.h b/libsysutils/include/sysutils/SocketClientCommand.h
similarity index 100%
rename from include/sysutils/SocketClientCommand.h
rename to libsysutils/include/sysutils/SocketClientCommand.h
diff --git a/include/sysutils/SocketListener.h b/libsysutils/include/sysutils/SocketListener.h
similarity index 100%
rename from include/sysutils/SocketListener.h
rename to libsysutils/include/sysutils/SocketListener.h
diff --git a/libutils/Android.bp b/libutils/Android.bp
index 217b8c3..0c777b1 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -12,6 +12,17 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+cc_library_headers {
+    name: "libutils_headers",
+    host_supported: true,
+    export_include_dirs: ["include"],
+    target: {
+        windows: {
+           enabled: true,
+      },
+    },
+}
+
 cc_library {
     name: "libutils",
     host_supported: true,
@@ -42,6 +53,8 @@
 
     cflags: ["-Werror"],
     include_dirs: ["external/safe-iop/include"],
+    header_libs: ["libutils_headers"],
+    export_header_lib_headers: ["libutils_headers"],
 
     arch: {
         mips: {
diff --git a/include/utils/AndroidThreads.h b/libutils/include/utils/AndroidThreads.h
similarity index 100%
rename from include/utils/AndroidThreads.h
rename to libutils/include/utils/AndroidThreads.h
diff --git a/include/utils/Atomic.h b/libutils/include/utils/Atomic.h
similarity index 100%
rename from include/utils/Atomic.h
rename to libutils/include/utils/Atomic.h
diff --git a/include/utils/BitSet.h b/libutils/include/utils/BitSet.h
similarity index 100%
rename from include/utils/BitSet.h
rename to libutils/include/utils/BitSet.h
diff --git a/include/utils/BlobCache.h b/libutils/include/utils/BlobCache.h
similarity index 100%
rename from include/utils/BlobCache.h
rename to libutils/include/utils/BlobCache.h
diff --git a/include/utils/ByteOrder.h b/libutils/include/utils/ByteOrder.h
similarity index 100%
rename from include/utils/ByteOrder.h
rename to libutils/include/utils/ByteOrder.h
diff --git a/include/utils/CallStack.h b/libutils/include/utils/CallStack.h
similarity index 100%
rename from include/utils/CallStack.h
rename to libutils/include/utils/CallStack.h
diff --git a/include/utils/Compat.h b/libutils/include/utils/Compat.h
similarity index 100%
rename from include/utils/Compat.h
rename to libutils/include/utils/Compat.h
diff --git a/include/utils/Condition.h b/libutils/include/utils/Condition.h
similarity index 100%
rename from include/utils/Condition.h
rename to libutils/include/utils/Condition.h
diff --git a/include/utils/Debug.h b/libutils/include/utils/Debug.h
similarity index 100%
rename from include/utils/Debug.h
rename to libutils/include/utils/Debug.h
diff --git a/include/utils/Endian.h b/libutils/include/utils/Endian.h
similarity index 100%
rename from include/utils/Endian.h
rename to libutils/include/utils/Endian.h
diff --git a/include/utils/Errors.h b/libutils/include/utils/Errors.h
similarity index 100%
rename from include/utils/Errors.h
rename to libutils/include/utils/Errors.h
diff --git a/include/utils/FastStrcmp.h b/libutils/include/utils/FastStrcmp.h
similarity index 100%
rename from include/utils/FastStrcmp.h
rename to libutils/include/utils/FastStrcmp.h
diff --git a/include/utils/FileMap.h b/libutils/include/utils/FileMap.h
similarity index 100%
rename from include/utils/FileMap.h
rename to libutils/include/utils/FileMap.h
diff --git a/include/utils/Flattenable.h b/libutils/include/utils/Flattenable.h
similarity index 100%
rename from include/utils/Flattenable.h
rename to libutils/include/utils/Flattenable.h
diff --git a/include/utils/Functor.h b/libutils/include/utils/Functor.h
similarity index 100%
rename from include/utils/Functor.h
rename to libutils/include/utils/Functor.h
diff --git a/include/utils/JenkinsHash.h b/libutils/include/utils/JenkinsHash.h
similarity index 100%
rename from include/utils/JenkinsHash.h
rename to libutils/include/utils/JenkinsHash.h
diff --git a/include/utils/KeyedVector.h b/libutils/include/utils/KeyedVector.h
similarity index 100%
rename from include/utils/KeyedVector.h
rename to libutils/include/utils/KeyedVector.h
diff --git a/include/utils/LinearTransform.h b/libutils/include/utils/LinearTransform.h
similarity index 100%
rename from include/utils/LinearTransform.h
rename to libutils/include/utils/LinearTransform.h
diff --git a/include/utils/List.h b/libutils/include/utils/List.h
similarity index 100%
rename from include/utils/List.h
rename to libutils/include/utils/List.h
diff --git a/include/utils/Log.h b/libutils/include/utils/Log.h
similarity index 100%
rename from include/utils/Log.h
rename to libutils/include/utils/Log.h
diff --git a/include/utils/Looper.h b/libutils/include/utils/Looper.h
similarity index 100%
rename from include/utils/Looper.h
rename to libutils/include/utils/Looper.h
diff --git a/include/utils/LruCache.h b/libutils/include/utils/LruCache.h
similarity index 100%
rename from include/utils/LruCache.h
rename to libutils/include/utils/LruCache.h
diff --git a/include/utils/Mutex.h b/libutils/include/utils/Mutex.h
similarity index 100%
rename from include/utils/Mutex.h
rename to libutils/include/utils/Mutex.h
diff --git a/include/utils/NativeHandle.h b/libutils/include/utils/NativeHandle.h
similarity index 100%
rename from include/utils/NativeHandle.h
rename to libutils/include/utils/NativeHandle.h
diff --git a/include/utils/Printer.h b/libutils/include/utils/Printer.h
similarity index 100%
rename from include/utils/Printer.h
rename to libutils/include/utils/Printer.h
diff --git a/include/utils/ProcessCallStack.h b/libutils/include/utils/ProcessCallStack.h
similarity index 100%
rename from include/utils/ProcessCallStack.h
rename to libutils/include/utils/ProcessCallStack.h
diff --git a/include/utils/PropertyMap.h b/libutils/include/utils/PropertyMap.h
similarity index 100%
rename from include/utils/PropertyMap.h
rename to libutils/include/utils/PropertyMap.h
diff --git a/include/utils/RWLock.h b/libutils/include/utils/RWLock.h
similarity index 100%
rename from include/utils/RWLock.h
rename to libutils/include/utils/RWLock.h
diff --git a/include/utils/RefBase.h b/libutils/include/utils/RefBase.h
similarity index 100%
rename from include/utils/RefBase.h
rename to libutils/include/utils/RefBase.h
diff --git a/include/utils/Singleton.h b/libutils/include/utils/Singleton.h
similarity index 100%
rename from include/utils/Singleton.h
rename to libutils/include/utils/Singleton.h
diff --git a/include/utils/SortedVector.h b/libutils/include/utils/SortedVector.h
similarity index 100%
rename from include/utils/SortedVector.h
rename to libutils/include/utils/SortedVector.h
diff --git a/include/utils/StopWatch.h b/libutils/include/utils/StopWatch.h
similarity index 100%
rename from include/utils/StopWatch.h
rename to libutils/include/utils/StopWatch.h
diff --git a/include/utils/String16.h b/libutils/include/utils/String16.h
similarity index 100%
rename from include/utils/String16.h
rename to libutils/include/utils/String16.h
diff --git a/include/utils/String8.h b/libutils/include/utils/String8.h
similarity index 100%
rename from include/utils/String8.h
rename to libutils/include/utils/String8.h
diff --git a/include/utils/StrongPointer.h b/libutils/include/utils/StrongPointer.h
similarity index 100%
rename from include/utils/StrongPointer.h
rename to libutils/include/utils/StrongPointer.h
diff --git a/include/utils/SystemClock.h b/libutils/include/utils/SystemClock.h
similarity index 100%
rename from include/utils/SystemClock.h
rename to libutils/include/utils/SystemClock.h
diff --git a/include/utils/Thread.h b/libutils/include/utils/Thread.h
similarity index 100%
rename from include/utils/Thread.h
rename to libutils/include/utils/Thread.h
diff --git a/include/utils/ThreadDefs.h b/libutils/include/utils/ThreadDefs.h
similarity index 100%
rename from include/utils/ThreadDefs.h
rename to libutils/include/utils/ThreadDefs.h
diff --git a/include/utils/Timers.h b/libutils/include/utils/Timers.h
similarity index 100%
rename from include/utils/Timers.h
rename to libutils/include/utils/Timers.h
diff --git a/include/utils/Tokenizer.h b/libutils/include/utils/Tokenizer.h
similarity index 100%
rename from include/utils/Tokenizer.h
rename to libutils/include/utils/Tokenizer.h
diff --git a/include/utils/Trace.h b/libutils/include/utils/Trace.h
similarity index 100%
rename from include/utils/Trace.h
rename to libutils/include/utils/Trace.h
diff --git a/include/utils/TypeHelpers.h b/libutils/include/utils/TypeHelpers.h
similarity index 100%
rename from include/utils/TypeHelpers.h
rename to libutils/include/utils/TypeHelpers.h
diff --git a/include/utils/Unicode.h b/libutils/include/utils/Unicode.h
similarity index 100%
rename from include/utils/Unicode.h
rename to libutils/include/utils/Unicode.h
diff --git a/include/utils/Vector.h b/libutils/include/utils/Vector.h
similarity index 100%
rename from include/utils/Vector.h
rename to libutils/include/utils/Vector.h
diff --git a/include/utils/VectorImpl.h b/libutils/include/utils/VectorImpl.h
similarity index 100%
rename from include/utils/VectorImpl.h
rename to libutils/include/utils/VectorImpl.h
diff --git a/include/utils/misc.h b/libutils/include/utils/misc.h
similarity index 100%
rename from include/utils/misc.h
rename to libutils/include/utils/misc.h
diff --git a/include/utils/threads.h b/libutils/include/utils/threads.h
similarity index 100%
rename from include/utils/threads.h
rename to libutils/include/utils/threads.h
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index 337861e..10d9e39 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -171,8 +171,8 @@
         if (!ep) {
             continue;
         }
-        static const size_t tag_field_width = 7;
-        ep -= tag_field_width;
+        static const size_t pid_field_width = 7;
+        ep -= pid_field_width;
         *ep = '\0';
         return cp;
     }
@@ -184,14 +184,15 @@
 static size_t inject(ssize_t count) {
     if (count <= 0) return 0;
 
-    static const size_t retry = 3;
+    static const size_t retry = 4;
     size_t errors = retry;
     size_t num = 0;
     for(;;) {
         log_time ts(CLOCK_MONOTONIC);
         if (__android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)) >= 0) {
             if (++num >= (size_t)count) {
-                sleep(1); // let data settle end-to-end
+                // let data settle end-to-end
+                sleep(3);
                 return num;
             }
             errors = retry;
@@ -211,7 +212,7 @@
         return;
     }
 
-    int tries = 3; // in case run too soon after system start or buffer clear
+    int tries = 4; // in case run too soon after system start or buffer clear
     int count;
 
     do {
@@ -228,6 +229,8 @@
         while (fgetLongTime(buffer, sizeof(buffer), fp)) {
             if (strstr(buffer, " -0700") || strstr(buffer, " -0800")) {
                 ++count;
+            } else {
+                fprintf(stderr, "ts=\"%s\"\n", buffer + 2);
             }
         }
 
@@ -261,7 +264,7 @@
 }
 
 void do_tail(int num) {
-    int tries = 3; // in case run too soon after system start or buffer clear
+    int tries = 4; // in case run too soon after system start or buffer clear
     int count;
 
     do {
@@ -310,7 +313,7 @@
     char *first_timestamp = NULL;
     char *cp;
 
-    int tries = 3; // in case run too soon after system start or buffer clear
+    int tries = 4; // in case run too soon after system start or buffer clear
 
     // Do not be tempted to use -v usec because that increases the
     // chances of an occasional test failure by 1000 (see below).
diff --git a/rootdir/init.rc b/rootdir/init.rc
index d6ae6f0..9ab2333 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -482,7 +482,7 @@
     # Check any timezone data in /data is newer than the copy in /system, delete if not.
     exec - system system -- /system/bin/tzdatacheck /system/usr/share/zoneinfo /data/misc/zoneinfo
 
-    # If there is no fs-post-data action in the init.<device>.rc file, you
+    # If there is no post-fs-data action in the init.<device>.rc file, you
     # must uncomment this line, otherwise encrypted filesystems
     # won't work.
     # Set indication (checked by vold) that we have finished this action