From 9ac914c6341817c31c002932e943c932cbffe5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 29 Jan 2025 16:12:06 +0100 Subject: libcamera: base: log: Protect log categories with lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Log categories may be added from any thread, so it is important to synchronize access to the `Logger::categories_` list between its two users: category creation (by LogCategory::create(), which calls Logger::findCategory() and Logger::registerCategory()); and log level setting (by Logger::logSetLevel()). The LogCategory::create() function uses a mutex to serialize category creation, but Logger::logSetLevel() can access `Logger::categories_` concurrently without any protection. To fix the issue, move the mutex to the Logger class, and use it to protect all accesses to the categories list. This requires moving all the logic of LogCategory::create() to a new Logger::findOrCreateCategory() function that combines both Logger::findCategory() and Logger::registerCategory() in order to make the two operations exacute atomically. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/base/log.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h index 1fb92603..8af74b59 100644 --- a/include/libcamera/base/log.h +++ b/include/libcamera/base/log.h @@ -39,6 +39,7 @@ public: static const LogCategory &defaultCategory(); private: + friend class Logger; explicit LogCategory(std::string_view name); const std::string name_; -- cgit v1.2.1