From: Michael Tremer Date: Fri, 10 Jul 2026 11:35:50 +0000 (+0000) Subject: source: Add a default request handler X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f4257428c3d7edc27bbb5451b2dd46902af5928;p=telemetry.git source: Add a default request handler This function catches basic cURL errors (e.g. host unreachable, etc) so that we will throttle sending requests at some point. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index c9e4617..6108cfc 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -640,6 +640,41 @@ ERROR: return r; } +static int td_source_request_failed(td_ctx* ctx, int code, td_file* file, void* data) { + td_source* self = data; + int r; + + switch (code) { + case CURLE_OK: + r = 0; + break; + + // For unrecoverable errors, we will disable the source straight away + case CURLE_UNSUPPORTED_PROTOCOL: + case CURLE_NOT_BUILT_IN: + case CURLE_RANGE_ERROR: + return td_source_disable(self); + + // Invalid requests + case CURLE_URL_MALFORMAT: + r = -EINVAL; + break; + + // Failed to connect + case CURLE_COULDNT_CONNECT: + r = -ECONNREFUSED; + break; + + // Handle anything else that is unknown + default: + r = -EINVAL; + break; + } + + // Run the error detection + return td_source_error_detection(self, r, 0); +} + int td_source_create_request(td_source* self, td_request** request) { td_client* client = NULL; int r; @@ -654,6 +689,9 @@ int td_source_create_request(td_source* self, td_request** request) { if (r < 0) goto ERROR; + // Set the failure callback + td_request_on_failure(*request, td_source_request_failed, self); + ERROR: if (client) td_client_unref(client);