system/corennnnn
Revision | bd36696a16d3107c9e9503d120d7455dcbfd3fe6 (tree) |
---|---|
Time | 2016-09-08 04:49:08 |
Author | Mark Salyzyn <salyzyn@goog...> |
Commiter | Narayan Kamath |
liblog: add android_log_close()
Bug: 30963384
(cherry picked from commit df7a4c6bae5f85532d79a93b7d9197a2aab17825)
(cherry picked from commit c12d3d250ceb6a4380d2fcaf7f6d30bdea200dad)
Change-Id: Id4313e99bf86b41c3713e1c2db0242d12aeb8bb7
@@ -89,6 +89,11 @@ typedef enum android_LogPriority { | ||
89 | 89 | } android_LogPriority; |
90 | 90 | |
91 | 91 | /* |
92 | + * Release any logger resources (a new log write will immediately re-acquire) | |
93 | + */ | |
94 | +void __android_log_close(); | |
95 | + | |
96 | +/* | |
92 | 97 | * Send a simple string to the log. |
93 | 98 | */ |
94 | 99 | int __android_log_write(int prio, const char *tag, const char *text); |
@@ -132,6 +132,41 @@ LIBLOG_ABI_PUBLIC int __android_log_dev_available() | ||
132 | 132 | } |
133 | 133 | return kLogNotAvailable; |
134 | 134 | } |
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 | +} | |
135 | 170 | |
136 | 171 | /* log_init_lock assumed */ |
137 | 172 | static int __write_to_log_initialize() |
@@ -132,12 +132,17 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) { | ||
132 | 132 | ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( |
133 | 133 | LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); |
134 | 134 | |
135 | + // Check that we can close and reopen the logger | |
135 | 136 | log_time ts(CLOCK_MONOTONIC); |
136 | - | |
137 | 137 | 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))); | |
138 | 142 | usleep(1000000); |
139 | 143 | |
140 | 144 | int count = 0; |
145 | + int second_count = 0; | |
141 | 146 | |
142 | 147 | for (;;) { |
143 | 148 | log_msg log_msg; |
@@ -161,10 +166,13 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) { | ||
161 | 166 | log_time tx(eventData + 4 + 1); |
162 | 167 | if (ts == tx) { |
163 | 168 | ++count; |
169 | + } else if (ts1 == tx) { | |
170 | + ++second_count; | |
164 | 171 | } |
165 | 172 | } |
166 | 173 | |
167 | 174 | EXPECT_EQ(1, count); |
175 | + EXPECT_EQ(1, second_count); | |
168 | 176 | |
169 | 177 | android_logger_list_close(logger_list); |
170 | 178 | } |