]> git.ipfire.org Git - oddments/collecty.git/commitdiff
client: Print any error messages from the daemon
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 14:44:18 +0000 (14:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 14:44:18 +0000 (14:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client/main.c

index 07776d99c2ec776dee16f2c90847c26923f3676b..957b0987816b32fd4b606b9530501ea4745777ab 100644 (file)
@@ -132,6 +132,7 @@ static int render(td_client_ctx* ctx) {
        sd_bus_message* reply = NULL;
        const void* buffer = NULL;
        sd_bus_message* m = NULL;
+       sd_bus_error error = {};
        char path[PATH_MAX];
        size_t bytes_written = 0;
        size_t length = 0;
@@ -181,15 +182,38 @@ static int render(td_client_ctx* ctx) {
                        goto ERROR;
        }
 
+       // Send from when we want the graph to be rendered
+       if (ctx->interval.since) {
+               r = sd_bus_message_append(m, "{sv}", "since", "s", ctx->interval.since);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Send until when we want the graph to be rendered
+       if (ctx->interval.until) {
+               r = sd_bus_message_append(m, "{sv}", "until", "s", ctx->interval.until);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Close the array
        r = sd_bus_message_close_container(m);
        if (r < 0)
                goto ERROR;
 
        // Call the message
-       r = sd_bus_call(ctx->bus, m, 0, NULL, &reply);
+       r = sd_bus_call(ctx->bus, m, 0, &error, &reply);
        if (r < 0) {
-               perror("Failed to call the Render() method");
+               // Fetch the error code
+               errno = sd_bus_error_get_errno(&error);
+
+               // Print the error message
+               if (error.message) {
+                       fprintf(stderr, "%s: %s\n", program_invocation_name, error.message);
+               } else {
+                       perror("Failed to call the Render() method");
+               }
+
                goto ERROR;
        }