From 8b11c4cec21dc8eedd153866ce738614cfae57e6 Mon Sep 17 00:00:00 2001 From: Geremy Condra Date: Thu, 7 Jun 2012 17:45:06 -0700 Subject: [PATCH] Adding event logging to libc. I've basically just copied the relevant bits out of liblog and EventLog.cpp. While this will let us do the uid logging we want to address the concerns in 245c07027f78565858dd489eb0d94c3d48743e9d it doesn't give us much else. Change-Id: Icac6ff20bc0a3ade5927f6f76fedffe1ae6f8522 --- libc/bionic/logd_write.c | 42 +++++++++++++++++++++++++++++++++++++++- libc/private/logd.h | 3 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/libc/bionic/logd_write.c b/libc/bionic/logd_write.c index 2bc39fa4f..ac71689cc 100644 --- a/libc/bionic/logd_write.c +++ b/libc/bionic/logd_write.c @@ -64,6 +64,7 @@ typedef enum { LOG_ID_NONE = 0, LOG_ID_MAIN, LOG_ID_RADIO, + LOG_ID_EVENTS, LOG_ID_MAX } log_id_t; @@ -84,7 +85,8 @@ static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; static log_channel_t log_channels[LOG_ID_MAX] = { { __write_to_log_null, -1, NULL }, { __write_to_log_init, -1, "/dev/"LOGGER_LOG_MAIN }, - { __write_to_log_init, -1, "/dev/"LOGGER_LOG_RADIO } + { __write_to_log_init, -1, "/dev/"LOGGER_LOG_RADIO }, + { __write_to_log_init, -1, "/dev/"LOGGER_LOG_EVENTS } }; /* Important: see technical note at start of source file */ @@ -207,3 +209,41 @@ int __libc_android_log_assert(const char *cond, const char *tag, return -1; } + +/* + * Event logging. + */ + +// must be kept in sync with frameworks/base/core/java/android/util/EventLog.java +typedef enum { + EVENT_TYPE_INT = 0, + EVENT_TYPE_LONG = 1, + EVENT_TYPE_STRING = 2, + EVENT_TYPE_LIST = 3, +} AndroidEventLogType; + +static int __libc_android_log_btwrite(int32_t tag, char type, const void *payload, size_t len) +{ + struct iovec vec[3]; + + vec[0].iov_base = &tag; + vec[0].iov_len = sizeof(tag); + vec[1].iov_base = &type; + vec[1].iov_len = sizeof(type); + vec[2].iov_base = (void*)payload; + vec[2].iov_len = len; + + return log_channels[LOG_ID_EVENTS].logger(LOG_ID_EVENTS, vec); +} + +__LIBC_HIDDEN__ +void __libc_android_log_event_int(int32_t tag, int value) +{ + __libc_android_log_btwrite(tag, EVENT_TYPE_INT, &value, sizeof(value)); +} + +__LIBC_HIDDEN__ +void __libc_android_log_event_uid(int32_t tag) +{ + __libc_android_log_event_int(tag, getuid()); +} diff --git a/libc/private/logd.h b/libc/private/logd.h index 4a9b62e83..37d4104e5 100644 --- a/libc/private/logd.h +++ b/libc/private/logd.h @@ -48,4 +48,7 @@ int __libc_android_log_write(int prio, const char* tag, const char* buffer); int __libc_android_log_print(int prio, const char *tag, const char *fmt, ...); int __libc_android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap); +void __libc_android_log_event_int(int32_t tag, int value); +void __libc_android_log_event_uid(int32_t tag); + #endif /* _ANDROID_BIONIC_LOGD_H */