diff options
Diffstat (limited to 'liblog')
-rw-r--r-- | liblog/Android.mk | 36 | ||||
-rw-r--r-- | liblog/README | 27 | ||||
-rw-r--r-- | liblog/event.logtags | 36 | ||||
-rw-r--r-- | liblog/logd_write.c | 36 | ||||
-rw-r--r-- | liblog/logd_write_kern.c | 2 |
5 files changed, 118 insertions, 19 deletions
diff --git a/liblog/Android.mk b/liblog/Android.mk index 5756c54..70aff83 100644 --- a/liblog/Android.mk +++ b/liblog/Android.mk @@ -16,6 +16,14 @@ LOCAL_PATH := $(my-dir) include $(CLEAR_VARS) +# This is what we want to do: +# liblog_cflags := $(shell \ +# sed -n \ +# 's/^\([0-9]*\)[ \t]*liblog[ \t].*/-DLIBLOG_LOG_TAG=\1/p' \ +# $(LOCAL_PATH)/event.logtags) +# so make sure we do not regret hard-coding it as follows: +liblog_cflags := -DLIBLOG_LOG_TAG=1005 + ifneq ($(TARGET_USES_LOGD),false) liblog_sources := logd_write.c else @@ -25,28 +33,20 @@ endif # some files must not be compiled when building against Mingw # they correspond to features not used by our host development tools # which are also hard or even impossible to port to native Win32 -WITH_MINGW := -ifeq ($(HOST_OS),windows) - ifeq ($(strip $(USE_CYGWIN)),) - WITH_MINGW := true - endif -endif -# USE_MINGW is defined when we build against Mingw on Linux -ifneq ($(strip $(USE_MINGW)),) - WITH_MINGW := true -endif -ifndef WITH_MINGW +ifeq ($(strip $(USE_MINGW)),) liblog_sources += \ - logprint.c \ event_tag_map.c else liblog_sources += \ uio.c endif -liblog_host_sources := $(liblog_sources) fake_log_device.c +liblog_host_sources := $(liblog_sources) fake_log_device.c event.logtags liblog_target_sources := $(liblog_sources) log_time.cpp log_is_loggable.c +ifeq ($(strip $(USE_MINGW)),) +liblog_target_sources += logprint.c +endif ifneq ($(TARGET_USES_LOGD),false) liblog_target_sources += log_read.c else @@ -57,7 +57,7 @@ endif # ======================================================== LOCAL_MODULE := liblog LOCAL_SRC_FILES := $(liblog_host_sources) -LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror +LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror $(liblog_cflags) LOCAL_MULTILIB := both include $(BUILD_HOST_STATIC_LIBRARY) @@ -76,13 +76,17 @@ include $(BUILD_HOST_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liblog LOCAL_SRC_FILES := $(liblog_target_sources) -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror $(liblog_cflags) include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liblog LOCAL_WHOLE_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror $(liblog_cflags) + +# TODO: This is to work around b/19059885. Remove after root cause is fixed +LOCAL_LDFLAGS_arm := -Wl,--hash-style=sysv + include $(BUILD_SHARED_LIBRARY) include $(call first-makefiles-under,$(LOCAL_PATH)) diff --git a/liblog/README b/liblog/README index 461dfbe..f29ac04 100644 --- a/liblog/README +++ b/liblog/README @@ -131,6 +131,33 @@ DESCRIPTION when opening the sub-log. It is recommended to open the log ANDROID_LOG_RDONLY in these cases. +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) diff --git a/liblog/event.logtags b/liblog/event.logtags new file mode 100644 index 0000000..72ecab1 --- /dev/null +++ b/liblog/event.logtags @@ -0,0 +1,36 @@ +# The entries in this file map a sparse set of log tag numbers to tag names. +# This is installed on the device, in /system/etc, and parsed by logcat. +# +# Tag numbers are decimal integers, from 0 to 2^31. (Let's leave the +# negative values alone for now.) +# +# Tag names are one or more ASCII letters and numbers or underscores, i.e. +# "[A-Z][a-z][0-9]_". Do not include spaces or punctuation (the former +# impacts log readability, the latter makes regex searches more annoying). +# +# Tag numbers and names are separated by whitespace. Blank lines and lines +# starting with '#' are ignored. +# +# Optionally, after the tag names can be put a description for the value(s) +# of the tag. Description are in the format +# (<name>|data type[|data unit]) +# Multiple values are separated by commas. +# +# The data type is a number from the following values: +# 1: int +# 2: long +# 3: string +# 4: list +# +# The data unit is a number taken from the following list: +# 1: Number of objects +# 2: Number of bytes +# 3: Number of milliseconds +# 4: Number of allocations +# 5: Id +# 6: Percent +# Default value for data of type int/long is 2 (bytes). +# +# TODO: generate ".java" and ".h" files with integer constants from this file. + +1005 liblog (dropped|1) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index 0208c73..8f8cc3f 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -13,12 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#if (FAKE_LOG_DEVICE == 0) +#include <endian.h> +#endif #include <errno.h> #include <fcntl.h> #if !defined(_WIN32) #include <pthread.h> #endif #include <stdarg.h> +#include <stdatomic.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -172,6 +176,11 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr) size_t i, payload_size; static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */ static pid_t last_pid = (pid_t) -1; + static atomic_int_fast32_t dropped; + + if (!nr) { + return -EINVAL; + } if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */ last_uid = getuid(); @@ -206,7 +215,6 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr) pmsg_header.uid = last_uid; pmsg_header.pid = last_pid; - header.id = log_id; header.tid = gettid(); header.realtime.tv_sec = ts.tv_sec; header.realtime.tv_nsec = ts.tv_nsec; @@ -216,6 +224,28 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr) newVec[1].iov_base = (unsigned char *) &header; newVec[1].iov_len = sizeof(header); + if (logd_fd > 0) { + int32_t snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed); + if (snapshot) { + android_log_event_int_t buffer; + + header.id = LOG_ID_EVENTS; + buffer.header.tag = htole32(LIBLOG_LOG_TAG); + buffer.payload.type = EVENT_TYPE_INT; + buffer.payload.data = htole32(snapshot); + + newVec[2].iov_base = &buffer; + newVec[2].iov_len = sizeof(buffer); + + ret = TEMP_FAILURE_RETRY(writev(logd_fd, newVec + 1, 2)); + if (ret != (ssize_t)(sizeof(header) + sizeof(buffer))) { + atomic_fetch_add_explicit(&dropped, snapshot, memory_order_relaxed); + } + } + } + + header.id = log_id; + for (payload_size = 0, i = header_length; i < nr + header_length; i++) { newVec[i].iov_base = vec[i - header_length].iov_base; payload_size += newVec[i].iov_len = vec[i - header_length].iov_len; @@ -281,6 +311,8 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr) if (ret > (ssize_t)sizeof(header)) { ret -= sizeof(header); + } else if (ret == -EAGAIN) { + atomic_fetch_add_explicit(&dropped, 1, memory_order_relaxed); } #endif @@ -463,7 +495,7 @@ void __android_log_assert(const char *cond, const char *tag, } __android_log_write(ANDROID_LOG_FATAL, tag, buf); - __builtin_trap(); /* trap so we have a chance to debug the situation */ + abort(); /* abort so we have a chance to debug the situation */ /* NOTREACHED */ } diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index 2ca3c94..ca63067 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -266,7 +266,7 @@ void __android_log_assert(const char *cond, const char *tag, } __android_log_write(ANDROID_LOG_FATAL, tag, buf); - __builtin_trap(); /* trap so we have a chance to debug the situation */ + abort(); /* abort so we have a chance to debug the situation */ /* NOTREACHED */ } |