From: Michael Tremer Date: Thu, 4 Jun 2026 16:17:54 +0000 (+0000) Subject: source: Disable sources where we cannot find the command X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7089749d986cc23c0eaa5bfa87361a73429f3a33;p=collecty.git source: Disable sources where we cannot find the command So basically if something has not been installed, we won't try to relaunch it again and again. But that also means that the daemon needs to be restarted after something else has been added. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index c2ffe08..62b177f 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -574,6 +574,29 @@ int td_source_create_command(td_source* self, td_command** command) { return td_command_create(command, self->ctx, self->daemon); } +static int td_source_command_failed(td_ctx* ctx, int rc, td_file* stderr, void* data) { + td_source* self = data; + + // Handle any errors + if (rc < 0) { + switch (-rc) { + // Command not found + case ENOENT: + // Let's disable the source because it does not make sense to repeatedly + // execute any commands that don't exist. + td_source_disable(self); + break; + + // For anything else, we should feed this into the error detection process + // so at least we would lower the heartbeat if there are errors. + default: + return td_source_error_detection(self, rc, 0); + } + } + + return 0; +} + int td_source_run_command(td_source* self, const cap_value_t* caps, const char** argv, td_command_success_callback callback, void* data) { td_command* command = NULL; @@ -591,8 +614,9 @@ int td_source_run_command(td_source* self, const cap_value_t* caps, const char** goto ERROR; } - // Set the callback + // Set the callbacks td_command_on_success(command, callback, data); + td_command_on_failure(command, td_source_command_failed, self); // Execute the command r = td_command_execute(command, argv);