Merge "Add license to ndk_headers."
diff --git a/adb/shell_service_protocol_test.cpp b/adb/shell_service_protocol_test.cpp
index a826035..b0fa3ed 100644
--- a/adb/shell_service_protocol_test.cpp
+++ b/adb/shell_service_protocol_test.cpp
@@ -86,9 +86,10 @@
namespace {
-// Returns true if the packet contains the given values.
+// Returns true if the packet contains the given values. `data` can't be null.
bool PacketEquals(const ShellProtocol* protocol, ShellProtocol::Id id,
const void* data, size_t data_length) {
+ // Note that passing memcmp null is bad, even if data_length is 0.
return (protocol->id() == id &&
protocol->data_length() == data_length &&
!memcmp(data, protocol->data(), data_length));
@@ -130,7 +131,8 @@
ASSERT_TRUE(write_protocol_->Write(id, 0));
ASSERT_TRUE(read_protocol_->Read());
- ASSERT_TRUE(PacketEquals(read_protocol_, id, nullptr, 0));
+ char buf[1];
+ ASSERT_TRUE(PacketEquals(read_protocol_, id, buf, 0));
}
// Tests exit code packets.
diff --git a/base/Android.bp b/base/Android.bp
index 88d8ad1..e6ad15b 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -73,6 +73,7 @@
"errors_test.cpp",
"file_test.cpp",
"logging_test.cpp",
+ "parsedouble_test.cpp",
"parseint_test.cpp",
"parsenetaddress_test.cpp",
"quick_exit_test.cpp",
diff --git a/base/include/android-base/parsedouble.h b/base/include/android-base/parsedouble.h
new file mode 100644
index 0000000..daa6902
--- /dev/null
+++ b/base/include/android-base/parsedouble.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ANDROID_BASE_PARSEDOUBLE_H
+#define ANDROID_BASE_PARSEDOUBLE_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <limits>
+
+namespace android {
+namespace base {
+
+// Parse double value in the string 's' and sets 'out' to that value.
+// Optionally allows the caller to define a 'min' and 'max' beyond which
+// otherwise valid values will be rejected. Returns boolean success.
+static inline bool ParseDouble(const char* s, double* out,
+ double min = std::numeric_limits<double>::lowest(),
+ double max = std::numeric_limits<double>::max()) {
+ errno = 0;
+ char* end;
+ double result = strtod(s, &end);
+ if (errno != 0 || s == end || *end != '\0') {
+ return false;
+ }
+ if (result < min || max < result) {
+ return false;
+ }
+ *out = result;
+ return true;
+}
+
+} // namespace base
+} // namespace android
+
+#endif // ANDROID_BASE_PARSEDOUBLE_H
diff --git a/base/logging.cpp b/base/logging.cpp
index dab86fe..cbc3c8a 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -45,7 +45,7 @@
// Headers for LogMessage::LogLine.
#ifdef __ANDROID__
-#include <android/log.h>
+#include <log/log.h>
#include <android/set_abort_message.h>
#else
#include <sys/types.h>
diff --git a/base/parsedouble_test.cpp b/base/parsedouble_test.cpp
new file mode 100644
index 0000000..8734c42
--- /dev/null
+++ b/base/parsedouble_test.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016 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 "android-base/parsedouble.h"
+
+#include <gtest/gtest.h>
+
+TEST(parsedouble, smoke) {
+ double d;
+ ASSERT_FALSE(android::base::ParseDouble("", &d));
+ ASSERT_FALSE(android::base::ParseDouble("x", &d));
+ ASSERT_FALSE(android::base::ParseDouble("123.4x", &d));
+
+ ASSERT_TRUE(android::base::ParseDouble("123.4", &d));
+ ASSERT_DOUBLE_EQ(123.4, d);
+ ASSERT_TRUE(android::base::ParseDouble("-123.4", &d));
+ ASSERT_DOUBLE_EQ(-123.4, d);
+
+ ASSERT_TRUE(android::base::ParseDouble("0", &d, 0.0));
+ ASSERT_DOUBLE_EQ(0.0, d);
+ ASSERT_FALSE(android::base::ParseDouble("0", &d, 1e-9));
+ ASSERT_FALSE(android::base::ParseDouble("3.0", &d, -1.0, 2.0));
+ ASSERT_TRUE(android::base::ParseDouble("1.0", &d, 0.0, 2.0));
+ ASSERT_DOUBLE_EQ(1.0, d);
+}
diff --git a/bootstat/event_log_list_builder.cpp b/bootstat/event_log_list_builder.cpp
index a6af13e..ce540a0 100644
--- a/bootstat/event_log_list_builder.cpp
+++ b/bootstat/event_log_list_builder.cpp
@@ -20,7 +20,7 @@
#include <memory>
#include <string>
-#include <android/log.h>
+#include <log/log.h>
#include <android-base/logging.h>
namespace {
diff --git a/bootstat/event_log_list_builder_test.cpp b/bootstat/event_log_list_builder_test.cpp
index 8f7f323..25909b0 100644
--- a/bootstat/event_log_list_builder_test.cpp
+++ b/bootstat/event_log_list_builder_test.cpp
@@ -18,9 +18,9 @@
#include <inttypes.h>
-#include <android/log.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <log/log.h>
using testing::ElementsAreArray;
diff --git a/bootstat/histogram_logger.cpp b/bootstat/histogram_logger.cpp
index 3144d8b..4f2386c 100644
--- a/bootstat/histogram_logger.cpp
+++ b/bootstat/histogram_logger.cpp
@@ -19,8 +19,8 @@
#include <cstdlib>
#include <memory>
-#include <android/log.h>
#include <android-base/logging.h>
+#include <log/log.h>
#include "event_log_list_builder.h"
diff --git a/debuggerd/crasher.cpp b/debuggerd/crasher.cpp
index cfcc26e..3db67b3 100644
--- a/debuggerd/crasher.cpp
+++ b/debuggerd/crasher.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright 2006, 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.
+ */
+
+#define LOG_TAG "crasher"
+
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp
index b8a62a5..5ae66db 100644
--- a/debuggerd/debuggerd.cpp
+++ b/debuggerd/debuggerd.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "debuggerd"
+
#include <arpa/inet.h>
#include <dirent.h>
#include <elf.h>
diff --git a/debuggerd/getevent.cpp b/debuggerd/getevent.cpp
index dfa7bec..dbb878a 100644
--- a/debuggerd/getevent.cpp
+++ b/debuggerd/getevent.cpp
@@ -26,6 +26,7 @@
#include <sys/ioctl.h>
#include <sys/limits.h>
#include <sys/poll.h>
+#include <unistd.h>
#include <memory>
diff --git a/debuggerd/signal_sender.cpp b/debuggerd/signal_sender.cpp
index 3adbef2..7fe4dee 100644
--- a/debuggerd/signal_sender.cpp
+++ b/debuggerd/signal_sender.cpp
@@ -14,7 +14,10 @@
* limitations under the License.
*/
+#define LOG_TAG "debuggerd-signal"
+
#include <errno.h>
+#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
diff --git a/debuggerd/test/log_fake.cpp b/debuggerd/test/log_fake.cpp
index 59910ad..3336bcb 100644
--- a/debuggerd/test/log_fake.cpp
+++ b/debuggerd/test/log_fake.cpp
@@ -19,8 +19,8 @@
#include <string>
-#include <android/log.h>
#include <android-base/stringprintf.h>
+#include <log/log.h>
// Forward declarations.
class Backtrace;
diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp
index e2461c0..459e4cc 100644
--- a/debuggerd/tombstone.cpp
+++ b/debuggerd/tombstone.cpp
@@ -36,6 +36,7 @@
#include <backtrace/Backtrace.h>
#include <backtrace/BacktraceMap.h>
#include <cutils/properties.h>
+#include <log/log.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/debuggerd/utility.cpp b/debuggerd/utility.cpp
index e334e71..419d36c 100644
--- a/debuggerd/utility.cpp
+++ b/debuggerd/utility.cpp
@@ -27,9 +27,9 @@
#include <string>
-#include <android/log.h>
#include <android-base/stringprintf.h>
#include <backtrace/Backtrace.h>
+#include <log/log.h>
// Whitelist output desired in the logcat output.
bool is_allowed_in_logcat(enum logtype ltype) {
diff --git a/include/log/logger.h b/include/log/logger.h
index 46587fb..65b38de 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -17,7 +17,7 @@
#include <string>
#endif
-#include <android/log.h>
+#include <log/log.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/private/android_logger.h b/include/private/android_logger.h
index 94095d1..02764d3 100644
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -21,6 +21,7 @@
/* Android private interfaces */
+#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
@@ -132,6 +133,20 @@
int __android_log_is_debuggable();
+#define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
+#define BOOL_DEFAULT_FALSE 0x0 /* false if property not present */
+#define BOOL_DEFAULT_TRUE 0x1 /* true if property not present */
+#define BOOL_DEFAULT_FLAG_PERSIST 0x2 /* <key>, persist.<key>, ro.<key> */
+#define BOOL_DEFAULT_FLAG_ENG 0x4 /* off for user */
+#define BOOL_DEFAULT_FLAG_SVELTE 0x8 /* off for low_ram */
+bool __android_logger_property_get_bool(const char *key, int flag);
+
+#define LOG_BUFFER_SIZE (256 * 1024) /* Tuned with ro.logd.size per-platform */
+#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
+#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
+unsigned long __android_logger_get_buffer_size(log_id_t logId);
+bool __android_logger_valid_buffer_size(unsigned long value);
+
#if defined(__cplusplus)
}
#endif
diff --git a/include/utils/Log.h b/include/utils/Log.h
index 6ef3fa3..5276a49 100644
--- a/include/utils/Log.h
+++ b/include/utils/Log.h
@@ -30,7 +30,7 @@
#include <sys/types.h>
-#include <android/log.h>
+#include <log/log.h>
#ifdef __cplusplus
diff --git a/include/utils/SortedVector.h b/include/utils/SortedVector.h
index 9f2ec02..86f3496 100644
--- a/include/utils/SortedVector.h
+++ b/include/utils/SortedVector.h
@@ -21,7 +21,7 @@
#include <stdint.h>
#include <sys/types.h>
-#include <android/log.h>
+#include <log/log.h>
#include <utils/TypeHelpers.h>
#include <utils/Vector.h>
#include <utils/VectorImpl.h>
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index 6c1931e..28a77b8 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -22,7 +22,7 @@
#include <new>
-#include <android/log.h>
+#include <log/log.h>
#include <utils/TypeHelpers.h>
#include <utils/VectorImpl.h>
diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp
index 85b5597..5c72234 100644
--- a/libbacktrace/Android.bp
+++ b/libbacktrace/Android.bp
@@ -92,6 +92,7 @@
],
static_libs: ["libcutils"],
+ host_ldlibs: ["-lrt"],
},
android: {
srcs: libbacktrace_sources,
diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp
index 19ea1e3..4496375 100644
--- a/libbacktrace/BacktraceMap.cpp
+++ b/libbacktrace/BacktraceMap.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "backtrace-map"
+
#include <ctype.h>
#include <inttypes.h>
#include <stdint.h>
diff --git a/libcutils/dlmalloc_stubs.c b/libcutils/dlmalloc_stubs.c
index 86fc880..6c07bed 100644
--- a/libcutils/dlmalloc_stubs.c
+++ b/libcutils/dlmalloc_stubs.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "dlmalloc-stubs"
+
#include "android/log.h"
#define UNUSED __attribute__((__unused__))
diff --git a/libcutils/fs.c b/libcutils/fs.c
index 1622ed9..c49233e 100644
--- a/libcutils/fs.c
+++ b/libcutils/fs.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 2cc72a6..cab9263 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -23,7 +23,7 @@
#include <string.h>
#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include <cutils/sched_policy.h>
#define UNUSED __attribute__((__unused__))
diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp
index e51a1c7..3545403 100644
--- a/libcutils/sockets_unix.cpp
+++ b/libcutils/sockets_unix.cpp
@@ -14,7 +14,11 @@
* limitations under the License.
*/
+#define LOG_TAG "socket-unix"
+
#include <sys/uio.h>
+#include <time.h>
+#include <unistd.h>
#include <android/log.h>
#include <cutils/sockets.h>
diff --git a/libion/ion.c b/libion/ion.c
index 424776a..4565efb 100644
--- a/libion/ion.c
+++ b/libion/ion.c
@@ -27,6 +27,7 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
+#include <unistd.h>
#include <android/log.h>
#include <ion/ion.h>
diff --git a/liblog/README b/liblog/README
index eefa80f..dd37832 100644
--- a/liblog/README
+++ b/liblog/README
@@ -1,12 +1,18 @@
-LIBLOG(3) Android NDK Programming Manual LIBLOG(3)
+LIBLOG(3) Android Internal NDK Programming Manual LIBLOG(3)
NAME
- liblog - Android NDK logger interfaces
+ liblog - Android Internal NDK logger interfaces
SYNOPSIS
- #include <android/log.h>
+ /*
+ * 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)
@@ -66,21 +72,44 @@
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
-
+ 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)
+
Link with -llog
DESCRIPTION
@@ -163,8 +192,8 @@
library retries on EINTR, -EINTR should never be returned.
SEE ALSO
- syslogd(8)
+ syslogd(8), klogd, auditd(8)
- 24 Jan 2014 LIBLOG(3)
+ 17 Oct 2016 LIBLOG(3)
diff --git a/liblog/event_tag_map.c b/liblog/event_tag_map.c
index 6705fb2..0e5a281 100644
--- a/liblog/event_tag_map.c
+++ b/liblog/event_tag_map.c
@@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index 5f7f05b..4939221 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -25,10 +25,14 @@
#if !defined(_WIN32)
#include <pthread.h>
#endif
+#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <android/log.h>
+#include <log/uio.h>
#include "fake_log_device.h"
#include "log_portability.h"
diff --git a/liblog/fake_writer.c b/liblog/fake_writer.c
index 47935e3..dab8bc5 100644
--- a/liblog/fake_writer.c
+++ b/liblog/fake_writer.c
@@ -18,7 +18,7 @@
#include <fcntl.h>
#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include "config_write.h"
#include "fake_log_device.h"
diff --git a/liblog/log_event_write.c b/liblog/log_event_write.c
index 8c8a9a1..7262fc5 100644
--- a/liblog/log_event_write.c
+++ b/liblog/log_event_write.c
@@ -15,8 +15,9 @@
*/
#include <errno.h>
+#include <stdint.h>
-#include <android/log.h>
+#include <log/log.h>
#include "log_portability.h"
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c
index 3dfc6a6..132d96f 100644
--- a/liblog/log_is_loggable.c
+++ b/liblog/log_is_loggable.c
@@ -16,12 +16,16 @@
#include <ctype.h>
#include <pthread.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
+#include <unistd.h>
#include <android/log.h>
+#include <log/logger.h>
+#include <private/android_logger.h>
#include "log_portability.h"
@@ -47,12 +51,16 @@
}
struct cache {
- const prop_info *pinfo;
+ const prop_info* pinfo;
uint32_t serial;
+};
+
+struct cache_char {
+ struct cache cache;
unsigned char c;
};
-static int check_cache(struct cache *cache)
+static int check_cache(struct cache* cache)
{
return cache->pinfo
&& __system_property_serial(cache->pinfo) != cache->serial;
@@ -61,18 +69,18 @@
#define BOOLEAN_TRUE 0xFF
#define BOOLEAN_FALSE 0xFE
-static void refresh_cache(struct cache *cache, const char *key)
+static void refresh_cache(struct cache_char* cache, const char* key)
{
char buf[PROP_VALUE_MAX];
- if (!cache->pinfo) {
- cache->pinfo = __system_property_find(key);
- if (!cache->pinfo) {
+ if (!cache->cache.pinfo) {
+ cache->cache.pinfo = __system_property_find(key);
+ if (!cache->cache.pinfo) {
return;
}
}
- cache->serial = __system_property_serial(cache->pinfo);
- __system_property_read(cache->pinfo, 0, buf);
+ cache->cache.serial = __system_property_serial(cache->cache.pinfo);
+ __system_property_read(cache->cache.pinfo, 0, buf);
switch(buf[0]) {
case 't': case 'T':
cache->c = strcasecmp(buf + 1, "rue") ? buf[0] : BOOLEAN_TRUE;
@@ -85,7 +93,7 @@
}
}
-static int __android_log_level(const char *tag, size_t len, int default_prio)
+static int __android_log_level(const char* tag, size_t len, int default_prio)
{
/* sizeof() is used on this array below */
static const char log_namespace[] = "persist.log.tag.";
@@ -93,8 +101,8 @@
/* calculate the size of our key temporary buffer */
const size_t taglen = tag ? len : 0;
/* sizeof(log_namespace) = strlen(log_namespace) + 1 */
- char key[sizeof(log_namespace) + taglen]; /* may be > PROPERTY_KEY_MAX */
- char *kp;
+ char key[sizeof(log_namespace) + taglen]; /* may be > PROP_NAME_MAX */
+ char* kp;
size_t i;
char c = 0;
/*
@@ -110,8 +118,8 @@
static uint32_t global_serial;
/* some compilers erroneously see uninitialized use. !not_locked */
uint32_t current_global_serial = 0;
- static struct cache tag_cache[2];
- static struct cache global_cache[2];
+ static struct cache_char tag_cache[2];
+ static struct cache_char global_cache[2];
int change_detected;
int global_change_detected;
int not_locked;
@@ -125,12 +133,12 @@
* check all known serial numbers to changes.
*/
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
- if (check_cache(&tag_cache[i])) {
+ if (check_cache(&tag_cache[i].cache)) {
change_detected = 1;
}
}
for (i = 0; i < (sizeof(global_cache) / sizeof(global_cache[0])); ++i) {
- if (check_cache(&global_cache[i])) {
+ if (check_cache(&global_cache[i].cache)) {
global_change_detected = 1;
}
}
@@ -154,7 +162,7 @@
|| ((len < sizeof(last_tag)) && last_tag[len])) {
/* invalidate log.tag.<tag> cache */
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
- tag_cache[i].pinfo = NULL;
+ tag_cache[i].cache.pinfo = NULL;
tag_cache[i].c = '\0';
}
last_tag[0] = '\0';
@@ -174,11 +182,11 @@
kp = key;
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
- struct cache *cache = &tag_cache[i];
- struct cache temp_cache;
+ struct cache_char* cache = &tag_cache[i];
+ struct cache_char temp_cache;
if (not_locked) {
- temp_cache.pinfo = NULL;
+ temp_cache.cache.pinfo = NULL;
temp_cache.c = '\0';
cache = &temp_cache;
}
@@ -212,13 +220,13 @@
kp = key;
for (i = 0; i < (sizeof(global_cache) / sizeof(global_cache[0])); ++i) {
- struct cache *cache = &global_cache[i];
- struct cache temp_cache;
+ struct cache_char* cache = &global_cache[i];
+ struct cache_char temp_cache;
if (not_locked) {
temp_cache = *cache;
- if (temp_cache.pinfo != cache->pinfo) { /* check atomic */
- temp_cache.pinfo = NULL;
+ if (temp_cache.cache.pinfo != cache->cache.pinfo) { /* check atomic */
+ temp_cache.cache.pinfo = NULL;
temp_cache.c = '\0';
}
cache = &temp_cache;
@@ -257,7 +265,7 @@
}
LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio,
- const char *tag, size_t len,
+ const char* tag, size_t len,
int default_prio)
{
int logLevel = __android_log_level(tag, len, default_prio);
@@ -265,7 +273,7 @@
}
LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio,
- const char *tag,
+ const char* tag,
int default_prio)
{
int logLevel = __android_log_level(tag,
@@ -277,18 +285,18 @@
LIBLOG_ABI_PRIVATE int __android_log_is_debuggable()
{
static uint32_t serial;
- static struct cache tag_cache;
+ static struct cache_char tag_cache;
static const char key[] = "ro.debuggable";
int ret;
if (tag_cache.c) { /* ro property does not change after set */
ret = tag_cache.c == '1';
} else if (lock()) {
- struct cache temp_cache = { NULL, -1, '\0' };
+ struct cache_char temp_cache = { { NULL, -1 }, '\0' };
refresh_cache(&temp_cache, key);
ret = temp_cache.c == '1';
} else {
- int change_detected = check_cache(&tag_cache);
+ int change_detected = check_cache(&tag_cache.cache);
uint32_t current_serial = __system_property_area_serial();
if (current_serial != serial) {
change_detected = 1;
@@ -310,17 +318,17 @@
* Since a change is rare, we will accept a trylock failure gracefully.
* Use a separate lock from is_loggable to keep contention down b/25563384.
*/
-struct cache2 {
+struct cache2_char {
pthread_mutex_t lock;
uint32_t serial;
- const char *key_persist;
- struct cache cache_persist;
- const char *key_ro;
- struct cache cache_ro;
- unsigned char (*const evaluate)(const struct cache2 *self);
+ const char* key_persist;
+ struct cache_char cache_persist;
+ const char* key_ro;
+ struct cache_char cache_ro;
+ unsigned char (*const evaluate)(const struct cache2_char *self);
};
-static inline unsigned char do_cache2(struct cache2 *self)
+static inline unsigned char do_cache2_char(struct cache2_char *self)
{
uint32_t current_serial;
int change_detected;
@@ -331,8 +339,8 @@
return self->evaluate(self);
}
- change_detected = check_cache(&self->cache_persist)
- || check_cache(&self->cache_ro);
+ change_detected = check_cache(&self->cache_persist.cache)
+ || check_cache(&self->cache_ro.cache);
current_serial = __system_property_area_serial();
if (current_serial != self->serial) {
change_detected = 1;
@@ -349,7 +357,7 @@
return c;
}
-static unsigned char evaluate_persist_ro(const struct cache2 *self)
+static unsigned char evaluate_persist_ro(const struct cache2_char *self)
{
unsigned char c = self->cache_persist.c;
@@ -366,17 +374,17 @@
*/
LIBLOG_ABI_PUBLIC clockid_t android_log_clockid()
{
- static struct cache2 clockid = {
+ static struct cache2_char clockid = {
PTHREAD_MUTEX_INITIALIZER,
0,
"persist.logd.timestamp",
- { NULL, -1, '\0' },
+ { { NULL, -1 }, '\0' },
"ro.logd.timestamp",
- { NULL, -1, '\0' },
+ { { NULL, -1 }, '\0' },
evaluate_persist_ro
};
- return (tolower(do_cache2(&clockid)) == 'm')
+ return (tolower(do_cache2_char(&clockid)) == 'm')
? CLOCK_MONOTONIC
: CLOCK_REALTIME;
}
@@ -385,7 +393,7 @@
* Security state generally remains constant, but the DO must be able
* to turn off logging should it become spammy after an attack is detected.
*/
-static unsigned char evaluate_security(const struct cache2 *self)
+static unsigned char evaluate_security(const struct cache2_char *self)
{
unsigned char c = self->cache_ro.c;
@@ -394,15 +402,265 @@
LIBLOG_ABI_PUBLIC int __android_log_security()
{
- static struct cache2 security = {
+ static struct cache2_char security = {
PTHREAD_MUTEX_INITIALIZER,
0,
"persist.logd.security",
- { NULL, -1, BOOLEAN_FALSE },
+ { { NULL, -1 }, BOOLEAN_FALSE },
"ro.device_owner",
- { NULL, -1, BOOLEAN_FALSE },
+ { { NULL, -1 }, BOOLEAN_FALSE },
evaluate_security
};
- return do_cache2(&security);
+ return do_cache2_char(&security);
+}
+
+/*
+ * Interface that represents the logd buffer size determination so that others
+ * need not guess our intentions.
+ */
+
+/* Property helper */
+static bool check_flag(const char* prop, const char* flag) {
+ const char* cp = strcasestr(prop, flag);
+ if (!cp) {
+ return false;
+ }
+ /* We only will document comma (,) */
+ static const char sep[] = ",:;|+ \t\f";
+ if ((cp != prop) && !strchr(sep, cp[-1])) {
+ return false;
+ }
+ cp += strlen(flag);
+ return !*cp || !!strchr(sep, *cp);
+}
+
+/* cache structure */
+struct cache_property {
+ struct cache cache;
+ char property[PROP_VALUE_MAX];
+};
+
+static void refresh_cache_property(struct cache_property* cache, const char* key)
+{
+ if (!cache->cache.pinfo) {
+ cache->cache.pinfo = __system_property_find(key);
+ if (!cache->cache.pinfo) {
+ return;
+ }
+ }
+ cache->cache.serial = __system_property_serial(cache->cache.pinfo);
+ __system_property_read(cache->cache.pinfo, 0, cache->property);
+}
+
+/* get boolean with the logger twist that supports eng adjustments */
+LIBLOG_ABI_PRIVATE bool __android_logger_property_get_bool(const char* key,
+ int flag)
+{
+ struct cache_property property = { { NULL, -1 }, { 0 } };
+ if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
+ char newkey[PROP_NAME_MAX];
+ snprintf(newkey, sizeof(newkey), "ro.%s", key);
+ refresh_cache_property(&property, newkey);
+ property.cache.pinfo = NULL;
+ property.cache.serial = -1;
+ snprintf(newkey, sizeof(newkey), "persist.%s", key);
+ refresh_cache_property(&property, newkey);
+ property.cache.pinfo = NULL;
+ property.cache.serial = -1;
+ }
+
+ refresh_cache_property(&property, key);
+
+ if (check_flag(property.property, "true")) {
+ return true;
+ }
+ if (check_flag(property.property, "false")) {
+ return false;
+ }
+ if (check_flag(property.property, "eng")) {
+ flag |= BOOL_DEFAULT_FLAG_ENG;
+ }
+ /* this is really a "not" flag */
+ if (check_flag(property.property, "svelte")) {
+ flag |= BOOL_DEFAULT_FLAG_SVELTE;
+ }
+
+ /* Sanity Check */
+ if (flag & (BOOL_DEFAULT_FLAG_SVELTE | BOOL_DEFAULT_FLAG_ENG)) {
+ flag &= ~BOOL_DEFAULT_FLAG_TRUE_FALSE;
+ flag |= BOOL_DEFAULT_TRUE;
+ }
+
+ if ((flag & BOOL_DEFAULT_FLAG_SVELTE)
+ && __android_logger_property_get_bool("ro.config.low_ram",
+ BOOL_DEFAULT_FALSE)) {
+ return false;
+ }
+ if ((flag & BOOL_DEFAULT_FLAG_ENG) && !__android_log_is_debuggable()) {
+ return false;
+ }
+
+ return (flag & BOOL_DEFAULT_FLAG_TRUE_FALSE) != BOOL_DEFAULT_FALSE;
+}
+
+LIBLOG_ABI_PRIVATE bool __android_logger_valid_buffer_size(unsigned long value)
+{
+ static long pages, pagesize;
+ unsigned long maximum;
+
+ if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
+ return false;
+ }
+
+ if (!pages) {
+ pages = sysconf(_SC_PHYS_PAGES);
+ }
+ if (pages < 1) {
+ return true;
+ }
+
+ if (!pagesize) {
+ pagesize = sysconf(_SC_PAGESIZE);
+ if (pagesize <= 1) {
+ pagesize = PAGE_SIZE;
+ }
+ }
+
+ /* maximum memory impact a somewhat arbitrary ~3% */
+ pages = (pages + 31) / 32;
+ maximum = pages * pagesize;
+
+ if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
+ return true;
+ }
+
+ return value <= maximum;
+}
+
+struct cache2_property_size {
+ pthread_mutex_t lock;
+ uint32_t serial;
+ const char* key_persist;
+ struct cache_property cache_persist;
+ const char* key_ro;
+ struct cache_property cache_ro;
+ unsigned long (*const evaluate)(const struct cache2_property_size* self);
+};
+
+static inline unsigned long do_cache2_property_size(struct cache2_property_size* self)
+{
+ uint32_t current_serial;
+ int change_detected;
+ unsigned long v;
+
+ if (pthread_mutex_trylock(&self->lock)) {
+ /* We are willing to accept some race in this context */
+ return self->evaluate(self);
+ }
+
+ change_detected = check_cache(&self->cache_persist.cache)
+ || check_cache(&self->cache_ro.cache);
+ current_serial = __system_property_area_serial();
+ if (current_serial != self->serial) {
+ change_detected = 1;
+ }
+ if (change_detected) {
+ refresh_cache_property(&self->cache_persist, self->key_persist);
+ refresh_cache_property(&self->cache_ro, self->key_ro);
+ self->serial = current_serial;
+ }
+ v = self->evaluate(self);
+
+ pthread_mutex_unlock(&self->lock);
+
+ return v;
+}
+
+static unsigned long property_get_size_from_cache(const struct cache_property* cache)
+{
+ char* cp;
+ unsigned long value = strtoul(cache->property, &cp, 10);
+
+ switch(*cp) {
+ case 'm':
+ case 'M':
+ value *= 1024;
+ /* FALLTHRU */
+ case 'k':
+ case 'K':
+ value *= 1024;
+ /* FALLTHRU */
+ case '\0':
+ break;
+
+ default:
+ value = 0;
+ }
+
+ if (!__android_logger_valid_buffer_size(value)) {
+ value = 0;
+ }
+
+ return value;
+}
+
+static unsigned long evaluate_property_get_size(const struct cache2_property_size* self)
+{
+ unsigned long size = property_get_size_from_cache(&self->cache_persist);
+ if (size) {
+ return size;
+ }
+ return property_get_size_from_cache(&self->cache_ro);
+}
+
+LIBLOG_ABI_PRIVATE unsigned long __android_logger_get_buffer_size(log_id_t logId)
+{
+ static const char global_tunable[] = "persist.logd.size"; /* Settings App */
+ static const char global_default[] = "ro.logd.size"; /* BoardConfig.mk */
+ static struct cache2_property_size global = {
+ PTHREAD_MUTEX_INITIALIZER,
+ 0,
+ global_tunable,
+ { { NULL, -1 }, {} },
+ global_default,
+ { { NULL, -1 }, {} },
+ evaluate_property_get_size
+ };
+ char key_persist[PROP_NAME_MAX];
+ char key_ro[PROP_NAME_MAX];
+ struct cache2_property_size local = {
+ PTHREAD_MUTEX_INITIALIZER,
+ 0,
+ key_persist,
+ { { NULL, -1 }, {} },
+ key_ro,
+ { { NULL, -1 }, {} },
+ evaluate_property_get_size
+ };
+ unsigned long property_size, default_size;
+
+ default_size = do_cache2_property_size(&global);
+ if (!default_size) {
+ default_size = __android_logger_property_get_bool("ro.config.low_ram",
+ BOOL_DEFAULT_FALSE)
+ ? LOG_BUFFER_MIN_SIZE /* 64K */
+ : LOG_BUFFER_SIZE; /* 256K */
+ }
+
+ snprintf(key_persist, sizeof(key_persist), "%s.%s",
+ global_tunable, android_log_id_to_name(logId));
+ snprintf(key_ro, sizeof(key_ro), "%s.%s",
+ global_default, android_log_id_to_name(logId));
+ property_size = do_cache2_property_size(&local);
+
+ if (!property_size) {
+ property_size = default_size;
+ }
+
+ if (!property_size) {
+ property_size = LOG_BUFFER_SIZE;
+ }
+
+ return property_size;
}
diff --git a/liblog/logd_reader.c b/liblog/logd_reader.c
index 71ff075..99d7fea 100644
--- a/liblog/logd_reader.c
+++ b/liblog/logd_reader.c
@@ -31,9 +31,7 @@
#include <time.h>
#include <unistd.h>
-#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/logd_writer.c b/liblog/logd_writer.c
index 2913507..8fdfb92 100644
--- a/liblog/logd_writer.c
+++ b/liblog/logd_writer.c
@@ -32,7 +32,6 @@
#include <unistd.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/logger.h b/liblog/logger.h
index d2aebcb..fb47786 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -19,11 +19,11 @@
#include <stdatomic.h>
#include <stdbool.h>
-#include <log/uio.h>
#include <android/log.h>
#include <cutils/list.h>
#include <log/logger.h>
+#include <log/uio.h>
#include "log_portability.h"
diff --git a/liblog/logger_read.c b/liblog/logger_read.c
index d979e22..c3cb7ad 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.c
@@ -25,7 +25,6 @@
#include <android/log.h>
#include <cutils/list.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include "config_read.h"
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index 1e56b27..c481e36 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -24,9 +24,7 @@
#include <android/set_abort_message.h>
#endif
-#include <android/log.h>
#include <log/event_tag_map.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index b3c4a1a..c1c068e 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -26,9 +26,6 @@
#include <sys/types.h>
#include <time.h>
-#include <android/log.h>
-#include <log/logger.h>
-
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index cd012ce..44045c3 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -20,9 +20,7 @@
#include <sys/types.h>
#include <unistd.h>
-#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_logger.h>
#include "benchmark.h"
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 7db048d..fd38849 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -27,12 +27,10 @@
#include <string>
-#include <android/log.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <cutils/properties.h>
#include <gtest/gtest.h>
-#include <log/logger.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index 9f9c83f..32b2d27 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "nativebridge"
+
#include "nativebridge/native_bridge.h"
#include <dlfcn.h>
@@ -22,6 +24,7 @@
#include <stdio.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <unistd.h>
#include <cstring>
diff --git a/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp b/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
index 67eba80..e212f1b 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
+++ b/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
@@ -14,6 +14,7 @@
** See the License for the specific language governing permissions and
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
#include <errno.h>
#include <stdint.h>
diff --git a/libpixelflinger/codeflinger/blending.cpp b/libpixelflinger/codeflinger/blending.cpp
index d4aa475..092f140 100644
--- a/libpixelflinger/codeflinger/blending.cpp
+++ b/libpixelflinger/codeflinger/blending.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
+
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/libpixelflinger/codeflinger/load_store.cpp b/libpixelflinger/codeflinger/load_store.cpp
index d68f6dc..b8a0e55 100644
--- a/libpixelflinger/codeflinger/load_store.cpp
+++ b/libpixelflinger/codeflinger/load_store.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
+
#include <assert.h>
#include <stdio.h>
diff --git a/libpixelflinger/codeflinger/texturing.cpp b/libpixelflinger/codeflinger/texturing.cpp
index d66981d..f4f4657 100644
--- a/libpixelflinger/codeflinger/texturing.cpp
+++ b/libpixelflinger/codeflinger/texturing.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
+
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/libpixelflinger/trap.cpp b/libpixelflinger/trap.cpp
index f00e50a..fa6338a 100644
--- a/libpixelflinger/trap.cpp
+++ b/libpixelflinger/trap.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-trap"
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/libsysutils/src/FrameworkCommand.cpp b/libsysutils/src/FrameworkCommand.cpp
index dccacda..a6c4abc 100644
--- a/libsysutils/src/FrameworkCommand.cpp
+++ b/libsysutils/src/FrameworkCommand.cpp
@@ -18,7 +18,7 @@
#include <errno.h>
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/FrameworkCommand.h>
#define UNUSED __attribute__((unused))
diff --git a/libsysutils/src/FrameworkListener.cpp b/libsysutils/src/FrameworkListener.cpp
index b96174a..52f28af 100644
--- a/libsysutils/src/FrameworkListener.cpp
+++ b/libsysutils/src/FrameworkListener.cpp
@@ -19,8 +19,9 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/FrameworkCommand.h>
#include <sysutils/FrameworkListener.h>
#include <sysutils/SocketClient.h>
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index b787692..fef801a 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -41,7 +41,7 @@
const int LOCAL_QLOG_NL_EVENT = 112;
const int LOCAL_NFLOG_PACKET = NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET;
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/NetlinkEvent.h>
NetlinkEvent::NetlinkEvent() {
diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp
index 1c4c7df..896dad3 100644
--- a/libsysutils/src/NetlinkListener.cpp
+++ b/libsysutils/src/NetlinkListener.cpp
@@ -20,11 +20,12 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
#include <linux/netlink.h> /* out of order because must follow sys/socket.h */
-#include <android/log.h>
#include <cutils/uevent.h>
+#include <log/log.h>
#include <sysutils/NetlinkEvent.h>
#if 1
diff --git a/libsysutils/src/ServiceManager.cpp b/libsysutils/src/ServiceManager.cpp
index 1abe988..13bac09 100644
--- a/libsysutils/src/ServiceManager.cpp
+++ b/libsysutils/src/ServiceManager.cpp
@@ -17,10 +17,12 @@
#define LOG_TAG "Service"
#include <errno.h>
+#include <stdio.h>
#include <string.h>
+#include <unistd.h>
-#include <android/log.h>
#include <cutils/properties.h>
+#include <log/log.h>
#include <sysutils/ServiceManager.h>
ServiceManager::ServiceManager() {
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 02505d3..971f908 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -25,8 +25,9 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/SocketClient.h>
SocketClient::SocketClient(int socket, bool owned) {
diff --git a/libsysutils/src/SocketListener.cpp b/libsysutils/src/SocketListener.cpp
index 6a676a9..3f8f3db 100644
--- a/libsysutils/src/SocketListener.cpp
+++ b/libsysutils/src/SocketListener.cpp
@@ -24,9 +24,10 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
+#include <unistd.h>
-#include <android/log.h>
#include <cutils/sockets.h>
+#include <log/log.h>
#include <sysutils/SocketListener.h>
#include <sysutils/SocketClient.h>
diff --git a/libutils/SharedBuffer.cpp b/libutils/SharedBuffer.cpp
index 2b3690c..269326a 100644
--- a/libutils/SharedBuffer.cpp
+++ b/libutils/SharedBuffer.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "sharedbuffer"
+
#include <stdlib.h>
#include <string.h>
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 0652101..c32f462 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "unicode"
+
#include <limits.h>
#include <stddef.h>
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index b00557c..d36cc3f 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -18,6 +18,8 @@
* Read-only access to Zip archives, with minimal heap allocation.
*/
+#define LOG_TAG "ziparchive"
+
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
@@ -30,11 +32,11 @@
#include <memory>
#include <vector>
-#include <android/log.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h> // TEMP_FAILURE_RETRY may or may not be in unistd
#include <android-base/memory.h>
+#include <log/log.h>
#include <utils/Compat.h>
#include <utils/FileMap.h>
#include "ziparchive/zip_archive.h"
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index 107aa3e..49746b3 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -18,6 +18,7 @@
#include <arpa/inet.h>
#include <errno.h>
+#include <sched.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp
index cc140b0..3811daa 100644
--- a/logd/LogAudit.cpp
+++ b/logd/LogAudit.cpp
@@ -25,7 +25,6 @@
#include <sys/uio.h>
#include <syslog.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 7f5fe4f..5554d53 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -25,114 +25,21 @@
#include <unordered_map>
#include <cutils/properties.h>
-#include <log/logger.h>
+#include <private/android_logger.h>
#include "LogBuffer.h"
#include "LogKlog.h"
#include "LogReader.h"
// Default
-#define LOG_BUFFER_SIZE (256 * 1024) // Tuned with ro.logd.size per-platform
#define log_buffer_size(id) mMaxSize[id]
-#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
-#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
-
-static bool valid_size(unsigned long value) {
- if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
- return false;
- }
-
- long pages = sysconf(_SC_PHYS_PAGES);
- if (pages < 1) {
- return true;
- }
-
- long pagesize = sysconf(_SC_PAGESIZE);
- if (pagesize <= 1) {
- pagesize = PAGE_SIZE;
- }
-
- // maximum memory impact a somewhat arbitrary ~3%
- pages = (pages + 31) / 32;
- unsigned long maximum = pages * pagesize;
-
- if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
- return true;
- }
-
- return value <= maximum;
-}
-
-static unsigned long property_get_size(const char *key) {
- char property[PROPERTY_VALUE_MAX];
- property_get(key, property, "");
-
- char *cp;
- unsigned long value = strtoul(property, &cp, 10);
-
- switch(*cp) {
- case 'm':
- case 'M':
- value *= 1024;
- /* FALLTHRU */
- case 'k':
- case 'K':
- value *= 1024;
- /* FALLTHRU */
- case '\0':
- break;
-
- default:
- value = 0;
- }
-
- if (!valid_size(value)) {
- value = 0;
- }
-
- return value;
-}
void LogBuffer::init() {
- static const char global_tuneable[] = "persist.logd.size"; // Settings App
- static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
-
- unsigned long default_size = property_get_size(global_tuneable);
- if (!default_size) {
- default_size = property_get_size(global_default);
- if (!default_size) {
- default_size = property_get_bool("ro.config.low_ram",
- BOOL_DEFAULT_FALSE)
- ? LOG_BUFFER_MIN_SIZE // 64K
- : LOG_BUFFER_SIZE; // 256K
- }
- }
-
log_id_for_each(i) {
mLastSet[i] = false;
mLast[i] = mLogElements.begin();
- char key[PROP_NAME_MAX];
-
- snprintf(key, sizeof(key), "%s.%s",
- global_tuneable, android_log_id_to_name(i));
- unsigned long property_size = property_get_size(key);
-
- if (!property_size) {
- snprintf(key, sizeof(key), "%s.%s",
- global_default, android_log_id_to_name(i));
- property_size = property_get_size(key);
- }
-
- if (!property_size) {
- property_size = default_size;
- }
-
- if (!property_size) {
- property_size = LOG_BUFFER_SIZE;
- }
-
- if (setSize(i, property_size)) {
+ if (setSize(i, __android_logger_get_buffer_size(i))) {
setSize(i, LOG_BUFFER_MIN_SIZE);
}
}
@@ -880,7 +787,7 @@
// set the total space allocated to "id"
int LogBuffer::setSize(log_id_t id, unsigned long size) {
// Reasonable limits ...
- if (!valid_size(size)) {
+ if (!__android_logger_valid_buffer_size(size)) {
return -1;
}
pthread_mutex_lock(&mLogElementsLock);
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index e5de11d..a939002 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -22,7 +22,6 @@
#include <time.h>
#include <unistd.h>
-#include <log/logger.h>
#include <private/android_logger.h>
#include "LogBuffer.h"
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index 61b7fd8..4a30e6d 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -23,7 +23,6 @@
#include <unistd.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/logd/LogUtils.h b/logd/LogUtils.h
index 6db4c51..d6b3dc6 100644
--- a/logd/LogUtils.h
+++ b/logd/LogUtils.h
@@ -20,8 +20,8 @@
#include <sys/cdefs.h>
#include <sys/types.h>
-#include <android/log.h>
#include <sysutils/SocketClient.h>
+#include <log/log.h>
// Hijack this header as a common include file used by most all sources
// to report some utilities defined here and there.
@@ -45,16 +45,6 @@
bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid);
bool clientHasLogCredentials(SocketClient *cli);
-// Furnished in main.cpp
-#define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
-#define BOOL_DEFAULT_FALSE 0x0 // false if property not present
-#define BOOL_DEFAULT_TRUE 0x1 // true if property not present
-#define BOOL_DEFAULT_FLAG_PERSIST 0x2 // <key>, persist.<key>, ro.<key>
-#define BOOL_DEFAULT_FLAG_ENG 0x4 // off for user
-#define BOOL_DEFAULT_FLAG_SVELTE 0x8 // off for low_ram
-
-bool property_get_bool(const char *key, int def);
-
static inline bool worstUidEnabledForLogid(log_id_t id) {
return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) ||
(id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS);
diff --git a/logd/libaudit.c b/logd/libaudit.c
index 288a052..d2b212e 100644
--- a/logd/libaudit.c
+++ b/logd/libaudit.c
@@ -18,26 +18,20 @@
*
*/
-#define LOG_TAG "libaudit"
-
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <android/log.h>
-
#include "libaudit.h"
/**
* Waits for an ack from the kernel
* @param fd
* The netlink socket fd
- * @param seq
- * The current sequence number were acking on
* @return
* This function returns 0 on success, else -errno.
*/
-static int get_ack(int fd, int16_t seq)
+static int get_ack(int fd)
{
int rc;
struct audit_message rep;
@@ -60,11 +54,6 @@
}
}
- if ((int16_t)rep.nlh.nlmsg_seq != seq) {
- SLOGW("Expected sequence number between user space and kernel space is out of skew, "
- "expected %u got %u", seq, rep.nlh.nlmsg_seq);
- }
-
return 0;
}
@@ -109,7 +98,6 @@
/* Ensure the message is not too big */
if (NLMSG_SPACE(size) > MAX_AUDIT_MESSAGE_LENGTH) {
- SLOGE("netlink message is too large");
return -EINVAL;
}
@@ -140,7 +128,6 @@
/* Not all the bytes were sent */
if (rc < 0) {
rc = -errno;
- SLOGE("Error sending data over the netlink socket: %s", strerror(-errno));
goto out;
} else if ((uint32_t) rc != req.nlh.nlmsg_len) {
rc = -EPROTO;
@@ -148,7 +135,7 @@
}
/* We sent all the bytes, get the ack */
- rc = get_ack(fd, sequence);
+ rc = get_ack(fd);
/* If the ack failed, return the error, else return the sequence number */
rc = (rc == 0) ? (int) sequence : rc;
@@ -156,7 +143,6 @@
out:
/* Don't let sequence roll to negative */
if (sequence < 0) {
- SLOGW("Auditd to Kernel sequence number has rolled over");
sequence = 0;
}
@@ -183,7 +169,6 @@
/* Let the kernel know this pid will be registering for audit events */
rc = audit_send(fd, AUDIT_SET, &status, sizeof(status));
if (rc < 0) {
- SLOGE("Could net set pid for audit events, error: %s", strerror(-rc));
return rc;
}
@@ -241,25 +226,21 @@
/* If request is non blocking and errno is EAGAIN, just return 0 */
return 0;
}
- SLOGE("Error receiving from netlink socket, error: %s", strerror(-rc));
return rc;
}
if (nladdrlen != sizeof(nladdr)) {
- SLOGE("Protocol fault, error: %s", strerror(EPROTO));
return -EPROTO;
}
/* Make sure the netlink message was not spoof'd */
if (nladdr.nl_pid) {
- SLOGE("Invalid netlink pid received, expected 0 got: %d", nladdr.nl_pid);
return -EINVAL;
}
/* Check if the reply from the kernel was ok */
if (!NLMSG_OK(&rep->nlh, (size_t)len)) {
rc = (len == sizeof(*rep)) ? -EFBIG : -EBADE;
- SLOGE("Bad kernel response %s", strerror(-rc));
}
return rc;
@@ -267,9 +248,5 @@
void audit_close(int fd)
{
- int rc = close(fd);
- if (rc < 0) {
- SLOGE("Attempting to close invalid fd %d, error: %s", fd, strerror(errno));
- }
- return;
+ close(fd);
}
diff --git a/logd/main.cpp b/logd/main.cpp
index c47f396..0cb26dc 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -131,57 +131,6 @@
return !*cp || !!strchr(sep, *cp);
}
-bool property_get_bool(const char *key, int flag) {
- char def[PROPERTY_VALUE_MAX];
- char property[PROPERTY_VALUE_MAX];
- def[0] = '\0';
- if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
- char newkey[PROPERTY_KEY_MAX];
- snprintf(newkey, sizeof(newkey), "ro.%s", key);
- property_get(newkey, property, "");
- // persist properties set by /data require inoculation with
- // logd-reinit. They may be set in init.rc early and function, but
- // otherwise are defunct unless reset. Do not rely on persist
- // properties for startup-only keys unless you are willing to restart
- // logd daemon (not advised).
- snprintf(newkey, sizeof(newkey), "persist.%s", key);
- property_get(newkey, def, property);
- }
-
- property_get(key, property, def);
-
- if (check_flag(property, "true")) {
- return true;
- }
- if (check_flag(property, "false")) {
- return false;
- }
- if (check_flag(property, "eng")) {
- flag |= BOOL_DEFAULT_FLAG_ENG;
- }
- // this is really a "not" flag
- if (check_flag(property, "svelte")) {
- flag |= BOOL_DEFAULT_FLAG_SVELTE;
- }
-
- // Sanity Check
- if (flag & (BOOL_DEFAULT_FLAG_SVELTE | BOOL_DEFAULT_FLAG_ENG)) {
- flag &= ~BOOL_DEFAULT_FLAG_TRUE_FALSE;
- flag |= BOOL_DEFAULT_TRUE;
- }
-
- if ((flag & BOOL_DEFAULT_FLAG_SVELTE)
- && property_get_bool("ro.config.low_ram",
- BOOL_DEFAULT_FALSE)) {
- return false;
- }
- if ((flag & BOOL_DEFAULT_FLAG_ENG) && !__android_log_is_debuggable()) {
- return false;
- }
-
- return (flag & BOOL_DEFAULT_FLAG_TRUE_FALSE) != BOOL_DEFAULT_FALSE;
-}
-
static int fdDmesg = -1;
void android::prdebug(const char *fmt, ...) {
if (fdDmesg < 0) {
@@ -365,11 +314,11 @@
// transitory per-client threads are created for each reader.
int main(int argc, char *argv[]) {
int fdPmesg = -1;
- bool klogd = property_get_bool("logd.kernel",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST |
- BOOL_DEFAULT_FLAG_ENG |
- BOOL_DEFAULT_FLAG_SVELTE);
+ bool klogd = __android_logger_property_get_bool("logd.kernel",
+ BOOL_DEFAULT_TRUE |
+ BOOL_DEFAULT_FLAG_PERSIST |
+ BOOL_DEFAULT_FLAG_ENG |
+ BOOL_DEFAULT_FLAG_SVELTE);
if (klogd) {
fdPmesg = open("/proc/kmsg", O_RDONLY | O_NDELAY);
}
@@ -449,11 +398,11 @@
signal(SIGHUP, reinit_signal_handler);
- if (property_get_bool("logd.statistics",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST |
- BOOL_DEFAULT_FLAG_ENG |
- BOOL_DEFAULT_FLAG_SVELTE)) {
+ if (__android_logger_property_get_bool("logd.statistics",
+ BOOL_DEFAULT_TRUE |
+ BOOL_DEFAULT_FLAG_PERSIST |
+ BOOL_DEFAULT_FLAG_ENG |
+ BOOL_DEFAULT_FLAG_SVELTE)) {
logBuf->enableStatistics();
}
@@ -487,17 +436,17 @@
// initiated log messages. New log entries are added to LogBuffer
// and LogReader is notified to send updates to connected clients.
- bool auditd = property_get_bool("logd.auditd",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST);
+ bool auditd = __android_logger_property_get_bool("logd.auditd",
+ BOOL_DEFAULT_TRUE |
+ BOOL_DEFAULT_FLAG_PERSIST);
LogAudit *al = NULL;
if (auditd) {
al = new LogAudit(logBuf, reader,
- property_get_bool("logd.auditd.dmesg",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST)
- ? fdDmesg
- : -1);
+ __android_logger_property_get_bool(
+ "logd.auditd.dmesg",
+ BOOL_DEFAULT_TRUE | BOOL_DEFAULT_FLAG_PERSIST)
+ ? fdDmesg
+ : -1);
}
LogKlog *kl = NULL;
diff --git a/trusty/gatekeeper/trusty_gatekeeper_ipc.c b/trusty/gatekeeper/trusty_gatekeeper_ipc.c
index ae536c5..45e65a7 100644
--- a/trusty/gatekeeper/trusty_gatekeeper_ipc.c
+++ b/trusty/gatekeeper/trusty_gatekeeper_ipc.c
@@ -17,8 +17,10 @@
#define LOG_TAG "TrustyGateKeeper"
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <android/log.h>
#include <trusty/tipc.h>
diff --git a/trusty/keymaster/trusty_keymaster_ipc.c b/trusty/keymaster/trusty_keymaster_ipc.c
index 0159bce..8755093 100644
--- a/trusty/keymaster/trusty_keymaster_ipc.c
+++ b/trusty/keymaster/trusty_keymaster_ipc.c
@@ -21,6 +21,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <android/log.h>
#include <trusty/tipc.h>
diff --git a/trusty/libtrusty/trusty.c b/trusty/libtrusty/trusty.c
index ba16bee..2398a53 100644
--- a/trusty/libtrusty/trusty.c
+++ b/trusty/libtrusty/trusty.c
@@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
#include <android/log.h>
diff --git a/trusty/nvram/trusty_nvram_implementation.cpp b/trusty/nvram/trusty_nvram_implementation.cpp
index caa25ab..ddaf333 100644
--- a/trusty/nvram/trusty_nvram_implementation.cpp
+++ b/trusty/nvram/trusty_nvram_implementation.cpp
@@ -20,6 +20,7 @@
#include <errno.h>
#include <string.h>
+#include <unistd.h>
#include <android/log.h>
#include <hardware/nvram.h>
diff --git a/trusty/storage/proxy/ipc.c b/trusty/storage/proxy/ipc.c
index b4748e2..57cf600 100644
--- a/trusty/storage/proxy/ipc.c
+++ b/trusty/storage/proxy/ipc.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
+#include <unistd.h>
#include <trusty/tipc.h>
diff --git a/trusty/storage/proxy/rpmb.c b/trusty/storage/proxy/rpmb.c
index 9130458..9c79105 100644
--- a/trusty/storage/proxy/rpmb.c
+++ b/trusty/storage/proxy/rpmb.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <unistd.h>
#include <linux/major.h>
#include <linux/mmc/ioctl.h>