#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
* 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;