From 3af0e57cdd4fa24762609db5660097e8adb08c8a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 29 Sep 2025 17:53:01 +0000 Subject: [PATCH] daemon: Initialize all graphs when the daemon starts Signed-off-by: Michael Tremer --- Makefile.am | 2 ++ src/daemon/daemon.c | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index c5adb6b..8a93aed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,6 +102,8 @@ dist_collectyd_SOURCES = \ src/daemon/graph.h \ src/daemon/graph-bus.c \ src/daemon/graph-bus.h \ + src/daemon/graphs.c \ + src/daemon/graphs.h \ src/daemon/logging.c \ src/daemon/logging.h \ src/daemon/main.c \ diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index d45429e..92715b0 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -28,6 +28,7 @@ #include "bus.h" #include "ctx.h" #include "daemon.h" +#include "graphs.h" #include "graph-bus.h" #include "module.h" #include "modules.h" @@ -54,15 +55,28 @@ struct collecty_daemon { // Queue collecty_queue* queue; + + // Graphs + collecty_graphs* graphs; }; static int collecty_daemon_init(sd_event_source* source, void* data) { collecty_daemon* self = data; + int r; DEBUG(self->ctx, "Initializing daemon...\n"); // Initialize all modules - return collecty_modules_init(self->ctx, self); + r = collecty_modules_init(self->ctx, self); + if (r < 0) + return r; + + // Initialize all graphs + r = collecty_graphs_create(&self->graphs, self->ctx, self); + if (r < 0) + return r; + + return 0; } static int collecty_daemon_exit(sd_event_source* source, void* data) { @@ -70,6 +84,12 @@ static int collecty_daemon_exit(sd_event_source* source, void* data) { DEBUG(self->ctx, "Cleaning up daemon...\n"); + // Free all graphs + if (self->graphs) { + collecty_graphs_unref(self->graphs); + self->graphs = NULL; + } + return 0; } @@ -159,6 +179,8 @@ static void collecty_daemon_free(collecty_daemon* self) { sd_event_source_unref(self->events.init); if (self->events.exit) sd_event_source_unref(self->events.exit); + if (self->graphs) + collecty_graphs_unref(self->graphs); if (self->queue) collecty_queue_unref(self->queue); if (self->ctx) -- 2.47.3