• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

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

system/corennnnn


Commit MetaInfo

Revision2d149691552676968b7de337f543463b920578b0 (tree)
Zeit2016-09-05 23:50:58
AutorMark Salyzyn <salyzyn@goog...>
CommiterNarayan Kamath

Log Message

liblog: add android_log_close()

Bug: 30963384

(cherry picked from commit df7a4c6bae5f85532d79a93b7d9197a2aab17825)

Change-Id: I2255486e84dd55af0f4e7fbbfb616c2deb1765d0

Ändern Zusammenfassung

Diff

--- 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/logd_write.c
+++ b/liblog/logd_write.c
@@ -282,6 +282,45 @@ const char *android_log_id_to_name(log_id_t log_id)
282282 }
283283 #endif
284284
285+/*
286+ * Release any logger resources. A new log write will immediately re-acquire.
287+ */
288+void __android_log_close()
289+{
290+#if FAKE_LOG_DEVICE
291+ int i;
292+#endif
293+
294+#ifdef HAVE_PTHREADS
295+ pthread_mutex_lock(&log_init_lock);
296+#endif
297+
298+ write_to_log = __write_to_log_init;
299+
300+ /*
301+ * Threads that are actively writing at this point are not held back
302+ * by a lock and are at risk of dropping the messages with a return code
303+ * -EBADF. Prefer to return error code than add the overhead of a lock to
304+ * each log writing call to guarantee delivery. In addition, anyone
305+ * calling this is doing so to release the logging resources and shut down,
306+ * for them to do so with outstanding log requests in other threads is a
307+ * disengenuous use of this function.
308+ */
309+#if FAKE_LOG_DEVICE
310+ for (i = 0; i < LOG_ID_MAX; i++) {
311+ fakeLogClose(log_fds[i]);
312+ log_fds[i] = -1;
313+ }
314+#else
315+ close(logd_fd);
316+ logd_fd = -1;
317+#endif
318+
319+#ifdef HAVE_PTHREADS
320+ pthread_mutex_unlock(&log_init_lock);
321+#endif
322+}
323+
285324 static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
286325 {
287326 #ifdef HAVE_PTHREADS
--- a/liblog/logd_write_kern.c
+++ b/liblog/logd_write_kern.c
@@ -117,6 +117,41 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
117117 return ret;
118118 }
119119
120+/*
121+ * Release any logger resources. A new log write will immediately re-acquire.
122+ */
123+void __android_log_close()
124+{
125+#ifdef HAVE_PTHREADS
126+ pthread_mutex_lock(&log_init_lock);
127+#endif
128+
129+ write_to_log = __write_to_log_init;
130+
131+ /*
132+ * Threads that are actively writing at this point are not held back
133+ * by a lock and are at risk of dropping the messages with a return code
134+ * -EBADF. Prefer to return error code than add the overhead of a lock to
135+ * each log writing call to guarantee delivery. In addition, anyone
136+ * calling this is doing so to release the logging resources and shut down,
137+ * for them to do so with outstanding log requests in other threads is a
138+ * disengenuous use of this function.
139+ */
140+
141+ log_close(log_fds[LOG_ID_MAIN]);
142+ log_fds[LOG_ID_MAIN] = -1;
143+ log_close(log_fds[LOG_ID_RADIO]);
144+ log_fds[LOG_ID_RADIO] = -1;
145+ log_close(log_fds[LOG_ID_EVENTS]);
146+ log_fds[LOG_ID_EVENTS] = -1;
147+ log_close(log_fds[LOG_ID_SYSTEM]);
148+ log_fds[LOG_ID_SYSTEM] = -1;
149+
150+#ifdef HAVE_PTHREADS
151+ pthread_mutex_unlock(&log_init_lock);
152+#endif
153+}
154+
120155 static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
121156 {
122157 #ifdef HAVE_PTHREADS
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -124,12 +124,17 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
124124 ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
125125 LOG_ID_EVENTS, O_RDONLY | O_NDELAY, 1000, pid)));
126126
127+ // Check that we can close and reopen the logger
127128 log_time ts(CLOCK_MONOTONIC);
128-
129129 ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
130+ __android_log_close();
131+
132+ log_time ts1(CLOCK_MONOTONIC);
133+ ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1)));
130134 usleep(1000000);
131135
132136 int count = 0;
137+ int second_count = 0;
133138
134139 for (;;) {
135140 log_msg log_msg;
@@ -153,10 +158,13 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
153158 log_time tx(eventData + 4 + 1);
154159 if (ts == tx) {
155160 ++count;
161+ } else if (ts1 == tx) {
162+ ++second_count;
156163 }
157164 }
158165
159166 EXPECT_EQ(1, count);
167+ EXPECT_EQ(1, second_count);
160168
161169 android_logger_list_close(logger_list);
162170 }