liblog: add __android_log_close()
Bug: 30963384
(cherry picked from commit df7a4c6bae5f85532d79a93b7d9197a2aab17825)
Change-Id: Iee7cd0db819644299fa086586630e71415643294
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index b802ed7..c7b5a84 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -132,6 +132,41 @@
}
return kLogNotAvailable;
}
+/*
+ * Release any logger resources. A new log write will immediately re-acquire.
+ */
+LIBLOG_ABI_PUBLIC void __android_log_close()
+{
+ struct android_log_transport_write *transport;
+
+ __android_log_lock();
+
+ 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.
+ */
+
+ write_transport_for_each(transport, &__android_log_persist_write) {
+ if (transport->close) {
+ (*transport->close)();
+ }
+ }
+
+ write_transport_for_each(transport, &__android_log_transport_write) {
+ if (transport->close) {
+ (*transport->close)();
+ }
+ }
+
+ __android_log_unlock();
+}
/* log_init_lock assumed */
static int __write_to_log_initialize()