summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@cyngn.com>2016-11-08 15:13:05 -0800
committerJessica Wagantall <jwagantall@cyngn.com>2016-11-09 11:59:30 -0800
commit85f740eb6ddaab64983085fb0c7bb8ae850ef828 (patch)
tree3a585316f18d9a8cd52e3727ad665bee3c24b4a5
parent7e1cf25bc3f0b5af9106bc09989d63e5c8c46c37 (diff)
parentdc7cf2204e8dbb2c825bad52f8504921e4a0f2b9 (diff)
downloadsystem_core-85f740eb6ddaab64983085fb0c7bb8ae850ef828.zip
system_core-85f740eb6ddaab64983085fb0c7bb8ae850ef828.tar.gz
system_core-85f740eb6ddaab64983085fb0c7bb8ae850ef828.tar.bz2
Merge tag 'android-6.0.1_r74' into HEAD
CYNGNOS-3303 Android 6.0.1 release 74 Change-Id: I2dade45f30d4ca2fa8c6efa5c7242de1a02f5c15
-rw-r--r--include/android/log.h5
-rw-r--r--liblog/logd_write.c42
-rw-r--r--liblog/logd_write_kern.c35
-rw-r--r--liblog/tests/liblog_test.cpp10
4 files changed, 91 insertions, 1 deletions
diff --git a/include/android/log.h b/include/android/log.h
index 1c171b7..391c826 100644
--- a/include/android/log.h
+++ b/include/android/log.h
@@ -89,6 +89,11 @@ typedef enum android_LogPriority {
} android_LogPriority;
/*
+ * Release any logger resources (a new log write will immediately re-acquire)
+ */
+void __android_log_close();
+
+/*
* Send a simple string to the log.
*/
int __android_log_write(int prio, const char *tag, const char *text);
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index 7f772af..9c4e481 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -323,6 +323,48 @@ const char *android_log_id_to_name(log_id_t log_id)
}
#endif
+/*
+ * Release any logger resources. A new log write will immediately re-acquire.
+ */
+void __android_log_close()
+{
+#if FAKE_LOG_DEVICE
+ int i;
+#endif
+
+#ifdef HAVE_PTHREADS
+ pthread_mutex_lock(&log_init_lock);
+#endif
+
+ write_to_log = __write_to_log_init;
+
+ /*
+ * Threads that are actively writing at this point are not held back
+ * by a lock and are at risk of dropping the messages with a return code
+ * -EBADF. Prefer to return error code than add the overhead of a lock to
+ * each log writing call to guarantee delivery. In addition, anyone
+ * calling this is doing so to release the logging resources and shut down,
+ * for them to do so with outstanding log requests in other threads is a
+ * disengenuous use of this function.
+ */
+#if FAKE_LOG_DEVICE
+ for (i = 0; i < LOG_ID_MAX; i++) {
+ fakeLogClose(log_fds[i]);
+ log_fds[i] = -1;
+ }
+#else
+ close(logd_fd);
+ logd_fd = -1;
+
+ close(pstore_fd);
+ pstore_fd = -1;
+#endif
+
+#ifdef HAVE_PTHREADS
+ pthread_mutex_unlock(&log_init_lock);
+#endif
+}
+
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
{
#if !defined(_WIN32)
diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c
index bd43238..f0c6cb2 100644
--- a/liblog/logd_write_kern.c
+++ b/liblog/logd_write_kern.c
@@ -106,6 +106,41 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
return ret;
}
+/*
+ * Release any logger resources. A new log write will immediately re-acquire.
+ */
+void __android_log_close()
+{
+#ifdef HAVE_PTHREADS
+ pthread_mutex_lock(&log_init_lock);
+#endif
+
+ write_to_log = __write_to_log_init;
+
+ /*
+ * Threads that are actively writing at this point are not held back
+ * by a lock and are at risk of dropping the messages with a return code
+ * -EBADF. Prefer to return error code than add the overhead of a lock to
+ * each log writing call to guarantee delivery. In addition, anyone
+ * calling this is doing so to release the logging resources and shut down,
+ * for them to do so with outstanding log requests in other threads is a
+ * disengenuous use of this function.
+ */
+
+ log_close(log_fds[LOG_ID_MAIN]);
+ log_fds[LOG_ID_MAIN] = -1;
+ log_close(log_fds[LOG_ID_RADIO]);
+ log_fds[LOG_ID_RADIO] = -1;
+ log_close(log_fds[LOG_ID_EVENTS]);
+ log_fds[LOG_ID_EVENTS] = -1;
+ log_close(log_fds[LOG_ID_SYSTEM]);
+ log_fds[LOG_ID_SYSTEM] = -1;
+
+#ifdef HAVE_PTHREADS
+ pthread_mutex_unlock(&log_init_lock);
+#endif
+}
+
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
{
pthread_mutex_lock(&log_init_lock);
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index c987041..0e7fec4 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -127,12 +127,17 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
+ // Check that we can close and reopen the logger
log_time ts(CLOCK_MONOTONIC);
-
ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
+ __android_log_close();
+
+ log_time ts1(CLOCK_MONOTONIC);
+ ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1)));
usleep(1000000);
int count = 0;
+ int second_count = 0;
for (;;) {
log_msg log_msg;
@@ -156,10 +161,13 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
log_time tx(eventData + 4 + 1);
if (ts == tx) {
++count;
+ } else if (ts1 == tx) {
+ ++second_count;
}
}
EXPECT_EQ(1, count);
+ EXPECT_EQ(1, second_count);
android_logger_list_close(logger_list);
}