Merge "Add libc++ as static library"
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp
index 813a8a9..83b9238 100644
--- a/adb/client/commandline.cpp
+++ b/adb/client/commandline.cpp
@@ -790,6 +790,15 @@
service_string);
}
+static int adb_shell_noinput(int argc, const char** argv) {
+#if !defined(_WIN32)
+ unique_fd fd(adb_open("/dev/null", O_RDONLY));
+ CHECK_NE(STDIN_FILENO, fd.get());
+ dup2(fd.get(), STDIN_FILENO);
+#endif
+ return adb_shell(argc, argv);
+}
+
static int adb_sideload_legacy(const char* filename, int in_fd, int size) {
std::string error;
unique_fd out_fd(adb_connect(android::base::StringPrintf("sideload:%d", size), &error));
@@ -1612,7 +1621,7 @@
return adb_query_command(query);
}
else if (!strcmp(argv[0], "connect")) {
- if (argc != 2) error_exit("usage: adb connect HOST[:PORT>]");
+ if (argc != 2) error_exit("usage: adb connect HOST[:PORT]");
std::string query = android::base::StringPrintf("host:connect:%s", argv[1]);
return adb_query_command(query);
@@ -1711,7 +1720,7 @@
if (CanUseFeature(features, kFeatureRemountShell)) {
std::vector<const char*> args = {"shell"};
args.insert(args.cend(), argv, argv + argc);
- return adb_shell(args.size(), args.data());
+ return adb_shell_noinput(args.size(), args.data());
} else if (argc > 1) {
auto command = android::base::StringPrintf("%s:%s", argv[0], argv[1]);
return adb_connect_command(command);
diff --git a/fs_mgr/libsnapshot/OWNERS b/fs_mgr/libsnapshot/OWNERS
index 0cfa7e4..801c446 100644
--- a/fs_mgr/libsnapshot/OWNERS
+++ b/fs_mgr/libsnapshot/OWNERS
@@ -1,2 +1,3 @@
+balsini@google.com
dvander@google.com
elsk@google.com
diff --git a/init/reboot_utils.cpp b/init/reboot_utils.cpp
index dac0cf4..485188b 100644
--- a/init/reboot_utils.cpp
+++ b/init/reboot_utils.cpp
@@ -34,12 +34,16 @@
namespace init {
static std::string init_fatal_reboot_target = "bootloader";
+static bool init_fatal_panic = false;
void SetFatalRebootTarget() {
std::string cmdline;
android::base::ReadFileToString("/proc/cmdline", &cmdline);
cmdline = android::base::Trim(cmdline);
+ const char kInitFatalPanicString[] = "androidboot.init_fatal_panic=true";
+ init_fatal_panic = cmdline.find(kInitFatalPanicString) != std::string::npos;
+
const char kRebootTargetString[] = "androidboot.init_fatal_reboot_target=";
auto start_pos = cmdline.find(kRebootTargetString);
if (start_pos == std::string::npos) {
@@ -133,6 +137,9 @@
for (size_t i = 0; i < backtrace->NumFrames(); i++) {
LOG(ERROR) << backtrace->FormatFrameData(i);
}
+ if (init_fatal_panic) {
+ _exit(signal_number);
+ }
RebootSystem(ANDROID_RB_RESTART2, init_fatal_reboot_target);
}
diff --git a/liblog/fake_log_device.cpp b/liblog/fake_log_device.cpp
index 2ec6393..af9f18b 100644
--- a/liblog/fake_log_device.cpp
+++ b/liblog/fake_log_device.cpp
@@ -49,14 +49,6 @@
#define TRACE(...) ((void)0)
#endif
-static void FakeClose();
-static int FakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec, size_t nr);
-
-struct android_log_transport_write fakeLoggerWrite = {
- .close = FakeClose,
- .write = FakeWrite,
-};
-
typedef struct LogState {
bool initialized = false;
/* global minimum priority */
@@ -453,7 +445,7 @@
* tag (N bytes -- null-terminated ASCII string)
* message (N bytes -- null-terminated ASCII string)
*/
-static int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, size_t count) {
+int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, size_t count) {
/* Make sure that no-one frees the LogState while we're using it.
* Also guarantees that only one thread is in showLog() at a given
* time (if it matters).
@@ -519,7 +511,7 @@
* call is in the exit handler. Logging can continue in the exit handler to
* help debug HOST tools ...
*/
-static void FakeClose() {
+void FakeClose() {
auto lock = std::lock_guard{*fake_log_mutex};
memset(&log_state, 0, sizeof(log_state));
diff --git a/liblog/fake_log_device.h b/liblog/fake_log_device.h
index bd2256c..a2b40e2 100644
--- a/liblog/fake_log_device.h
+++ b/liblog/fake_log_device.h
@@ -18,16 +18,14 @@
#include <sys/types.h>
-#include "log_portability.h"
-#include "uio.h"
+#include <android/log.h>
-struct iovec;
+#include "log_portability.h"
__BEGIN_DECLS
-int fakeLogOpen(const char* pathName);
-int fakeLogClose(int fd);
-ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count);
+void FakeClose();
+int FakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec, size_t nr);
int __android_log_is_loggable(int prio, const char*, int def);
int __android_log_is_loggable_len(int prio, const char*, size_t, int def);
diff --git a/liblog/logd_reader.cpp b/liblog/logd_reader.cpp
index 6865c14..82ed6b2 100644
--- a/liblog/logd_reader.cpp
+++ b/liblog/logd_reader.cpp
@@ -35,8 +35,6 @@
#include <string>
-#include <cutils/sockets.h>
-#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
#include "logger.h"
diff --git a/liblog/logd_writer.cpp b/liblog/logd_writer.cpp
index 3c6eb69..f49c59e 100644
--- a/liblog/logd_writer.cpp
+++ b/liblog/logd_writer.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "logd_writer.h"
+
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -32,7 +34,6 @@
#include <shared_mutex>
-#include <cutils/sockets.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
@@ -41,14 +42,6 @@
#include "rwlock.h"
#include "uio.h"
-static int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
-static void LogdClose();
-
-struct android_log_transport_write logdLoggerWrite = {
- .close = LogdClose,
- .write = LogdWrite,
-};
-
static int logd_socket;
static RwLock logd_socket_lock;
@@ -90,7 +83,7 @@
OpenSocketLocked();
}
-static void LogdClose() {
+void LogdClose() {
auto lock = std::unique_lock{logd_socket_lock};
if (logd_socket > 0) {
close(logd_socket);
@@ -98,7 +91,7 @@
logd_socket = 0;
}
-static int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
+int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
ssize_t ret;
static const unsigned headerLength = 1;
struct iovec newVec[nr + headerLength];
@@ -119,7 +112,7 @@
}
/* logd, after initialization and priv drop */
- if (__android_log_uid() == AID_LOGD) {
+ if (getuid() == AID_LOGD) {
/*
* ignore log messages we send to ourself (logd).
* Such log messages are often generated by libraries we depend on
diff --git a/liblog/logd_writer.h b/liblog/logd_writer.h
new file mode 100644
index 0000000..41197b5
--- /dev/null
+++ b/liblog/logd_writer.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2020 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 <stddef.h>
+
+#include <android/log.h>
+
+int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
+void LogdClose();
diff --git a/liblog/logger.h b/liblog/logger.h
index 40d5fe5..078e778 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -18,7 +18,6 @@
#include <stdatomic.h>
-#include <cutils/list.h>
#include <log/log.h>
#include "log_portability.h"
@@ -26,13 +25,6 @@
__BEGIN_DECLS
-struct android_log_transport_write {
- void (*close)(); /* free up resources */
- /* write log to transport, returns number of bytes propagated, or -errno */
- int (*write)(log_id_t logId, struct timespec* ts, struct iovec* vec,
- size_t nr);
-};
-
struct logger_list {
atomic_int fd;
int mode;
@@ -56,18 +48,4 @@
return reinterpret_cast<uintptr_t>(logger) & LOGGER_LOGD;
}
-/* OS specific dribs and drabs */
-
-#if defined(_WIN32)
-#include <private/android_filesystem_config.h>
-typedef uint32_t uid_t;
-static inline uid_t __android_log_uid() {
- return AID_SYSTEM;
-}
-#else
-static inline uid_t __android_log_uid() {
- return getuid();
-}
-#endif
-
__END_DECLS
diff --git a/liblog/logger_read.cpp b/liblog/logger_read.cpp
index 0d383ff..a13ab36 100644
--- a/liblog/logger_read.cpp
+++ b/liblog/logger_read.cpp
@@ -27,8 +27,6 @@
#include <unistd.h>
#include <android/log.h>
-#include <cutils/list.h>
-#include <private/android_filesystem_config.h>
#include "log_portability.h"
#include "logd_reader.h"
diff --git a/liblog/logger_write.cpp b/liblog/logger_write.cpp
index d38b402..77be581 100644
--- a/liblog/logger_write.cpp
+++ b/liblog/logger_write.cpp
@@ -15,7 +15,6 @@
*/
#include <errno.h>
-#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
@@ -31,24 +30,18 @@
#include "logger.h"
#include "uio.h"
-#define LOG_BUF_SIZE 1024
-
#if (FAKE_LOG_DEVICE == 0)
-extern struct android_log_transport_write logdLoggerWrite;
-extern struct android_log_transport_write pmsgLoggerWrite;
-
-android_log_transport_write* android_log_write = &logdLoggerWrite;
-android_log_transport_write* android_log_persist_write = &pmsgLoggerWrite;
+#include "logd_writer.h"
+#include "pmsg_writer.h"
#else
-extern android_log_transport_write fakeLoggerWrite;
-
-android_log_transport_write* android_log_write = &fakeLoggerWrite;
-android_log_transport_write* android_log_persist_write = nullptr;
+#include "fake_log_device.h"
#endif
+#define LOG_BUF_SIZE 1024
+
#if defined(__ANDROID__)
static int check_log_uid_permissions() {
- uid_t uid = __android_log_uid();
+ uid_t uid = getuid();
/* Matches clientHasLogCredentials() in logd */
if ((uid != AID_SYSTEM) && (uid != AID_ROOT) && (uid != AID_LOG)) {
@@ -92,14 +85,12 @@
* Release any logger resources. A new log write will immediately re-acquire.
*/
void __android_log_close() {
- if (android_log_write != nullptr) {
- android_log_write->close();
- }
-
- if (android_log_persist_write != nullptr) {
- android_log_persist_write->close();
- }
-
+#if (FAKE_LOG_DEVICE == 0)
+ LogdClose();
+ PmsgClose();
+#else
+ FakeClose();
+#endif
}
static int write_to_log(log_id_t log_id, struct iovec* vec, size_t nr) {
@@ -158,17 +149,12 @@
ret = 0;
- if (android_log_write != nullptr) {
- ssize_t retval;
- retval = android_log_write->write(log_id, &ts, vec, nr);
- if (ret >= 0) {
- ret = retval;
- }
- }
-
- if (android_log_persist_write != nullptr) {
- android_log_persist_write->write(log_id, &ts, vec, nr);
- }
+#if (FAKE_LOG_DEVICE == 0)
+ ret = LogdWrite(log_id, &ts, vec, nr);
+ PmsgWrite(log_id, &ts, vec, nr);
+#else
+ ret = FakeWrite(log_id, &ts, vec, nr);
+#endif
errno = save_errno;
return ret;
diff --git a/liblog/pmsg_reader.cpp b/liblog/pmsg_reader.cpp
index 9390fec..64a92b7 100644
--- a/liblog/pmsg_reader.cpp
+++ b/liblog/pmsg_reader.cpp
@@ -23,7 +23,7 @@
#include <string.h>
#include <sys/types.h>
-#include <private/android_filesystem_config.h>
+#include <cutils/list.h>
#include <private/android_logger.h>
#include "logger.h"
diff --git a/liblog/pmsg_writer.cpp b/liblog/pmsg_writer.cpp
index 4f45780..319360f 100644
--- a/liblog/pmsg_writer.cpp
+++ b/liblog/pmsg_writer.cpp
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-/*
- * pmsg write handler
- */
+#include "pmsg_writer.h"
#include <errno.h>
#include <fcntl.h>
@@ -28,7 +26,6 @@
#include <shared_mutex>
#include <log/log_properties.h>
-#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
#include "log_portability.h"
@@ -36,14 +33,6 @@
#include "rwlock.h"
#include "uio.h"
-static void PmsgClose();
-static int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
-
-struct android_log_transport_write pmsgLoggerWrite = {
- .close = PmsgClose,
- .write = PmsgWrite,
-};
-
static int pmsg_fd;
static RwLock pmsg_fd_lock;
@@ -57,7 +46,7 @@
pmsg_fd = TEMP_FAILURE_RETRY(open("/dev/pmsg0", O_WRONLY | O_CLOEXEC));
}
-static void PmsgClose() {
+void PmsgClose() {
auto lock = std::unique_lock{pmsg_fd_lock};
if (pmsg_fd > 0) {
close(pmsg_fd);
@@ -65,7 +54,7 @@
pmsg_fd = 0;
}
-static int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
+int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
static const unsigned headerLength = 2;
struct iovec newVec[nr + headerLength];
android_log_header_t header;
@@ -123,7 +112,7 @@
pmsgHeader.magic = LOGGER_MAGIC;
pmsgHeader.len = sizeof(pmsgHeader) + sizeof(header);
- pmsgHeader.uid = __android_log_uid();
+ pmsgHeader.uid = getuid();
pmsgHeader.pid = getpid();
header.id = logId;
diff --git a/liblog/pmsg_writer.h b/liblog/pmsg_writer.h
new file mode 100644
index 0000000..d5e1a1c
--- /dev/null
+++ b/liblog/pmsg_writer.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2020 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 <stddef.h>
+
+#include <android/log.h>
+
+int PmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
+void PmsgClose();