]> git.ipfire.org Git - collecty.git/commitdiff
daemon: Terminate the event loop if we fail to initialize
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 15:08:03 +0000 (15:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 15:08:03 +0000 (15:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/daemon.c

index 21f11f7eb5183679cd1b1f8b7956054c2113d806..2d116a5b63845e1740212ba7e5512ef24703b1af 100644 (file)
@@ -99,21 +99,27 @@ static int td_daemon_init(sd_event_source* source, void* data) {
        // Initialize all sources
        r = td_sources_create(&self->sources, self->ctx, self, self->enabled_sources);
        if (r < 0)
-               return r;
+               goto ERROR;
 
        // Initialize all graphs
        r = td_graphs_create(&self->graphs, self->ctx, self);
        if (r < 0)
-               return r;
+               goto ERROR;
 
 #ifdef HAVE_SENSORS
        // Initialize sensors
        r = td_sensors_init(self->ctx);
        if (r < 0)
-               return r;
+               goto ERROR;
 #endif /* HAVE_SENSORS */
 
        return 0;
+
+ERROR:
+       ERROR(self->ctx, "Failed to initialize: %s\n", strerror(-r));
+
+       // Terminating the event loop
+       return sd_event_exit(sd_event_source_get_event(source), r);
 }
 
 static int td_daemon_on_exit(sd_event_source* source, void* data) {