summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2014-05-29 17:53:41 -0700
committerMark Salyzyn <salyzyn@google.com>2014-06-02 12:33:57 -0700
commit076ba81ce997e408c662be438ac37eb532b72eda (patch)
tree79f2ddebacf3db77f1d928deb7b57827af11b330
parent252b0e2b46e3d5e71a8b5c55928dc9ca62811f0a (diff)
downloadsystem_core-076ba81ce997e408c662be438ac37eb532b72eda.zip
system_core-076ba81ce997e408c662be438ac37eb532b72eda.tar.gz
system_core-076ba81ce997e408c662be438ac37eb532b72eda.tar.bz2
liblog: cache getuid() syscall
BUG: 15315766 Change-Id: I8f889a1c6ede74f2621f1b8ea5fda666c4b9cba2
-rw-r--r--liblog/logd_write.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index 121d84d..f10eb8e 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -159,10 +159,14 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
struct timespec ts;
log_time realtime_ts;
size_t i, payload_size;
+ static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
- if (getuid() == AID_LOGD) {
+ if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
+ last_uid = getuid();
+ }
+ if (last_uid == AID_LOGD) { /* logd, after initialization and priv drop */
/*
- * ignore log messages we send to ourself.
+ * ignore log messages we send to ourself (logd).
* Such log messages are often generated by libraries we depend on
* which use standard Android logging.
*/
@@ -193,6 +197,10 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
* };
*/
+ clock_gettime(CLOCK_REALTIME, &ts);
+ realtime_ts.tv_sec = ts.tv_sec;
+ realtime_ts.tv_nsec = ts.tv_nsec;
+
log_id_buf = log_id;
tid = gettid();
@@ -200,11 +208,6 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
newVec[0].iov_len = sizeof_log_id_t;
newVec[1].iov_base = (unsigned char *) &tid;
newVec[1].iov_len = sizeof(tid);
-
- clock_gettime(CLOCK_REALTIME, &ts);
- realtime_ts.tv_sec = ts.tv_sec;
- realtime_ts.tv_nsec = ts.tv_nsec;
-
newVec[2].iov_base = (unsigned char *) &realtime_ts;
newVec[2].iov_len = sizeof(log_time);