• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisionbd36696a16d3107c9e9503d120d7455dcbfd3fe6 (tree)
Time2016-09-08 04:49:08
AuthorMark Salyzyn <salyzyn@goog...>
CommiterNarayan Kamath

Log Message

liblog: add android_log_close()

Bug: 30963384

(cherry picked from commit df7a4c6bae5f85532d79a93b7d9197a2aab17825)

(cherry picked from commit c12d3d250ceb6a4380d2fcaf7f6d30bdea200dad)

Change-Id: Id4313e99bf86b41c3713e1c2db0242d12aeb8bb7

Change Summary

Incremental Difference

--- a/include/android/log.h
+++ b/include/android/log.h
@@ -89,6 +89,11 @@ typedef enum android_LogPriority {
8989 } android_LogPriority;
9090
9191 /*
92+ * Release any logger resources (a new log write will immediately re-acquire)
93+ */
94+void __android_log_close();
95+
96+/*
9297 * Send a simple string to the log.
9398 */
9499 int __android_log_write(int prio, const char *tag, const char *text);
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -132,6 +132,41 @@ LIBLOG_ABI_PUBLIC int __android_log_dev_available()
132132 }
133133 return kLogNotAvailable;
134134 }
135+/*
136+ * Release any logger resources. A new log write will immediately re-acquire.
137+ */
138+LIBLOG_ABI_PUBLIC void __android_log_close()
139+{
140+ struct android_log_transport_write *transport;
141+
142+ __android_log_lock();
143+
144+ write_to_log = __write_to_log_init;
145+
146+ /*
147+ * Threads that are actively writing at this point are not held back
148+ * by a lock and are at risk of dropping the messages with a return code
149+ * -EBADF. Prefer to return error code than add the overhead of a lock to
150+ * each log writing call to guarantee delivery. In addition, anyone
151+ * calling this is doing so to release the logging resources and shut down,
152+ * for them to do so with outstanding log requests in other threads is a
153+ * disengenuous use of this function.
154+ */
155+
156+ write_transport_for_each(transport, &__android_log_persist_write) {
157+ if (transport->close) {
158+ (*transport->close)();
159+ }
160+ }
161+
162+ write_transport_for_each(transport, &__android_log_transport_write) {
163+ if (transport->close) {
164+ (*transport->close)();
165+ }
166+ }
167+
168+ __android_log_unlock();
169+}
135170
136171 /* log_init_lock assumed */
137172 static int __write_to_log_initialize()
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -132,12 +132,17 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
132132 ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
133133 LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
134134
135+ // Check that we can close and reopen the logger
135136 log_time ts(CLOCK_MONOTONIC);
136-
137137 ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
138+ __android_log_close();
139+
140+ log_time ts1(CLOCK_MONOTONIC);
141+ ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1)));
138142 usleep(1000000);
139143
140144 int count = 0;
145+ int second_count = 0;
141146
142147 for (;;) {
143148 log_msg log_msg;
@@ -161,10 +166,13 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
161166 log_time tx(eventData + 4 + 1);
162167 if (ts == tx) {
163168 ++count;
169+ } else if (ts1 == tx) {
170+ ++second_count;
164171 }
165172 }
166173
167174 EXPECT_EQ(1, count);
175+ EXPECT_EQ(1, second_count);
168176
169177 android_logger_list_close(logger_list);
170178 }