Merge "adbd: don't leave zombies when subprocess creation fails."
diff --git a/bootstat/boot_event_record_store.cpp b/bootstat/boot_event_record_store.cpp
index 0133f5b..4dab92e 100644
--- a/bootstat/boot_event_record_store.cpp
+++ b/bootstat/boot_event_record_store.cpp
@@ -21,8 +21,8 @@
 #include <sys/stat.h>
 #include <utime.h>
 #include <cstdlib>
-#include <base/file.h>
-#include <base/logging.h>
+#include <android-base/file.h>
+#include <android-base/logging.h>
 
 namespace {
 
diff --git a/bootstat/boot_event_record_store.h b/bootstat/boot_event_record_store.h
index efe1e43..77978ef 100644
--- a/bootstat/boot_event_record_store.h
+++ b/bootstat/boot_event_record_store.h
@@ -21,7 +21,7 @@
 #include <string>
 #include <utility>
 #include <vector>
-#include <base/macros.h>
+#include <android-base/macros.h>
 #include <gtest/gtest_prod.h>
 
 // BootEventRecordStore manages the persistence of boot events to the record
diff --git a/bootstat/boot_event_record_store_test.cpp b/bootstat/boot_event_record_store_test.cpp
index 56af0a6..90874f5 100644
--- a/bootstat/boot_event_record_store_test.cpp
+++ b/bootstat/boot_event_record_store_test.cpp
@@ -21,8 +21,8 @@
 #include <unistd.h>
 #include <cstdint>
 #include <cstdlib>
-#include <base/file.h>
-#include <base/test_utils.h>
+#include <android-base/file.h>
+#include <android-base/test_utils.h>
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index a4cbf4e..a83f8ad 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -25,7 +25,7 @@
 #include <cstdio>
 #include <memory>
 #include <string>
-#include <base/logging.h>
+#include <android-base/logging.h>
 #include <log/log.h>
 #include "boot_event_record_store.h"
 #include "event_log_list_builder.h"
diff --git a/bootstat/event_log_list_builder.cpp b/bootstat/event_log_list_builder.cpp
index 017a7c5..7eb355a 100644
--- a/bootstat/event_log_list_builder.cpp
+++ b/bootstat/event_log_list_builder.cpp
@@ -18,7 +18,7 @@
 
 #include <cinttypes>
 #include <string>
-#include <base/logging.h>
+#include <android-base/logging.h>
 #include <log/log.h>
 
 namespace {
diff --git a/bootstat/event_log_list_builder.h b/bootstat/event_log_list_builder.h
index 52d623f..4e29b01 100644
--- a/bootstat/event_log_list_builder.h
+++ b/bootstat/event_log_list_builder.h
@@ -20,7 +20,7 @@
 #include <cstdint>
 #include <memory>
 
-#include <base/macros.h>
+#include <android-base/macros.h>
 
 // EventLogListBuilder provides a mechanism to build an EventLog list
 // consisting of int and string EventLog values.
diff --git a/bootstat/testrunner.cpp b/bootstat/testrunner.cpp
index ff8611e..79b61d1 100644
--- a/bootstat/testrunner.cpp
+++ b/bootstat/testrunner.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include <base/logging.h>
+#include <android-base/logging.h>
 #include <gtest/gtest.h>
 
 int main(int argc, char** argv) {
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index 32a65ea..4eff891 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -413,14 +413,19 @@
       if (errno == ENOENT) {
         if (mkdir(app_code_cache_dir, S_IRWXU | S_IRWXG | S_IXOTH) == -1) {
           ALOGW("Cannot create code cache directory %s: %s.", app_code_cache_dir, strerror(errno));
+          fprintf(stderr, "Cannot create code cache directory %s: %s.",
+              app_code_cache_dir, strerror(errno));
           ReleaseAppCodeCacheDir();
         }
       } else {
         ALOGW("Cannot stat code cache directory %s: %s.", app_code_cache_dir, strerror(errno));
+        fprintf(stderr, "Cannot stat code cache directory %s: %s.",
+            app_code_cache_dir, strerror(errno));
         ReleaseAppCodeCacheDir();
       }
     } else if (!S_ISDIR(st.st_mode)) {
       ALOGW("Code cache is not a directory %s.", app_code_cache_dir);
+      fprintf(stderr, "Code cache is not a directory %s.", app_code_cache_dir);
       ReleaseAppCodeCacheDir();
     }
 
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index cdf5d08..9e0d451 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -332,13 +332,21 @@
         }
     }
 
-    bool setLast = mLastSet[id] && (it == mLast[id]);
+    bool setLast[LOG_ID_MAX];
+    bool doSetLast = false;
+    log_id_for_each(i) {
+        doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]);
+    }
     it = mLogElements.erase(it);
-    if (setLast) {
-        if (it == mLogElements.end()) { // unlikely
-            mLastSet[id] = false;
-        } else {
-            mLast[id] = it;
+    if (doSetLast) {
+        log_id_for_each(i) {
+            if (setLast[i]) {
+                if (it == mLogElements.end()) { // unlikely
+                    mLastSet[i] = false;
+                } else {
+                    mLast[i] = it;
+                }
+            }
         }
     }
     if (coalesce) {
diff --git a/metricsd/Android.mk b/metricsd/Android.mk
index ed3fcbb..250c657 100644
--- a/metricsd/Android.mk
+++ b/metricsd/Android.mk
@@ -202,6 +202,9 @@
 LOCAL_SHARED_LIBRARIES := $(metricsd_shared_libraries)
 LOCAL_SRC_FILES := $(metricsd_tests_sources) $(metricsd_common)
 LOCAL_STATIC_LIBRARIES := libBionicGtestMain libgmock metricsd_protos metricsd_binder_proxy
+ifdef BRILLO
+LOCAL_MODULE_TAGS := debug
+endif
 include $(BUILD_NATIVE_TEST)
 
 # Unit tests for metrics_collector.
@@ -217,6 +220,9 @@
   $(metrics_collector_common)
 LOCAL_STATIC_LIBRARIES := libBionicGtestMain libgmock metricsd_binder_proxy \
   $(metrics_collector_static_libraries)
+ifdef BRILLO
+LOCAL_MODULE_TAGS := debug
+endif
 include $(BUILD_NATIVE_TEST)
 
 # Weave schema files
diff --git a/metricsd/uploader/upload_service.cc b/metricsd/uploader/upload_service.cc
index ab44b28..0dc59a4 100644
--- a/metricsd/uploader/upload_service.cc
+++ b/metricsd/uploader/upload_service.cc
@@ -90,6 +90,7 @@
 
 void UploadService::OnShutdown(int* exit_code) {
   metricsd_service_runner_.Stop();
+  PersistToDisk();
 }
 
 void UploadService::InitForTest(SystemProfileSetter* setter) {