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
This commit is contained in:
Tom Cherry 2019-10-02 10:52:55 -07:00
parent 3d8fbfada6
commit 97ec4eecd4

View file

@ -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;
}