]> git.ipfire.org Git - collecty.git/commitdiff
source: Don't log (non-)errors of async tasks
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 11:41:52 +0000 (11:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 11:41:52 +0000 (11:41 +0000)
We don't want to log the dispatching of a command as "success" if the
actual command later won't execute. So we reserve EINPROGRESS that
sources can signal that something is running...

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/client.c
src/daemon/command.c
src/daemon/source.c

index 41fdc339eeb3955310defc26749c533e91afba85..9b3ee3fa927d291760692148aeafc78dc715e68b 100644 (file)
@@ -414,6 +414,9 @@ int td_client_launch_request(td_client* self, td_request* request) {
        // Let cURL hold a reference to the request object
        td_request_ref(request);
 
+       // Signal that this operation is now in progress
+       r = -EINPROGRESS;
+
 ERROR:
        if (url)
                free(url);
index 4c426a37bca9ef673024dca99c48ac4b522fadb8..f3e99489162e9be0cdef7feb24f1598953c50571 100644 (file)
@@ -616,7 +616,8 @@ static int td_command_parent(td_command* self) {
                }
        }
 
-       return r;
+       // Signal that some operation is in progress
+       return -EINPROGRESS;
 }
 
 static int td_command_child(td_command* self, const char** argv) {
index 6108cfcfc888af38ea86e377524f138008fec735..3ad5a22ba1704adfe8073fdc48f307897bde3a6a 100644 (file)
@@ -196,6 +196,18 @@ static int td_source_error_detection(td_source* self, int result, uint64_t runti
        enum td_source_state state;
        int r;
 
+       // Ignore some return codes
+       switch (-result) {
+               // If the heartbeat callback has launched an asynchronous task (e.g. executing
+               // a command or sending a HTTP request), we will expect this to be signalled
+               // and won't log any errors right now.
+               case EINPROGRESS:
+                       return 0;
+
+               default:
+                       break;
+       }
+
        // Move everything up in the array
        for (unsigned int i = NUM_RESULTS - 1; i > 0; i--)
                self->results.r[i] = self->results.r[i - 1];
@@ -304,8 +316,15 @@ static int td_source_heartbeat(sd_event_source* source, uint64_t usec, void* dat
        // Call the heartbeat method
        r = self->impl->heartbeat(self->ctx, self);
        if (r < 0) {
-               ERROR(self->ctx, "heartbeat() failed for %s: %s\n",
-                       td_source_name(self), strerror(-r));
+               switch (-r) {
+                       case EINPROGRESS:
+                               break;
+
+                       default:
+                               ERROR(self->ctx, "heartbeat() failed for %s: %s\n",
+                                       td_source_name(self), strerror(-r));
+                               break;
+               }
        }
 
        // Fetch the end timestamp