From: Michael Tremer Date: Thu, 2 Oct 2025 09:03:23 +0000 (+0000) Subject: module: Remove hack where the event loop stores the reference X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=24dc3bfa1d18faa172eadea81759a7c6addca48f;p=collecty.git module: Remove hack where the event loop stores the reference This was needed when we did not have a proper registry for all modules, but it seems that that is now the easier way. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/module.c b/src/daemon/module.c index 02dd238..db7e06c 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -79,7 +79,6 @@ struct collecty_module { // Events struct { sd_event_source* heartbeat; - sd_event_source* shutdown; } events; }; @@ -127,30 +126,6 @@ static int collecty_module_register_heartbeat(collecty_module* self) { return 0; } -static int collecty_module_shutdown(sd_event_source* source, void* data) { - collecty_module* self = data; - - DEBUG(self->ctx, "Shutting down module '%s'\n", collecty_module_name(self)); - - // Decrement the reference counter to free the module - collecty_module_unref(self); - - return 0; -} - -static int collecty_module_register_shutdown(collecty_module* self) { - int r; - - // Call the shutdown function when the loop exits - r = sd_event_add_exit(self->loop, &self->events.shutdown, - collecty_module_shutdown, collecty_module_ref(self)); - if (r < 0) { - ERROR(self->ctx, "Failed to register module shutdown: %s\n", strerror(-r)); - } - - return r; -} - static int collecty_module_init(collecty_module* self) { int r; @@ -173,8 +148,6 @@ static void collecty_module_free(collecty_module* self) { self->methods->free(self->ctx); if (self->events.heartbeat) sd_event_source_unref(self->events.heartbeat); - if (self->events.shutdown) - sd_event_source_unref(self->events.shutdown); if (self->loop) sd_event_unref(self->loop); if (self->daemon) @@ -214,11 +187,6 @@ int collecty_module_create(collecty_module** module, if (r < 0) goto ERROR; - // Register shutdown - r = collecty_module_register_shutdown(self); - if (r < 0) - goto ERROR; - // Initialize the module r = collecty_module_init(self); if (r < 0)