// Events
struct {
sd_event_source* heartbeat;
- sd_event_source* shutdown;
} events;
};
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;
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)
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)