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;
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);