Merge "libfs_avb: Switch to range-for for GetHashtreeDescriptor"
diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h
index 4e6c879..c8d12cf 100644
--- a/base/include/android-base/unique_fd.h
+++ b/base/include/android-base/unique_fd.h
@@ -103,7 +103,7 @@
void reset(int new_value = -1) { reset(new_value, nullptr); }
int get() const { return fd_; }
- operator int() const { return get(); }
+ operator int() const { return get(); } // NOLINT
int release() __attribute__((warn_unused_result)) {
tag(fd_, this, nullptr);
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index 943fe10..9f6c550 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -523,13 +523,13 @@
}
// Mark the given block device as read-only, using the BLKROSET ioctl.
-bool fs_mgr_set_blk_ro(const std::string& blockdev) {
+bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly) {
unique_fd fd(TEMP_FAILURE_RETRY(open(blockdev.c_str(), O_RDONLY | O_CLOEXEC)));
if (fd < 0) {
return false;
}
- int ON = 1;
+ int ON = readonly;
return ioctl(fd, BLKROSET, &ON) == 0;
}
diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp
index 7dae7f1..6364ca9 100644
--- a/fs_mgr/fs_mgr_overlayfs.cpp
+++ b/fs_mgr/fs_mgr_overlayfs.cpp
@@ -277,6 +277,9 @@
// Don't check entries that are managed by vold.
if (entry->fs_mgr_flags.vold_managed || entry->fs_mgr_flags.recovery_only) return false;
+ // *_other doesn't want overlayfs.
+ if (entry->fs_mgr_flags.slot_select_other) return false;
+
// Only concerned with readonly partitions.
if (!(entry->flags & MS_RDONLY)) return false;
@@ -595,7 +598,11 @@
entry.mount_point = kScratchMountPoint;
entry.fs_type = mnt_type;
entry.flags = MS_RELATIME;
- if (readonly) entry.flags |= MS_RDONLY;
+ if (readonly) {
+ entry.flags |= MS_RDONLY;
+ } else {
+ fs_mgr_set_blk_ro(device_path, false);
+ }
auto save_errno = errno;
auto mounted = fs_mgr_do_mount_one(entry) == 0;
if (!mounted) {
@@ -653,6 +660,7 @@
return false;
}
command += " " + scratch_device;
+ fs_mgr_set_blk_ro(scratch_device, false);
auto ret = system(command.c_str());
if (ret) {
LERROR << "make " << mnt_type << " filesystem on " << scratch_device << " return=" << ret;
diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h
index 7d1159b..7842ca2 100644
--- a/fs_mgr/fs_mgr_priv.h
+++ b/fs_mgr/fs_mgr_priv.h
@@ -134,7 +134,7 @@
const std::chrono::milliseconds relative_timeout,
FileWaitMode wait_mode = FileWaitMode::Exists);
-bool fs_mgr_set_blk_ro(const std::string& blockdev);
+bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);
bool fs_mgr_update_for_slotselect(Fstab* fstab);
bool fs_mgr_is_device_unlocked();
const std::string& get_android_dt_dir();
diff --git a/fs_mgr/liblp/utility.cpp b/fs_mgr/liblp/utility.cpp
index 9ccabe9..ecf94a4 100644
--- a/fs_mgr/liblp/utility.cpp
+++ b/fs_mgr/liblp/utility.cpp
@@ -19,6 +19,11 @@
#include <sys/stat.h>
#include <unistd.h>
+#if defined(__linux__)
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#endif
+
#include <android-base/file.h>
#include <ext4_utils/ext4_utils.h>
#include <openssl/sha.h>
@@ -155,5 +160,16 @@
return true;
}
+bool SetBlockReadonly(int fd, bool readonly) {
+#if defined(__linux__)
+ int val = readonly;
+ return ioctl(fd, BLKROSET, &val) == 0;
+#else
+ (void)fd;
+ (void)readonly;
+ return true;
+#endif
+}
+
} // namespace fs_mgr
} // namespace android
diff --git a/fs_mgr/liblp/utility.h b/fs_mgr/liblp/utility.h
index 8b70919..e8b2ca9 100644
--- a/fs_mgr/liblp/utility.h
+++ b/fs_mgr/liblp/utility.h
@@ -29,6 +29,7 @@
#define LWARN LOG(WARNING) << LP_TAG
#define LINFO LOG(INFO) << LP_TAG
#define LERROR LOG(ERROR) << LP_TAG
+#define PWARNING PLOG(WARNING) << LP_TAG
#define PERROR PLOG(ERROR) << LP_TAG
namespace android {
@@ -88,6 +89,9 @@
bool UpdateBlockDevicePartitionName(LpMetadataBlockDevice* device, const std::string& name);
bool UpdatePartitionGroupName(LpMetadataPartitionGroup* group, const std::string& name);
+// Call BLKROSET ioctl on fd so that fd is readonly / read-writable.
+bool SetBlockReadonly(int fd, bool readonly);
+
} // namespace fs_mgr
} // namespace android
diff --git a/fs_mgr/liblp/writer.cpp b/fs_mgr/liblp/writer.cpp
index 454258b..54a1883 100644
--- a/fs_mgr/liblp/writer.cpp
+++ b/fs_mgr/liblp/writer.cpp
@@ -259,6 +259,12 @@
return false;
}
+ // On retrofit devices, super_partition is system_other and might be set to readonly by
+ // fs_mgr_set_blk_ro(). Unset readonly so that fd can be written to.
+ if (!SetBlockReadonly(fd.get(), false)) {
+ PWARNING << __PRETTY_FUNCTION__ << " BLKROSET 0 failed: " << super_partition;
+ }
+
// Write zeroes to the first block.
std::string zeroes(LP_PARTITION_RESERVED_BYTES, 0);
if (SeekFile64(fd, 0, SEEK_SET) < 0) {
diff --git a/init/first_stage_mount.cpp b/init/first_stage_mount.cpp
index b5ff658..71fe401 100644
--- a/init/first_stage_mount.cpp
+++ b/init/first_stage_mount.cpp
@@ -414,16 +414,32 @@
return entry.mount_point == "/system";
});
- if (system_partition != fstab_.end()) {
- if (!MountPartition(&(*system_partition))) {
- return false;
+ if (system_partition == fstab_.end()) return true;
+
+ bool mounted = false;
+ bool no_fail = false;
+ for (auto it = system_partition; it != fstab_.end();) {
+ if (it->mount_point != "/system") {
+ break;
}
-
- SwitchRoot((*system_partition).mount_point);
-
- fstab_.erase(system_partition);
+ no_fail |= (it->fs_mgr_flags).no_fail;
+ if (MountPartition(&(*it))) {
+ mounted = true;
+ SwitchRoot("/system");
+ break;
+ }
+ it++;
}
+ if (!mounted && !no_fail) {
+ LOG(ERROR) << "Failed to mount /system";
+ return false;
+ }
+
+ auto it = std::remove_if(fstab_.begin(), fstab_.end(),
+ [](const auto& entry) { return entry.mount_point == "/system"; });
+ fstab_.erase(it, fstab_.end());
+
return true;
}
@@ -444,14 +460,12 @@
if (skip_mount_point.empty()) {
continue;
}
- auto removing_entry =
- std::find_if(fstab_.begin(), fstab_.end(), [&skip_mount_point](const auto& entry) {
- return entry.mount_point == skip_mount_point;
- });
- if (removing_entry != fstab_.end()) {
- fstab_.erase(removing_entry);
- LOG(INFO) << "Skip mounting partition: " << skip_mount_point;
- }
+ auto it = std::remove_if(fstab_.begin(), fstab_.end(),
+ [&skip_mount_point](const auto& entry) {
+ return entry.mount_point == skip_mount_point;
+ });
+ fstab_.erase(it, fstab_.end());
+ LOG(INFO) << "Skip mounting partition: " << skip_mount_point;
}
return true;
@@ -462,8 +476,21 @@
if (!TrySkipMountingPartitions()) return false;
- for (auto& fstab_entry : fstab_) {
- if (!MountPartition(&fstab_entry) && !fstab_entry.fs_mgr_flags.no_fail) {
+ for (auto it = fstab_.begin(); it != fstab_.end();) {
+ bool mounted = false;
+ bool no_fail = false;
+ auto start_mount_point = it->mount_point;
+ do {
+ no_fail |= (it->fs_mgr_flags).no_fail;
+ if (!mounted)
+ mounted = MountPartition(&(*it));
+ else
+ LOG(INFO) << "Skip already-mounted partition: " << start_mount_point;
+ it++;
+ } while (it != fstab_.end() && it->mount_point == start_mount_point);
+
+ if (!mounted && !no_fail) {
+ LOG(ERROR) << start_mount_point << " mounted unsuccessfully but it is required!";
return false;
}
}
diff --git a/init/main.cpp b/init/main.cpp
index 868c409..2ce46ef 100644
--- a/init/main.cpp
+++ b/init/main.cpp
@@ -57,27 +57,22 @@
return ueventd_main(argc, argv);
}
- if (argc < 2) {
- return FirstStageMain(argc, argv);
+ if (argc > 1) {
+ if (!strcmp(argv[1], "subcontext")) {
+ android::base::InitLogging(argv, &android::base::KernelLogger);
+ const BuiltinFunctionMap function_map;
+
+ return SubcontextMain(argc, argv, &function_map);
+ }
+
+ if (!strcmp(argv[1], "selinux_setup")) {
+ return SetupSelinux(argv);
+ }
+
+ if (!strcmp(argv[1], "second_stage")) {
+ return SecondStageMain(argc, argv);
+ }
}
- if (!strcmp(argv[1], "subcontext")) {
- android::base::InitLogging(argv, &android::base::KernelLogger);
- const BuiltinFunctionMap function_map;
-
- return SubcontextMain(argc, argv, &function_map);
- }
-
- if (!strcmp(argv[1], "selinux_setup")) {
- return SetupSelinux(argv);
- }
-
- if (!strcmp(argv[1], "second_stage")) {
- return SecondStageMain(argc, argv);
- }
-
- android::base::InitLogging(argv, &android::base::KernelLogger);
-
- LOG(ERROR) << "Unknown argument passed to init '" << argv[1] << "'";
- return 1;
+ return FirstStageMain(argc, argv);
}
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 04ca207..e4da52c 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -432,24 +432,6 @@
selinux_android_restorecon("/dev/urandom", 0);
selinux_android_restorecon("/dev/__properties__", 0);
- selinux_android_restorecon("/plat_file_contexts", 0);
- selinux_android_restorecon("/nonplat_file_contexts", 0);
- selinux_android_restorecon("/vendor_file_contexts", 0);
- selinux_android_restorecon("/plat_property_contexts", 0);
- selinux_android_restorecon("/nonplat_property_contexts", 0);
- selinux_android_restorecon("/vendor_property_contexts", 0);
- selinux_android_restorecon("/plat_seapp_contexts", 0);
- selinux_android_restorecon("/nonplat_seapp_contexts", 0);
- selinux_android_restorecon("/vendor_seapp_contexts", 0);
- selinux_android_restorecon("/plat_service_contexts", 0);
- selinux_android_restorecon("/nonplat_service_contexts", 0);
- selinux_android_restorecon("/vendor_service_contexts", 0);
- selinux_android_restorecon("/plat_hwservice_contexts", 0);
- selinux_android_restorecon("/nonplat_hwservice_contexts", 0);
- selinux_android_restorecon("/vendor_hwservice_contexts", 0);
- selinux_android_restorecon("/sepolicy", 0);
- selinux_android_restorecon("/vndservice_contexts", 0);
-
selinux_android_restorecon("/dev/block", SELINUX_ANDROID_RESTORECON_RECURSE);
selinux_android_restorecon("/dev/device-mapper", 0);
diff --git a/liblog/.clang-format b/liblog/.clang-format
deleted file mode 100644
index 9db87a8..0000000
--- a/liblog/.clang-format
+++ /dev/null
@@ -1,9 +0,0 @@
-BasedOnStyle: Google
-AllowShortFunctionsOnASingleLine: false
-
-CommentPragmas: NOLINT:.*
-DerivePointerAlignment: false
-PointerAlignment: Left
-PenaltyExcessCharacter: 32
-
-Cpp11BracedListStyle: false
diff --git a/liblog/.clang-format b/liblog/.clang-format
new file mode 120000
index 0000000..fd0645f
--- /dev/null
+++ b/liblog/.clang-format
@@ -0,0 +1 @@
+../.clang-format-2
\ No newline at end of file
diff --git a/liblog/Android.bp b/liblog/Android.bp
index 4a165a0..619a94b 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -17,7 +17,6 @@
liblog_sources = [
"config_read.c",
"config_write.c",
- "local_logger.c",
"log_event_list.c",
"log_event_write.c",
"log_ratelimit.cpp",
diff --git a/liblog/README b/liblog/README
deleted file mode 100644
index 5a845be..0000000
--- a/liblog/README
+++ /dev/null
@@ -1,209 +0,0 @@
-LIBLOG(3) Android Internal NDK Programming Manual LIBLOG(3)
-
-
-
-NAME
- liblog - Android Internal NDK logger interfaces
-
-SYNOPSIS
- /*
- * Please limit to 24 characters for runtime is loggable,
- * 16 characters for persist is loggable, and logcat pretty
- * alignment with limit of 7 characters.
- */
- #define LOG_TAG "yourtag"
- #include <log/log.h>
-
- ALOG(android_priority, tag, format, ...)
- IF_ALOG(android_priority, tag)
- LOG_PRI(priority, tag, format, ...)
- LOG_PRI_VA(priority, tag, format, args)
- #define LOG_TAG NULL
- ALOGV(format, ...)
- SLOGV(format, ...)
- RLOGV(format, ...)
- ALOGV_IF(cond, format, ...)
- SLOGV_IF(cond, format, ...)
- RLOGV_IF(cond, format, ...)
- IF_ALOGC()
- ALOGD(format, ...)
- SLOGD(format, ...)
- RLOGD(format, ...)
- ALOGD_IF(cond, format, ...)
- SLOGD_IF(cond, format, ...)
- RLOGD_IF(cond, format, ...)
- IF_ALOGD()
- ALOGI(format, ...)
- SLOGI(format, ...)
- RLOGI(format, ...)
- ALOGI_IF(cond, format, ...)
- SLOGI_IF(cond, format, ...)
- RLOGI_IF(cond, format, ...)
- IF_ALOGI()
- ALOGW(format, ...)
- SLOGW(format, ...)
- RLOGW(format, ...)
- ALOGW_IF(cond, format, ...)
- SLOGW_IF(cond, format, ...)
- RLOGW_IF(cond, format, ...)
- IF_ALOGW()
- ALOGE(format, ...)
- SLOGE(format, ...)
- RLOGE(format, ...)
- ALOGE_IF(cond, format, ...)
- SLOGE_IF(cond, format, ...)
- RLOGE_IF(cond, format, ...)
- IF_ALOGE()
- LOG_FATAL(format, ...)
- LOG_ALWAYS_FATAL(format, ...)
- LOG_FATAL_IF(cond, format, ...)
- LOG_ALWAYS_FATAL_IF(cond, format, ...)
- ALOG_ASSERT(cond, format, ...)
- LOG_EVENT_INT(tag, value)
- LOG_EVENT_LONG(tag, value)
-
- clockid_t android_log_clockid()
-
- log_id_t android_logger_get_id(struct logger *logger)
- int android_logger_clear(struct logger *logger)
- int android_logger_get_log_size(struct logger *logger)
- int android_logger_get_log_readable_size(struct logger *logger)
- int android_logger_get_log_version(struct logger *logger)
-
- struct logger_list *android_logger_list_alloc(int mode,
- unsigned int tail,
- pid_t pid)
- struct logger *android_logger_open(struct logger_list *logger_list,
- log_id_t id)
- struct logger_list *android_logger_list_open(log_id_t id, int mode,
- unsigned int tail,
- pid_t pid)
- int android_logger_list_read(struct logger_list *logger_list,
- struct log_msg *log_msg)
- void android_logger_list_free(struct logger_list *logger_list)
-
- log_id_t android_name_to_log_id(const char *logName)
- const char *android_log_id_to_name(log_id_t log_id)
-
- android_log_context create_android_logger(uint32_t tag)
-
- int android_log_write_list_begin(android_log_context ctx)
- int android_log_write_list_end(android_log_context ctx)
-
- int android_log_write_int32(android_log_context ctx, int32_t value)
- int android_log_write_int64(android_log_context ctx, int64_t value)
- int android_log_write_string8(android_log_context ctx,
- const char *value)
- int android_log_write_string8_len(android_log_context ctx,
- const char *value, size_t maxlen)
- int android_log_write_float32(android_log_context ctx, float value)
-
- int android_log_write_list(android_log_context ctx,
- log_id_t id = LOG_ID_EVENTS)
-
- android_log_context create_android_log_parser(const char *msg,
- size_t len)
- android_log_list_element android_log_read_next(android_log_context ctx)
- android_log_list_element android_log_peek_next(android_log_context ctx)
-
- int android_log_destroy(android_log_context *ctx)
-
- #include <log/log_transport.h>
-
- int android_set_log_transport(int transport_flag)
- int android_get_log_transport()
-
- Link with -llog
-
-DESCRIPTION
- liblog represents an interface to the volatile Android Logging system
- for NDK (Native) applications and libraries. Interfaces for either
- writing or reading logs. The log buffers are divided up in Main, Sys‐
- tem, Radio and Events sub-logs.
-
- The logging interfaces are a series of macros, all of which can be
- overridden individually in order to control the verbosity of the appli‐
- cation or library. [ASR]LOG[VDIWE] calls are used to log to BAsic,
- System or Radio sub-logs in either the Verbose, Debug, Info, Warning or
- Error priorities. [ASR]LOG[VDIWE]_IF calls are used to perform thus
- based on a condition being true. IF_ALOG[VDIWE] calls are true if the
- current LOG_TAG is enabled at the specified priority. LOG_ALWAYS_FATAL
- is used to ALOG a message, then kill the process. LOG_FATAL call is a
- variant of LOG_ALWAYS_FATAL, only enabled in engineering, and not
- release builds. ALOG_ASSERT is used to ALOG a message if the condition
- is false; the condition is part of the logged message.
- LOG_EVENT_(INT|LONG) is used to drop binary content into the Events
- sub-log.
-
- The log reading interfaces permit opening the logs either singly or
- multiply, retrieving a log entry at a time in time sorted order,
- optionally limited to a specific pid and tail of the log(s) and finally
- a call closing the logs. A single log can be opened with android_log‐
- ger_list_open; or multiple logs can be opened with android_log‐
- ger_list_alloc, calling in turn the android_logger_open for each log
- id. Each entry can be retrieved with android_logger_list_read. The
- log(s) can be closed with android_logger_list_free. The logs should be
- opened with an ANDROID_LOG_RDONLY mode. ANDROID_LOG_NONBLOCK mode
- will report when the log reading is done with an EAGAIN error return
- code, otherwise the android_logger_list_read call will block for new
- entries.
-
- The ANDROID_LOG_WRAP mode flag to the android_logger_list_alloc_time
- signals logd to quiesce the reader until the buffer is about to prune
- at the start time then proceed to dumping content.
-
- The ANDROID_LOG_PSTORE mode flag to the android_logger_open is used to
- switch from the active logs to the persistent logs from before the last
- reboot.
-
- The value returned by android_logger_open can be used as a parameter to
- the android_logger_clear function to empty the sub-log. It is recom‐
- mended to only open log ANDROID_LOG_WRONLY in that case.
-
- The value returned by android_logger_open can be used as a parameter to
- the android_logger_get_log_(size|readable_size|version) to retrieve the
- sub-log maximum size, readable size and log buffer format protocol ver‐
- sion respectively. android_logger_get_id returns the id that was used
- when opening the sub-log. It is recommended to open the log
- ANDROID_LOG_RDONLY in these cases.
-
- android_set_log_transport() selects transport filters. Argument is
- either LOGGER_DEFAULT, LOGGER_LOGD, LOGGER_NULL or LOGGER_LOCAL. Log to
- logger daemon for default or logd, drop contents on floor, or log into
- local memory respectively. Both android_set_log_transport()
- and android_get_log_transport() return the current transport mask, or
- a negative errno for any problems.
-
-ERRORS
- If messages fail, a negative error code will be returned to the caller.
-
- The -ENOTCONN return code indicates that the logger daemon is stopped.
-
- The -EBADF return code indicates that the log access point can not be
- opened, or the log buffer id is out of range.
-
- For the -EAGAIN return code, this means that the logging message was
- temporarily backed-up either because of Denial Of Service (DOS) logging
- pressure from some chatty application or service in the Android system,
- or if too small of a value is set in /proc/sys/net/unix/max_dgram_qlen.
- To aid in diagnosing the occurence of this, a binary event from liblog
- will be sent to the log daemon once a new message can get through
- indicating how many messages were dropped as a result. Please take
- action to resolve the structural problems at the source.
-
- It is generally not advised for the caller to retry the -EAGAIN return
- code as this will only make the problem(s) worse and cause your
- application to temporarily drop to the logger daemon priority, BATCH
- scheduling policy and background task cgroup. If you require a group of
- messages to be passed atomically, merge them into one message with
- embedded newlines to the maximum length LOGGER_ENTRY_MAX_PAYLOAD.
-
- Other return codes from writing operation can be returned. Since the
- library retries on EINTR, -EINTR should never be returned.
-
-SEE ALSO
- syslogd(8), klogd, auditd(8)
-
-
-
- 08 Feb 2017 LIBLOG(3)
diff --git a/liblog/README.md b/liblog/README.md
new file mode 100644
index 0000000..98bee9f
--- /dev/null
+++ b/liblog/README.md
@@ -0,0 +1,176 @@
+Android liblog
+--------------
+
+Public Functions and Macros
+---------------------------
+
+ /*
+ * Please limit to 24 characters for runtime is loggable,
+ * 16 characters for persist is loggable, and logcat pretty
+ * alignment with limit of 7 characters.
+ */
+ #define LOG_TAG "yourtag"
+ #include <log/log.h>
+
+ ALOG(android_priority, tag, format, ...)
+ IF_ALOG(android_priority, tag)
+ LOG_PRI(priority, tag, format, ...)
+ LOG_PRI_VA(priority, tag, format, args)
+ #define LOG_TAG NULL
+ ALOGV(format, ...)
+ SLOGV(format, ...)
+ RLOGV(format, ...)
+ ALOGV_IF(cond, format, ...)
+ SLOGV_IF(cond, format, ...)
+ RLOGV_IF(cond, format, ...)
+ IF_ALOGC()
+ ALOGD(format, ...)
+ SLOGD(format, ...)
+ RLOGD(format, ...)
+ ALOGD_IF(cond, format, ...)
+ SLOGD_IF(cond, format, ...)
+ RLOGD_IF(cond, format, ...)
+ IF_ALOGD()
+ ALOGI(format, ...)
+ SLOGI(format, ...)
+ RLOGI(format, ...)
+ ALOGI_IF(cond, format, ...)
+ SLOGI_IF(cond, format, ...)
+ RLOGI_IF(cond, format, ...)
+ IF_ALOGI()
+ ALOGW(format, ...)
+ SLOGW(format, ...)
+ RLOGW(format, ...)
+ ALOGW_IF(cond, format, ...)
+ SLOGW_IF(cond, format, ...)
+ RLOGW_IF(cond, format, ...)
+ IF_ALOGW()
+ ALOGE(format, ...)
+ SLOGE(format, ...)
+ RLOGE(format, ...)
+ ALOGE_IF(cond, format, ...)
+ SLOGE_IF(cond, format, ...)
+ RLOGE_IF(cond, format, ...)
+ IF_ALOGE()
+ LOG_FATAL(format, ...)
+ LOG_ALWAYS_FATAL(format, ...)
+ LOG_FATAL_IF(cond, format, ...)
+ LOG_ALWAYS_FATAL_IF(cond, format, ...)
+ ALOG_ASSERT(cond, format, ...)
+ LOG_EVENT_INT(tag, value)
+ LOG_EVENT_LONG(tag, value)
+
+ clockid_t android_log_clockid()
+
+ log_id_t android_logger_get_id(struct logger *logger)
+ int android_logger_clear(struct logger *logger)
+ int android_logger_get_log_size(struct logger *logger)
+ int android_logger_get_log_readable_size(struct logger *logger)
+ int android_logger_get_log_version(struct logger *logger)
+
+ struct logger_list *android_logger_list_alloc(int mode, unsigned int tail, pid_t pid)
+ struct logger *android_logger_open(struct logger_list *logger_list, log_id_t id)
+ struct logger_list *android_logger_list_open(log_id_t id, int mode, unsigned int tail, pid_t pid)
+ int android_logger_list_read(struct logger_list *logger_list, struct log_msg *log_msg)
+ void android_logger_list_free(struct logger_list *logger_list)
+
+ log_id_t android_name_to_log_id(const char *logName)
+ const char *android_log_id_to_name(log_id_t log_id)
+
+ android_log_context create_android_logger(uint32_t tag)
+
+ int android_log_write_list_begin(android_log_context ctx)
+ int android_log_write_list_end(android_log_context ctx)
+
+ int android_log_write_int32(android_log_context ctx, int32_t value)
+ int android_log_write_int64(android_log_context ctx, int64_t value)
+ int android_log_write_string8(android_log_context ctx, const char *value)
+ int android_log_write_string8_len(android_log_context ctx, const char *value, size_t maxlen)
+ int android_log_write_float32(android_log_context ctx, float value)
+
+ int android_log_write_list(android_log_context ctx, log_id_t id = LOG_ID_EVENTS)
+
+ android_log_context create_android_log_parser(const char *msg, size_t len)
+ android_log_list_element android_log_read_next(android_log_context ctx)
+ android_log_list_element android_log_peek_next(android_log_context ctx)
+
+ int android_log_destroy(android_log_context *ctx)
+
+ #include <log/log_transport.h>
+
+ int android_set_log_transport(int transport_flag)
+ int android_get_log_transport()
+
+Description
+-----------
+
+liblog represents an interface to the volatile Android Logging system for NDK (Native) applications
+and libraries. Interfaces for either writing or reading logs. The log buffers are divided up in
+Main, System, Radio and Events sub-logs.
+
+The logging interfaces are a series of macros, all of which can be overridden individually in order
+to control the verbosity of the application or library. `[ASR]LOG[VDIWE]` calls are used to log to
+BAsic, System or Radio sub-logs in either the Verbose, Debug, Info, Warning or Error priorities.
+`[ASR]LOG[VDIWE]_IF` calls are used to perform thus based on a condition being true.
+`IF_ALOG[VDIWE]` calls are true if the current `LOG_TAG` is enabled at the specified priority.
+`LOG_ALWAYS_FATAL` is used to `ALOG` a message, then kill the process. `LOG_FATAL` call is a
+variant of `LOG_ALWAYS_FATAL`, only enabled in engineering, and not release builds. `ALOG_ASSERT`
+is used to `ALOG` a message if the condition is false; the condition is part of the logged message.
+`LOG_EVENT_(INT|LONG)` is used to drop binary content into the Events sub-log.
+
+The log reading interfaces permit opening the logs either singly or multiply, retrieving a log entry
+at a time in time sorted order, optionally limited to a specific pid and tail of the log(s) and
+finally a call closing the logs. A single log can be opened with `android_logger_list_open()`; or
+multiple logs can be opened with `android_logger_list_alloc()`, calling in turn the
+`android_logger_open()` for each log id. Each entry can be retrieved with
+`android_logger_list_read()`. The log(s) can be closed with `android_logger_list_free()`. The logs
+should be opened with an `ANDROID_LOG_RDONLY` mode. `ANDROID_LOG_NONBLOCK` mode will report when
+the log reading is done with an `EAGAIN` error return code, otherwise the
+`android_logger_list_read()` call will block for new entries.
+
+The `ANDROID_LOG_WRAP` mode flag to the `android_logger_list_alloc_time()` signals logd to quiesce
+the reader until the buffer is about to prune at the start time then proceed to dumping content.
+
+The `ANDROID_LOG_PSTORE` mode flag to the `android_logger_open()` is used to switch from the active
+logs to the persistent logs from before the last reboot.
+
+The value returned by `android_logger_open()` can be used as a parameter to the
+`android_logger_clear()` function to empty the sub-log. It is recommended to only open log
+`ANDROID_LOG_WRONLY` in that case.
+
+The value returned by `android_logger_open()` can be used as a parameter to the
+`android_logger_get_log_(size|readable_size|version)` to retrieve the sub-log maximum size, readable
+size and log buffer format protocol version respectively. `android_logger_get_id()` returns the id
+that was used when opening the sub-log. It is recommended to open the log `ANDROID_LOG_RDONLY` in
+these cases.
+
+`android_set_log_transport()` selects transport filters. Argument is either `LOGGER_DEFAULT`,
+`LOGGER_LOGD`, or `LOGGER_NULL`. Log to logger daemon for default or logd, or drop contents on floor
+respectively. `Both android_set_log_transport()` and `android_get_log_transport()` return the
+current transport mask, or a negative errno for any problems.
+
+Errors
+------
+
+If messages fail, a negative error code will be returned to the caller.
+
+The `-ENOTCONN` return code indicates that the logger daemon is stopped.
+
+The `-EBADF` return code indicates that the log access point can not be opened, or the log buffer id
+is out of range.
+
+For the `-EAGAIN` return code, this means that the logging message was temporarily backed-up either
+because of Denial Of Service (DOS) logging pressure from some chatty application or service in the
+Android system, or if too small of a value is set in /proc/sys/net/unix/max_dgram_qlen. To aid in
+diagnosing the occurence of this, a binary event from liblog will be sent to the log daemon once a
+new message can get through indicating how many messages were dropped as a result. Please take
+action to resolve the structural problems at the source.
+
+It is generally not advised for the caller to retry the `-EAGAIN` return code as this will only make
+the problem(s) worse and cause your application to temporarily drop to the logger daemon priority,
+BATCH scheduling policy and background task cgroup. If you require a group of messages to be passed
+atomically, merge them into one message with embedded newlines to the maximum length
+`LOGGER_ENTRY_MAX_PAYLOAD`.
+
+Other return codes from writing operation can be returned. Since the library retries on `EINTR`,
+`-EINTR` should never be returned.
diff --git a/liblog/config_read.c b/liblog/config_read.c
index ca80c80..51ffff6 100644
--- a/liblog/config_read.c
+++ b/liblog/config_read.c
@@ -55,12 +55,6 @@
}
LIBLOG_HIDDEN void __android_log_config_read() {
- if (__android_log_transport & LOGGER_LOCAL) {
- extern struct android_log_transport_read localLoggerRead;
-
- __android_log_add_transport(&__android_log_transport_read, &localLoggerRead);
- }
-
#if (FAKE_LOG_DEVICE == 0)
if ((__android_log_transport == LOGGER_DEFAULT) ||
(__android_log_transport & LOGGER_LOGD)) {
diff --git a/liblog/config_write.c b/liblog/config_write.c
index 0a8b52f..003ec8f 100644
--- a/liblog/config_write.c
+++ b/liblog/config_write.c
@@ -55,13 +55,6 @@
}
LIBLOG_HIDDEN void __android_log_config_write() {
- if (__android_log_transport & LOGGER_LOCAL) {
- extern struct android_log_transport_write localLoggerWrite;
-
- __android_log_add_transport(&__android_log_transport_write,
- &localLoggerWrite);
- }
-
if ((__android_log_transport == LOGGER_DEFAULT) ||
(__android_log_transport & LOGGER_LOGD)) {
#if (FAKE_LOG_DEVICE == 0)
diff --git a/liblog/include/log/log_transport.h b/liblog/include/log/log_transport.h
index 80b30db..8b02995 100644
--- a/liblog/include/log/log_transport.h
+++ b/liblog/include/log/log_transport.h
@@ -22,7 +22,7 @@
#define LOGGER_LOGD 0x01
#define LOGGER_KERNEL 0x02 /* Reserved/Deprecated */
#define LOGGER_NULL 0x04 /* Does not release resources of other selections */
-#define LOGGER_LOCAL 0x08 /* logs sent to local memory */
+#define LOGGER_RESERVED 0x08 /* Reserved, previously for logging to local memory */
#define LOGGER_STDERR 0x10 /* logs sent to stderr */
/* clang-format on */
diff --git a/liblog/local_logger.c b/liblog/local_logger.c
deleted file mode 100644
index 563cb3f..0000000
--- a/liblog/local_logger.c
+++ /dev/null
@@ -1,550 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <pthread.h>
-#if !defined(__MINGW32__)
-#include <pwd.h>
-#endif
-#include <log/uio.h>
-#include <sched.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include <cutils/list.h> /* template, no library dependency */
-#include <log/log_transport.h>
-#include <private/android_filesystem_config.h>
-#include <private/android_logger.h>
-#include <system/thread_defs.h>
-
-#include "config_read.h"
-#include "config_write.h"
-#include "log_portability.h"
-#include "logger.h"
-
-static const char baseServiceName[] = "android.logd";
-
-static int writeToLocalInit();
-static int writeToLocalAvailable(log_id_t logId);
-static void writeToLocalReset();
-static int writeToLocalWrite(log_id_t logId, struct timespec* ts,
- struct iovec* vec, size_t nr);
-
-LIBLOG_HIDDEN struct android_log_transport_write localLoggerWrite = {
- .node = { &localLoggerWrite.node, &localLoggerWrite.node },
- .context.priv = NULL,
- .name = "local",
- .available = writeToLocalAvailable,
- .open = writeToLocalInit,
- .close = writeToLocalReset,
- .write = writeToLocalWrite,
-};
-
-static int writeToLocalVersion(struct android_log_logger* logger,
- struct android_log_transport_context* transp);
-static int writeToLocalRead(struct android_log_logger_list* logger_list,
- struct android_log_transport_context* transp,
- struct log_msg* log_msg);
-static int writeToLocalPoll(struct android_log_logger_list* logger_list,
- struct android_log_transport_context* transp);
-static void writeToLocalClose(struct android_log_logger_list* logger_list,
- struct android_log_transport_context* transp);
-static int writeToLocalClear(struct android_log_logger* logger,
- struct android_log_transport_context* transp);
-static ssize_t writeToLocalGetSize(struct android_log_logger* logger,
- struct android_log_transport_context* transp);
-static ssize_t writeToLocalSetSize(
- struct android_log_logger* logger,
- struct android_log_transport_context* transp __unused, size_t size);
-static ssize_t writeToLocalGetReadbleSize(
- struct android_log_logger* logger,
- struct android_log_transport_context* transp);
-
-struct android_log_transport_read localLoggerRead = {
- .node = { &localLoggerRead.node, &localLoggerRead.node },
- .name = "local",
- .available = writeToLocalAvailable,
- .version = writeToLocalVersion,
- .read = writeToLocalRead,
- .poll = writeToLocalPoll,
- .close = writeToLocalClose,
- .clear = writeToLocalClear,
- .getSize = writeToLocalGetSize,
- .setSize = writeToLocalSetSize,
- .getReadableSize = writeToLocalGetReadbleSize,
- .getPrune = NULL,
- .setPrune = NULL,
- .getStats = NULL,
-};
-
-struct LogBufferElement {
- struct listnode node;
- log_id_t logId;
- pid_t tid;
- log_time timestamp;
- unsigned short len;
- char msg[];
-};
-
-static const size_t MAX_SIZE_DEFAULT = 32768;
-
-/*
- * Number of log buffers we support with the following assumption:
- * . . .
- * LOG_ID_SECURITY = 5, // security logs go to the system logs only
- * LOG_ID_KERNEL = 6, // place last, third-parties can not use it
- * LOG_ID_MAX
- * } log_id_t;
- *
- * Confirm the following should <log/log_id.h> be adjusted in the future.
- */
-#define NUMBER_OF_LOG_BUFFERS \
- ((LOG_ID_SECURITY == (LOG_ID_MAX - 2)) ? LOG_ID_SECURITY : LOG_ID_KERNEL)
-#define BLOCK_LOG_BUFFERS(id) \
- (((id) == LOG_ID_SECURITY) || ((id) == LOG_ID_KERNEL))
-
-static struct LogBuffer {
- struct listnode head;
- pthread_rwlock_t listLock;
- char* serviceName; /* Also indicates ready by having a value */
- /* Order and proximity important for memset */
- size_t number[NUMBER_OF_LOG_BUFFERS]; /* clear memset */
- size_t size[NUMBER_OF_LOG_BUFFERS]; /* clear memset */
- size_t totalSize[NUMBER_OF_LOG_BUFFERS]; /* init memset */
- size_t maxSize[NUMBER_OF_LOG_BUFFERS]; /* init MAX_SIZE_DEFAULT */
- struct listnode* last[NUMBER_OF_LOG_BUFFERS]; /* init &head */
-} logbuf = {
- .head = { &logbuf.head, &logbuf.head }, .listLock = PTHREAD_RWLOCK_INITIALIZER,
-};
-
-static void LogBufferInit(struct LogBuffer* log) {
- size_t i;
-
- pthread_rwlock_wrlock(&log->listLock);
- list_init(&log->head);
- memset(log->number, 0,
- sizeof(log->number) + sizeof(log->size) + sizeof(log->totalSize));
- for (i = 0; i < NUMBER_OF_LOG_BUFFERS; ++i) {
- log->maxSize[i] = MAX_SIZE_DEFAULT;
- log->last[i] = &log->head;
- }
-#ifdef __BIONIC__
- asprintf(&log->serviceName, "%s@%d:%d", baseServiceName, __android_log_uid(),
- getpid());
-#else
- char buffer[sizeof(baseServiceName) + 1 + 5 + 1 + 5 + 8];
- snprintf(buffer, sizeof(buffer), "%s@%d:%d", baseServiceName,
- __android_log_uid(), getpid());
- log->serviceName = strdup(buffer);
-#endif
- pthread_rwlock_unlock(&log->listLock);
-}
-
-static void LogBufferClear(struct LogBuffer* log) {
- size_t i;
- struct listnode* node;
-
- pthread_rwlock_wrlock(&log->listLock);
- memset(log->number, 0, sizeof(log->number) + sizeof(log->size));
- for (i = 0; i < NUMBER_OF_LOG_BUFFERS; ++i) {
- log->last[i] = &log->head;
- }
- while ((node = list_head(&log->head)) != &log->head) {
- struct LogBufferElement* element;
-
- element = node_to_item(node, struct LogBufferElement, node);
- list_remove(node);
- free(element);
- }
- pthread_rwlock_unlock(&log->listLock);
-}
-
-static inline void LogBufferFree(struct LogBuffer* log) {
- pthread_rwlock_wrlock(&log->listLock);
- free(log->serviceName);
- log->serviceName = NULL;
- pthread_rwlock_unlock(&log->listLock);
- LogBufferClear(log);
-}
-
-static int LogBufferLog(struct LogBuffer* log,
- struct LogBufferElement* element) {
- log_id_t logId = element->logId;
-
- pthread_rwlock_wrlock(&log->listLock);
- log->number[logId]++;
- log->size[logId] += element->len;
- log->totalSize[logId] += element->len;
- /* prune entry(s) until enough space is available */
- if (log->last[logId] == &log->head) {
- log->last[logId] = list_tail(&log->head);
- }
- while (log->size[logId] > log->maxSize[logId]) {
- struct listnode* node = log->last[logId];
- struct LogBufferElement* e;
- struct android_log_logger_list* logger_list;
-
- e = node_to_item(node, struct LogBufferElement, node);
- log->number[logId]--;
- log->size[logId] -= e->len;
- logger_list_rdlock();
- logger_list_for_each(logger_list) {
- struct android_log_transport_context* transp;
-
- transport_context_for_each(transp, logger_list) {
- if ((transp->transport == &localLoggerRead) &&
- (transp->context.node == node)) {
- if (node == &log->head) {
- transp->context.node = &log->head;
- } else {
- transp->context.node = node->next;
- }
- }
- }
- }
- logger_list_unlock();
- if (node != &log->head) {
- log->last[logId] = node->prev;
- }
- list_remove(node);
- LOG_ALWAYS_FATAL_IF(node == log->last[logId], "corrupted list");
- free(e);
- }
- /* add entry to list */
- list_add_head(&log->head, &element->node);
- /* ToDo: wake up all readers */
- pthread_rwlock_unlock(&log->listLock);
-
- return element->len;
-}
-
-/*
- * return zero if permitted to log directly to logd,
- * return 1 if binder server started and
- * return negative error number if failed to start binder server.
- */
-static int writeToLocalInit() {
- pthread_attr_t attr;
- struct LogBuffer* log;
-
- if (writeToLocalAvailable(LOG_ID_MAIN) < 0) {
- return -EPERM;
- }
-
- log = &logbuf;
- if (!log->serviceName) {
- LogBufferInit(log);
- }
-
- if (!log->serviceName) {
- LogBufferFree(log);
- return -ENOMEM;
- }
-
- return EPERM; /* successful local-only logging */
-}
-
-static void writeToLocalReset() {
- LogBufferFree(&logbuf);
-}
-
-static int writeToLocalAvailable(log_id_t logId) {
-#if !defined(__MINGW32__)
- uid_t uid;
-#endif
-
- if ((logId >= NUMBER_OF_LOG_BUFFERS) || BLOCK_LOG_BUFFERS(logId)) {
- return -EINVAL;
- }
-
-/* Android hard coded permitted, system goes to logd */
-#if !defined(__MINGW32__)
- if (__android_log_transport == LOGGER_DEFAULT) {
- uid = __android_log_uid();
- if ((uid < AID_APP) && (getpwuid(uid) != NULL)) {
- return -EPERM;
- }
- }
-#endif
-
- /* ToDo: Ask package manager for LOGD permissions */
- /* Assume we do _not_ have permissions to go to LOGD, so must go local */
- return 0;
-}
-
-static int writeToLocalWrite(log_id_t logId, struct timespec* ts,
- struct iovec* vec, size_t nr) {
- size_t len, i;
- struct LogBufferElement* element;
-
- if ((logId >= NUMBER_OF_LOG_BUFFERS) || BLOCK_LOG_BUFFERS(logId)) {
- return -EINVAL;
- }
-
- len = 0;
- for (i = 0; i < nr; ++i) {
- len += vec[i].iov_len;
- }
-
- if (len > LOGGER_ENTRY_MAX_PAYLOAD) {
- len = LOGGER_ENTRY_MAX_PAYLOAD;
- }
- element = (struct LogBufferElement*)calloc(
- 1, sizeof(struct LogBufferElement) + len + 1);
- if (!element) {
- return errno ? -errno : -ENOMEM;
- }
- element->timestamp.tv_sec = ts->tv_sec;
- element->timestamp.tv_nsec = ts->tv_nsec;
-#ifdef __BIONIC__
- element->tid = gettid();
-#else
- element->tid = getpid();
-#endif
- element->logId = logId;
- element->len = len;
-
- char* cp = element->msg;
- for (i = 0; i < nr; ++i) {
- size_t iov_len = vec[i].iov_len;
- if (iov_len > len) {
- iov_len = len;
- }
- memcpy(cp, vec[i].iov_base, iov_len);
- len -= iov_len;
- if (len == 0) {
- break;
- }
- cp += iov_len;
- }
-
- return LogBufferLog(&logbuf, element);
-}
-
-static int writeToLocalVersion(struct android_log_logger* logger __unused,
- struct android_log_transport_context* transp
- __unused) {
- return 3;
-}
-
-/* within reader lock, serviceName already validated */
-static struct listnode* writeToLocalNode(
- struct android_log_logger_list* logger_list,
- struct android_log_transport_context* transp) {
- struct listnode* node;
- unsigned logMask;
- unsigned int tail;
-
- node = transp->context.node;
- if (node) {
- return node;
- }
-
- if (!logger_list->tail) {
- return transp->context.node = &logbuf.head;
- }
-
- logMask = transp->logMask;
- tail = logger_list->tail;
-
- for (node = list_head(&logbuf.head); node != &logbuf.head; node = node->next) {
- struct LogBufferElement* element;
- log_id_t logId;
-
- element = node_to_item(node, struct LogBufferElement, node);
- logId = element->logId;
-
- if ((logMask & (1 << logId)) && !--tail) {
- node = node->next;
- break;
- }
- }
- return transp->context.node = node;
-}
-
-static int writeToLocalRead(struct android_log_logger_list* logger_list,
- struct android_log_transport_context* transp,
- struct log_msg* log_msg) {
- int ret;
- struct listnode* node;
- unsigned logMask;
-
- pthread_rwlock_rdlock(&logbuf.listLock);
- if (!logbuf.serviceName) {
- pthread_rwlock_unlock(&logbuf.listLock);
- return (logger_list->mode & ANDROID_LOG_NONBLOCK) ? -ENODEV : 0;
- }
-
- logMask = transp->logMask;
-
- node = writeToLocalNode(logger_list, transp);
-
- ret = 0;
-
- while (node != list_head(&logbuf.head)) {
- struct LogBufferElement* element;
- log_id_t logId;
-
- node = node->prev;
- element = node_to_item(node, struct LogBufferElement, node);
- logId = element->logId;
-
- if (logMask & (1 << logId)) {
- ret = log_msg->entry_v3.len = element->len;
- log_msg->entry_v3.hdr_size = sizeof(log_msg->entry_v3);
- log_msg->entry_v3.pid = getpid();
- log_msg->entry_v3.tid = element->tid;
- log_msg->entry_v3.sec = element->timestamp.tv_sec;
- log_msg->entry_v3.nsec = element->timestamp.tv_nsec;
- log_msg->entry_v3.lid = logId;
- memcpy(log_msg->entry_v3.msg, element->msg, ret);
- ret += log_msg->entry_v3.hdr_size;
- break;
- }
- }
-
- transp->context.node = node;
-
- /* ToDo: if blocking, and no entry, put reader to sleep */
- pthread_rwlock_unlock(&logbuf.listLock);
- return ret;
-}
-
-static int writeToLocalPoll(struct android_log_logger_list* logger_list,
- struct android_log_transport_context* transp) {
- int ret = (logger_list->mode & ANDROID_LOG_NONBLOCK) ? -ENODEV : 0;
-
- pthread_rwlock_rdlock(&logbuf.listLock);
-
- if (logbuf.serviceName) {
- unsigned logMask = transp->logMask;
- struct listnode* node = writeToLocalNode(logger_list, transp);
-
- ret = (node != list_head(&logbuf.head));
- if (ret) {
- do {
- ret = !!(logMask &
- (1 << (node_to_item(node->prev, struct LogBufferElement, node))
- ->logId));
- } while (!ret && ((node = node->prev) != list_head(&logbuf.head)));
- }
-
- transp->context.node = node;
- }
-
- pthread_rwlock_unlock(&logbuf.listLock);
-
- return ret;
-}
-
-static void writeToLocalClose(struct android_log_logger_list* logger_list
- __unused,
- struct android_log_transport_context* transp) {
- pthread_rwlock_wrlock(&logbuf.listLock);
- transp->context.node = list_head(&logbuf.head);
- pthread_rwlock_unlock(&logbuf.listLock);
-}
-
-static int writeToLocalClear(struct android_log_logger* logger,
- struct android_log_transport_context* unused
- __unused) {
- log_id_t logId = logger->logId;
- struct listnode *node, *n;
-
- if ((logId >= NUMBER_OF_LOG_BUFFERS) || BLOCK_LOG_BUFFERS(logId)) {
- return -EINVAL;
- }
-
- pthread_rwlock_wrlock(&logbuf.listLock);
- logbuf.number[logId] = 0;
- logbuf.last[logId] = &logbuf.head;
- list_for_each_safe(node, n, &logbuf.head) {
- struct LogBufferElement* element;
- element = node_to_item(node, struct LogBufferElement, node);
-
- if (logId == element->logId) {
- struct android_log_logger_list* logger_list;
-
- logger_list_rdlock();
- logger_list_for_each(logger_list) {
- struct android_log_transport_context* transp;
-
- transport_context_for_each(transp, logger_list) {
- if ((transp->transport == &localLoggerRead) &&
- (transp->context.node == node)) {
- transp->context.node = node->next;
- }
- }
- }
- logger_list_unlock();
- list_remove(node);
- free(element);
- }
- }
-
- pthread_rwlock_unlock(&logbuf.listLock);
-
- return 0;
-}
-
-static ssize_t writeToLocalGetSize(struct android_log_logger* logger,
- struct android_log_transport_context* transp
- __unused) {
- ssize_t ret = -EINVAL;
- log_id_t logId = logger->logId;
-
- if ((logId < NUMBER_OF_LOG_BUFFERS) && !BLOCK_LOG_BUFFERS(logId)) {
- pthread_rwlock_rdlock(&logbuf.listLock);
- ret = logbuf.maxSize[logId];
- pthread_rwlock_unlock(&logbuf.listLock);
- }
-
- return ret;
-}
-
-static ssize_t writeToLocalSetSize(
- struct android_log_logger* logger,
- struct android_log_transport_context* transp __unused, size_t size) {
- ssize_t ret = -EINVAL;
-
- if ((size > LOGGER_ENTRY_MAX_LEN) || (size < (4 * 1024 * 1024))) {
- log_id_t logId = logger->logId;
- if ((logId < NUMBER_OF_LOG_BUFFERS) || !BLOCK_LOG_BUFFERS(logId)) {
- pthread_rwlock_wrlock(&logbuf.listLock);
- ret = logbuf.maxSize[logId] = size;
- pthread_rwlock_unlock(&logbuf.listLock);
- }
- }
-
- return ret;
-}
-
-static ssize_t writeToLocalGetReadbleSize(
- struct android_log_logger* logger,
- struct android_log_transport_context* transp __unused) {
- ssize_t ret = -EINVAL;
- log_id_t logId = logger->logId;
-
- if ((logId < NUMBER_OF_LOG_BUFFERS) && !BLOCK_LOG_BUFFERS(logId)) {
- pthread_rwlock_rdlock(&logbuf.listLock);
- ret = logbuf.serviceName ? (ssize_t)logbuf.size[logId] : -EBADF;
- pthread_rwlock_unlock(&logbuf.listLock);
- }
-
- return ret;
-}
diff --git a/liblog/logger.h b/liblog/logger.h
index 246b33c..af83228 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -98,7 +98,6 @@
};
struct android_log_logger_list {
- struct listnode node;
struct listnode logger;
struct listnode transport;
int mode;
@@ -144,37 +143,6 @@
(logp) = \
node_to_item((logp)->node.next, struct android_log_logger, node))
-/*
- * Global list of log readers.
- *
- * Usage case: search out transport contexts for all readers
- */
-
-LIBLOG_HIDDEN struct listnode __android_log_readers;
-
-#if defined(_WIN32)
-#define logger_list_rdlock()
-#define logger_list_wrlock()
-#define logger_list_unlock()
-#else
-LIBLOG_HIDDEN pthread_rwlock_t __android_log_readers_lock;
-
-#define logger_list_rdlock() pthread_rwlock_rdlock(&__android_log_readers_lock)
-#define logger_list_wrlock() pthread_rwlock_wrlock(&__android_log_readers_lock)
-#define logger_list_unlock() pthread_rwlock_unlock(&__android_log_readers_lock)
-#endif
-
-/* Must be called with logger_list_rdlock() or logger_list_wrlock() held */
-#define logger_list_for_each(logger_list) \
- for ((logger_list) = node_to_item(&__android_log_readers, \
- struct android_log_logger_list, node); \
- (logger_list) != node_to_item(&__android_log_readers, \
- struct android_log_logger_list, node) && \
- (logger_list) != node_to_item((logger_list)->node.next, \
- struct android_log_logger_list, node); \
- (logger_list) = node_to_item((logger_list)->node.next, \
- struct android_log_logger_list, node))
-
/* OS specific dribs and drabs */
#if defined(_WIN32)
diff --git a/liblog/logger_read.c b/liblog/logger_read.c
index 0fd6efa..29ebaf7 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.c
@@ -213,13 +213,6 @@
LOGGER_LIST_FUNCTION(logger_list, -ENODEV, setPrune, buf, len);
}
-LIBLOG_HIDDEN struct listnode __android_log_readers = { &__android_log_readers,
- &__android_log_readers };
-#if !defined(_WIN32)
-LIBLOG_HIDDEN pthread_rwlock_t __android_log_readers_lock =
- PTHREAD_RWLOCK_INITIALIZER;
-#endif
-
LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_alloc(
int mode, unsigned int tail, pid_t pid) {
struct android_log_logger_list* logger_list;
@@ -235,10 +228,6 @@
logger_list->tail = tail;
logger_list->pid = pid;
- logger_list_wrlock();
- list_add_tail(&__android_log_readers, &logger_list->node);
- logger_list_unlock();
-
return (struct logger_list*)logger_list;
}
@@ -257,10 +246,6 @@
logger_list->start = start;
logger_list->pid = pid;
- logger_list_wrlock();
- list_add_tail(&__android_log_readers, &logger_list->node);
- logger_list_unlock();
-
return (struct logger_list*)logger_list;
}
@@ -472,10 +457,6 @@
return;
}
- logger_list_wrlock();
- list_remove(&logger_list_internal->node);
- logger_list_unlock();
-
while (!list_empty(&logger_list_internal->transport)) {
struct listnode* node = list_head(&logger_list_internal->transport);
struct android_log_transport_context* transp =
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index 2754e6e..6dcda9b 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -684,9 +684,9 @@
return retval;
}
- __android_log_transport &= LOGGER_LOCAL | LOGGER_LOGD | LOGGER_STDERR;
+ __android_log_transport &= LOGGER_LOGD | LOGGER_STDERR;
- transport_flag &= LOGGER_LOCAL | LOGGER_LOGD | LOGGER_STDERR;
+ transport_flag &= LOGGER_LOGD | LOGGER_STDERR;
if (__android_log_transport != transport_flag) {
__android_log_transport = transport_flag;
@@ -714,7 +714,7 @@
if (write_to_log == __write_to_log_null) {
ret = LOGGER_NULL;
} else {
- __android_log_transport &= LOGGER_LOCAL | LOGGER_LOGD | LOGGER_STDERR;
+ __android_log_transport &= LOGGER_LOGD | LOGGER_STDERR;
ret = __android_log_transport;
if ((write_to_log != __write_to_log_init) &&
(write_to_log != __write_to_log_daemon)) {
diff --git a/liblog/tests/Android.bp b/liblog/tests/Android.bp
index e6a9c0c..2c47fd6 100644
--- a/liblog/tests/Android.bp
+++ b/liblog/tests/Android.bp
@@ -54,9 +54,7 @@
srcs: [
"libc_test.cpp",
"liblog_test_default.cpp",
- "liblog_test_local.cpp",
"liblog_test_stderr.cpp",
- "liblog_test_stderr_local.cpp",
"log_id_test.cpp",
"log_radio_test.cpp",
"log_read_test.cpp",
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 383d0e7..2d0fc9b 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -52,22 +52,6 @@
#endif
#endif
-#if (!defined(USING_LOGGER_DEFAULT) || !defined(USING_LOGGER_LOCAL) || \
- !defined(USING_LOGGER_STDERR))
-#ifdef liblog // a binary clue that we are overriding the test names
-// Does not support log reading blocking feature yet
-// Does not support LOG_ID_SECURITY (unless we set LOGGER_LOCAL | LOGGER_LOGD)
-// Assume some common aspects are tested by USING_LOGGER_DEFAULT:
-// Does not need to _retest_ pmsg functionality
-// Does not need to _retest_ property handling as it is a higher function
-// Does not need to _retest_ event mapping functionality
-// Does not need to _retest_ ratelimit
-// Does not need to _retest_ logprint
-#define USING_LOGGER_LOCAL
-#else
-#define USING_LOGGER_DEFAULT
-#endif
-#endif
#ifdef USING_LOGGER_STDERR
#define SUPPORTS_END_TO_END 0
#else
@@ -175,7 +159,7 @@
#endif
TEST(liblog, __android_log_btwrite__android_logger_list_read) {
-#if (defined(__ANDROID__) || defined(USING_LOGGER_LOCAL))
+#ifdef __ANDROID__
#ifdef TEST_PREFIX
TEST_PREFIX
#endif
@@ -269,7 +253,7 @@
#endif
}
-#if (defined(__ANDROID__) || defined(USING_LOGGER_LOCAL))
+#ifdef __ANDROID__
static void print_transport(const char* prefix, int logger) {
static const char orstr[] = " | ";
@@ -297,16 +281,11 @@
fprintf(stderr, "%sLOGGER_NULL", prefix);
prefix = orstr;
}
- if (logger & LOGGER_LOCAL) {
- fprintf(stderr, "%sLOGGER_LOCAL", prefix);
- prefix = orstr;
- }
if (logger & LOGGER_STDERR) {
fprintf(stderr, "%sLOGGER_STDERR", prefix);
prefix = orstr;
}
- logger &= ~(LOGGER_LOGD | LOGGER_KERNEL | LOGGER_NULL | LOGGER_LOCAL |
- LOGGER_STDERR);
+ logger &= ~(LOGGER_LOGD | LOGGER_KERNEL | LOGGER_NULL | LOGGER_STDERR);
if (logger) {
fprintf(stderr, "%s0x%x", prefix, logger);
prefix = orstr;
@@ -321,7 +300,7 @@
// and behind us, to make us whole. We could incorporate a prefix and
// suffix test to make this standalone, but opted to not complicate this.
TEST(liblog, android_set_log_transport) {
-#if (defined(__ANDROID__) || defined(USING_LOGGER_LOCAL))
+#ifdef __ANDROID__
#ifdef TEST_PREFIX
TEST_PREFIX
#endif
@@ -632,7 +611,7 @@
buf_write_test("\n Hello World \n");
}
-#ifndef USING_LOGGER_LOCAL // requires blocking reader functionality
+#ifdef USING_LOGGER_DEFAULT // requires blocking reader functionality
#ifdef TEST_PREFIX
static unsigned signaled;
static log_time signal_time;
@@ -944,7 +923,7 @@
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif // !USING_LOGGER_LOCAL
+#endif // USING_LOGGER_DEFAULT
#ifdef TEST_PREFIX
static const char max_payload_tag[] = "TEST_max_payload_and_longish_tag_XXXX";
@@ -2417,7 +2396,7 @@
}
// Do not retest logger list handling
-#if (defined(TEST_PREFIX) || !defined(USING_LOGGER_LOCAL))
+#ifdef TEST_PREFIX
static int is_real_element(int type) {
return ((type == EVENT_TYPE_INT) || (type == EVENT_TYPE_LONG) ||
(type == EVENT_TYPE_STRING) || (type == EVENT_TYPE_FLOAT));
@@ -2572,7 +2551,7 @@
return 0;
}
-#endif // TEST_PREFIX || !USING_LOGGER_LOCAL
+#endif // TEST_PREFIX
#ifdef TEST_PREFIX
static const char* event_test_int32(uint32_t tag, size_t& expected_len) {
diff --git a/liblog/tests/liblog_test_local.cpp b/liblog/tests/liblog_test_local.cpp
deleted file mode 100644
index 451beca..0000000
--- a/liblog/tests/liblog_test_local.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <log/log_transport.h>
-#define liblog liblog_local
-#define TEST_LOGGER LOGGER_LOCAL
-#include "liblog_test.cpp"
diff --git a/liblog/tests/liblog_test_stderr_local.cpp b/liblog/tests/liblog_test_stderr_local.cpp
deleted file mode 100644
index bb5c7ae..0000000
--- a/liblog/tests/liblog_test_stderr_local.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <log/log_transport.h>
-#define liblog liblog_stderr_local
-#define TEST_LOGGER (LOGGER_LOCAL | LOGGER_STDERR)
-#include "liblog_test.cpp"
diff --git a/llkd/libllkd.cpp b/llkd/libllkd.cpp
index 3c295b5..b26ad4d 100644
--- a/llkd/libllkd.cpp
+++ b/llkd/libllkd.cpp
@@ -525,7 +525,7 @@
// NOTREACHED
return;
}
- ::sync();
+ // Wish could ::sync() here, if storage is locked up, we will not continue.
if (dump) {
// Show all locks that are held
android::base::WriteStringToFd("d", sysrqTriggerFd);