daemon: extract reader start-up to a function 10/305110/2
authorMichal Bloch <m.bloch@samsung.com>
Thu, 25 Jan 2024 18:13:44 +0000 (19:13 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 1 Feb 2024 17:59:18 +0000 (18:59 +0100)
Later on, zlogger readers will be wired up cleanly as well.

Change-Id: I13168087ef460e74c203ab0f0311b91f6f2421ef

src/logger/logger.c

index 17c6805..7f05bca 100644 (file)
@@ -1082,6 +1082,30 @@ static void register_low_mem_handler(struct logger *server) { }
 
 #endif
 
+static int reader_cleanup_subless_and_run(void *_reader, struct logger *server)
+{
+       assert(_reader);
+       struct reader_common *const reader = *((struct reader_common **)_reader);
+
+       if (!reader)
+               return 0;
+
+       int ret = 0;
+       if (!reader->subs)
+               goto cleanup;
+
+       ret = reader_run(reader, server);
+       if (ret < 0)
+               goto cleanup;
+
+       return 0;
+
+cleanup:
+       reader_free(reader);
+       *((struct reader_common **)_reader) = NULL;
+       return ret;
+}
+
 /**
  * @brief Finalize initialisation
  * @details Do misc stuff needed at the end of the initialisation
@@ -1109,22 +1133,9 @@ static int finalize_init(struct logger_config_data *data, struct logger *server)
         * runtime, so this is the time to do some
         * processing that relies on subs being ready. */
        for (log_id_t id = 0; id < LOG_ID_MAX; ++id) {
-               struct reader_logger *const reader = g_backend.logger_readers[id];
-               if (!reader)
-                       continue;
-
-               if (reader->common.subs == NULL) {
-                       reader_free(&reader->common);
-                       g_backend.logger_readers[id] = NULL;
-                       continue;
-               }
-
-               r = reader_run(&reader->common, server);
-               if (r < 0) {
-                       reader_free(&reader->common);
-                       g_backend.logger_readers[id] = NULL;
+               r = reader_cleanup_subless_and_run(g_backend.logger_readers + id, server);
+               if (r < 0)
                        return r;
-               }
        }
 
        return 0;