Snap for 7299144 from 087b6880b76b9034c5b098d94b7b7a1208c2a40b to build-tools-release

Change-Id: I56ea22b2e756c6172639a759ad5e25979ec07061
diff --git a/include/android-base/logging.h b/include/android-base/logging.h
index 9064075..179ddf0 100644
--- a/include/android-base/logging.h
+++ b/include/android-base/logging.h
@@ -27,6 +27,8 @@
 //   LOG(INFO) << "Some text; " << some_value;
 //
 // Replace `INFO` with any severity from `enum LogSeverity`.
+// Most devices filter out VERBOSE logs by default, run
+// `adb shell setprop log.tag.<TAG> V` to see them in adb logcat.
 //
 // To log the result of a failed function and include the string
 // representation of `errno` at the end:
diff --git a/include/android-base/properties.h b/include/android-base/properties.h
index 0f208ec..021f466 100644
--- a/include/android-base/properties.h
+++ b/include/android-base/properties.h
@@ -97,8 +97,8 @@
 };
 #endif
 
-static inline int TimeoutMultiplier() {
-  return android::base::GetIntProperty("ro.timeout_multiplier", 1);
+static inline int HwTimeoutMultiplier() {
+  return android::base::GetIntProperty("ro.hw_timeout_multiplier", 1);
 }
 
 } // namespace base
diff --git a/include/android-base/silent_death_test.h b/include/android-base/silent_death_test.h
new file mode 100644
index 0000000..2aec890
--- /dev/null
+++ b/include/android-base/silent_death_test.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <signal.h>
+
+#include <gtest/gtest.h>
+
+#if !defined(__BIONIC__)
+#define sigaction64 sigaction
+#endif
+
+// Disables debuggerd stack traces to speed up death tests and make them less
+// noisy in logcat.
+//
+// Use `using my_DeathTest = SilentDeathTest;` instead of inheriting from
+// testing::Test yourself.
+class SilentDeathTest : public testing::Test {
+ protected:
+  virtual void SetUp() {
+    // Suppress debuggerd stack traces. Too slow.
+    for (int signo : {SIGABRT, SIGBUS, SIGSEGV, SIGSYS}) {
+      struct sigaction64 action = {.sa_handler = SIG_DFL};
+      sigaction64(signo, &action, &previous_);
+    }
+  }
+
+  virtual void TearDown() {
+    for (int signo : {SIGABRT, SIGBUS, SIGSEGV, SIGSYS}) {
+      sigaction64(signo, &previous_, nullptr);
+    }
+  }
+
+ private:
+  struct sigaction64 previous_;
+};
diff --git a/logging.cpp b/logging.cpp
index 54f3fcc..4942e2f 100644
--- a/logging.cpp
+++ b/logging.cpp
@@ -32,10 +32,6 @@
 #include <errno.h>
 #endif
 
-#if defined(__linux__)
-#include <sys/uio.h>
-#endif
-
 #include <atomic>
 #include <iostream>
 #include <limits>
@@ -255,20 +251,22 @@
 
   int level = kLogSeverityToKernelLogLevel[severity];
 
-  // The kernel's printk buffer is only 1024 bytes.
-  // TODO: should we automatically break up long lines into multiple lines?
-  // Or we could log but with something like "..." at the end?
-  char buf[1024] __attribute__((__uninitialized__));
+  // The kernel's printk buffer is only |1024 - PREFIX_MAX| bytes, where
+  // PREFIX_MAX could be 48 or 32.
+  // Reference: kernel/printk/printk.c
+  static constexpr int LOG_LINE_MAX = 1024 - 48;
+  char buf[LOG_LINE_MAX] __attribute__((__uninitialized__));
   size_t size = snprintf(buf, sizeof(buf), "<%d>%s: %.*s\n", level, tag, length, msg);
-  if (size > sizeof(buf)) {
-    size = snprintf(buf, sizeof(buf), "<%d>%s: %zu-byte message too long for printk\n",
-                    level, tag, size);
-  }
+  TEMP_FAILURE_RETRY(write(klog_fd, buf, std::min(size, sizeof(buf))));
 
-  iovec iov[1];
-  iov[0].iov_base = buf;
-  iov[0].iov_len = size;
-  TEMP_FAILURE_RETRY(writev(klog_fd, iov, 1));
+  if (size > sizeof(buf)) {
+    size_t truncated = size - sizeof(buf);
+    size = snprintf(
+        buf, sizeof(buf),
+        "<%d>%s: **previous message missing %zu bytes** %zu-byte message too long for printk\n",
+        level, tag, truncated, size);
+    TEMP_FAILURE_RETRY(write(klog_fd, buf, std::min(size, sizeof(buf))));
+  }
 }
 
 void KernelLogger(android::base::LogId, android::base::LogSeverity severity, const char* tag,