]> git.ipfire.org Git - collecty.git/commitdiff
source: Disable sources where we cannot find the command
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Jun 2026 16:17:54 +0000 (16:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Jun 2026 16:17:54 +0000 (16:17 +0000)
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 <michael.tremer@ipfire.org>
src/daemon/source.c

index c2ffe0873775535fb524832cd49f473f15d0edfd..62b177f6f7ce3285f9a19e7deb4ae4fe76e83dae 100644 (file)
@@ -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);