]> git.ipfire.org Git - oddments/collecty.git/commitdiff
source: Run some basic checks
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Oct 2025 16:40:41 +0000 (16:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Oct 2025 16:40:41 +0000 (16:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index a116c68a4aa95fd854d1134085107784f8dffbca..aaac3cff72c30cb6c11853c23ae413b991dd1908 100644 (file)
@@ -384,6 +384,23 @@ static int td_source_init(td_source* self) {
        return r;
 }
 
+static int td_source_check(td_source* self) {
+       // Check if name is set
+       if (!self->impl->name) {
+               ERROR(self->ctx, "Source has no name\n");
+               return -EINVAL;
+       }
+
+       // Check if either init or heartbeat exists
+       if (!self->impl->init && !self->impl->heartbeat) {
+               ERROR(self->ctx, "Source %s has neither an init, nor a heartbeat function\n",
+                       td_source_name(self));
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static void td_source_free(td_source* self) {
        if (self->impl->free)
                self->impl->free(self->ctx);
@@ -423,6 +440,11 @@ int td_source_create(td_source** source,
        // Store the implementation
        self->impl = impl;
 
+       // Check if the implementation is complete
+       r = td_source_check(self);
+       if (r < 0)
+               goto ERROR;
+
        // Register heartbeat
        r = td_source_register_heartbeat(self);
        if (r < 0)