]> git.ipfire.org Git - collecty.git/commitdiff
module: Remove hack where the event loop stores the reference
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 09:03:23 +0000 (09:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 09:03:23 +0000 (09:03 +0000)
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 <michael.tremer@ipfire.org>
src/daemon/module.c

index 02dd23881b0004bbb01512f15c5509ace4be3f32..db7e06cfb22a21f2aa7120e201144e8315642641 100644 (file)
@@ -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)