summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2016-07-13 07:38:39 -0700
committerMark Salyzyn <salyzyn@google.com>2016-07-14 07:34:53 -0700
commitec4f5c776d2bde026e2a74128218924be7b3f46a (patch)
treec938befe02e59834eb079dea7153c7eaad48ae98
parent4c06cd86347aa85c9e5999ad5f5ca20ef5f4ac8e (diff)
downloadcore-ec4f5c776d2bde026e2a74128218924be7b3f46a.tar.gz
liblog: reset pid and uid cache after a vfork()
Bionic getuid() and getpid() calls cache to reduce the need to perform a syscall, and also reset their own cache after a vfork(). No more need for liblog to be performing this flawed cache operation. Bug: 30085794 Change-Id: I70feed8bff0ddd919c2885a348ba67b14ddc0e0d
-rw-r--r--liblog/logger.h6
-rw-r--r--liblog/logger_lock.c26
-rw-r--r--liblog/pmsg_writer.c2
3 files changed, 5 insertions, 29 deletions
diff --git a/liblog/logger.h b/liblog/logger.h
index 508725610..2a4cfcb56 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -146,11 +146,13 @@ struct android_log_transport_context {
/* OS specific dribs and drabs */
#if defined(_WIN32)
+#include <private/android_filesystem_config.h>
typedef uint32_t uid_t;
+static inline uid_t __android_log_uid() { return AID_SYSTEM; }
+#else
+static inline uid_t __android_log_uid() { return getuid(); }
#endif
-LIBLOG_HIDDEN uid_t __android_log_uid();
-LIBLOG_HIDDEN pid_t __android_log_pid();
LIBLOG_HIDDEN void __android_log_lock();
LIBLOG_HIDDEN int __android_log_trylock();
LIBLOG_HIDDEN void __android_log_unlock();
diff --git a/liblog/logger_lock.c b/liblog/logger_lock.c
index ee979bd5e..14feee078 100644
--- a/liblog/logger_lock.c
+++ b/liblog/logger_lock.c
@@ -22,34 +22,8 @@
#include <pthread.h>
#endif
-#include <private/android_filesystem_config.h>
-
#include "logger.h"
-LIBLOG_HIDDEN uid_t __android_log_uid()
-{
-#if defined(_WIN32)
- return AID_SYSTEM;
-#else
- static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
-
- if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
- last_uid = getuid();
- }
- return last_uid;
-#endif
-}
-
-LIBLOG_HIDDEN pid_t __android_log_pid()
-{
- static pid_t last_pid = (pid_t) -1;
-
- if (last_pid == (pid_t) -1) {
- last_pid = getpid();
- }
- return last_pid;
-}
-
#if !defined(_WIN32)
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index 2ba31fab1..944febae8 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -142,7 +142,7 @@ static int pmsgWrite(log_id_t logId, struct timespec *ts,
pmsgHeader.magic = LOGGER_MAGIC;
pmsgHeader.len = sizeof(pmsgHeader) + sizeof(header);
pmsgHeader.uid = __android_log_uid();
- pmsgHeader.pid = __android_log_pid();
+ pmsgHeader.pid = getpid();
header.id = logId;
header.tid = gettid();