summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2019-10-02 10:52:55 -0700
committerTom Cherry <tomcherry@google.com>2019-10-02 14:22:07 -0700
commit97ec4eecd44f04d6c6580846c1efe9acb75bb06b (patch)
treec9aaa91ebdddc791832dcfb039ec5290187efb5a
parent3d8fbfada6d7d2d190d6bdcf6b4fa0b947e769ad (diff)
liblog: don't set transports to nullptr when they close
The old code did not free the transports, just unlink their nodes from the linked list, so there was no race condition between close() and other threads writing to the logs. By settings these to nullptr, I introduced a race condition, but setting them to nullptr isn't necessary, so let's simply not do that. Test: liblog-unit-tests Change-Id: Iec0b680addd13b5d30bd91ccef5bdeab6bf797b0
-rw-r--r--liblog/logger_write.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/liblog/logger_write.cpp b/liblog/logger_write.cpp
index abcead7b6..678e80961 100644
--- a/liblog/logger_write.cpp
+++ b/liblog/logger_write.cpp
@@ -34,8 +34,18 @@
#define LOG_BUF_SIZE 1024
-android_log_transport_write* android_log_write = nullptr;
+#if (FAKE_LOG_DEVICE == 0)
+extern struct android_log_transport_write logdLoggerWrite;
+extern struct android_log_transport_write pmsgLoggerWrite;
+
+android_log_transport_write* android_log_write = &logdLoggerWrite;
+android_log_transport_write* android_log_persist_write = &pmsgLoggerWrite;
+#else
+extern android_log_transport_write fakeLoggerWrite;
+
+android_log_transport_write* android_log_write = &fakeLoggerWrite;
android_log_transport_write* android_log_persist_write = nullptr;
+#endif
static int __write_to_log_init(log_id_t, struct iovec* vec, size_t nr);
static int (*write_to_log)(log_id_t, struct iovec* vec, size_t nr) = __write_to_log_init;
@@ -132,9 +142,6 @@ void __android_log_close() {
android_log_persist_write->close();
}
- android_log_write = nullptr;
- android_log_persist_write = nullptr;
-
#if defined(__ANDROID__)
/*
* Additional risk here somewhat mitigated by immediately unlock flushing
@@ -179,26 +186,11 @@ static bool transport_initialize(android_log_transport_write* transport) {
/* log_init_lock assumed */
static int __write_to_log_initialize() {
-#if (FAKE_LOG_DEVICE == 0)
- extern struct android_log_transport_write logdLoggerWrite;
- extern struct android_log_transport_write pmsgLoggerWrite;
-
- android_log_write = &logdLoggerWrite;
- android_log_persist_write = &pmsgLoggerWrite;
-#else
- extern struct android_log_transport_write fakeLoggerWrite;
-
- android_log_write = &fakeLoggerWrite;
-#endif
-
if (!transport_initialize(android_log_write)) {
- android_log_write = nullptr;
return -ENODEV;
}
- if (!transport_initialize(android_log_persist_write)) {
- android_log_persist_write = nullptr;
- }
+ transport_initialize(android_log_persist_write);
return 1;
}