From 7307fbfc09b63f973a310e325f33208b446231ad Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Mon, 9 Oct 2023 11:38:42 +0200 Subject: [PATCH] Fix: generic cleanup for logger readers Also solves a performance/behaviour issue. Change-Id: I4c546d8e3479b7498c9ed2def85b7f710672b07b --- src/logger/logger.c | 17 +++++++---------- src/logger/reader_logger.c | 2 ++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/logger/logger.c b/src/logger/logger.c index 08c5baa..84fbac0 100644 --- a/src/logger/logger.c +++ b/src/logger/logger.c @@ -1333,21 +1333,18 @@ cleanup: if (ret != DLOG_EXIT_SUCCESS) wake_on_exit_signal_received(&sigmar); - /* This doesn't happen earlier because these readers aren't really - * supposed to die and there's a limited number of them. Turns out - * reading a ring buffer can turn you into a ring wraith. */ - for (log_id_t id = 0; id < LOG_ID_MAX; ++id) { - struct reader_logger *const reader = g_backend.logger_readers[id]; - if (!reader) - continue; - reader_free(&reader->common); - } - /* Threads use the server struct so we have to let them finish first. * Spin instead of doing some fancy tracking because this is only for * warnings in the early-quit case, not worth overengineering for. */ while (server.reader_thread_count > 0); + /* Ideally we would also check this for pipe readers, though we don't + * really keep proper track of those. Logger readers aren't otherwise + * supposed to die and there's a limited number of them. Turns out + * reading a ring buffer can turn you into a ring wraith. */ + for (log_id_t id = 0; id < LOG_ID_MAX; ++id) + assert(!g_backend.logger_readers[id]); + free_config_data(&data); logger_free(&server); return ret; diff --git a/src/logger/reader_logger.c b/src/logger/reader_logger.c index ba91b4b..9a042d1 100644 --- a/src/logger/reader_logger.c +++ b/src/logger/reader_logger.c @@ -171,6 +171,8 @@ static void *reader_logger_thread(void *userdata) } reader_service(&reader->common); + g_backend.logger_readers[reader->buf_id] = NULL; + reader_thread_finished(&reader->common); return NULL; } -- 2.7.4