From: Michael Tremer Date: Sun, 26 Oct 2025 16:40:41 +0000 (+0000) Subject: source: Run some basic checks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=054ad46915c0897ed9f8c4b7de9339f79cf5cc55;p=telemetry.git source: Run some basic checks Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index a116c68..aaac3cf 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -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)