]> git.ipfire.org Git - telemetry.git/commitdiff
graphs: Write title/vlabel to the stack
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Oct 2025 16:33:10 +0000 (16:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Oct 2025 16:33:10 +0000 (16:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs/conntrack.c
src/daemon/graphs/contextswitches.c
src/daemon/graphs/loadavg.c
src/daemon/graphs/processor.c
src/daemon/graphs/uptime.c

index 248aac445573e0a63a0cc8fd875e76f602600920..1e84cca863eb9afac40b9d02a41e4979aef89bb0 100644 (file)
 #include "graph.h"
 #include "time.h"
 
+// Maximum length of the title/vlabel
+#define TITLE_MAX              128
+#define VLABEL_MAX             64
+
 struct collecty_graph {
        collecty_ctx* ctx;
        int nrefs;
@@ -200,8 +204,8 @@ ERROR:
 int collecty_graph_render(collecty_graph* self, const char* object,
                const collecty_graph_render_options* options, char** buffer, size_t* length) {
        collecty_args* args = NULL;
-       char* vlabel = NULL;
-       char* title = NULL;
+       char vlabel[VLABEL_MAX] = "";
+       char title[TITLE_MAX] = "";
        char** data = NULL;
        FILE* f = NULL;
        int w = 0;
@@ -283,14 +287,14 @@ int collecty_graph_render(collecty_graph* self, const char* object,
        // Set the title
        if (self->impl->title) {
                // Fetch the title
-               r = self->impl->title(self->ctx, self, object, &title);
+               r = self->impl->title(self->ctx, self, object, title, sizeof(title));
                if (r < 0) {
                        ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r));
                        goto ERROR;
                }
 
                // Add the title to the command line
-               if (title) {
+               if (*title) {
                        r = collecty_args_push(args, "--title=%s", title);
                        if (r < 0)
                                goto ERROR;
@@ -300,14 +304,14 @@ int collecty_graph_render(collecty_graph* self, const char* object,
        // Set the vertical label
        if (self->impl->vlabel) {
                // Fetch the vertical label
-               r = self->impl->vlabel(self->ctx, self, object, &vlabel);
+               r = self->impl->vlabel(self->ctx, self, object, vlabel, sizeof(vlabel));
                if (r < 0) {
                        ERROR(self->ctx, "Failed to render the vertical label: %s\n", strerror(-r));
                        goto ERROR;
                }
 
                // Add the vertical label to the command line
-               if (vlabel) {
+               if (*vlabel) {
                        r = collecty_args_push(args, "--vertical-label=%s", vlabel);
                        if (r < 0)
                                goto ERROR;
@@ -379,10 +383,6 @@ ERROR:
                        free(data[i]);
                free(data);
        }
-       if (vlabel)
-               free(vlabel);
-       if (title)
-               free(title);
        if (args)
                collecty_args_unref(args);
        if (f)
index 2f1fc62fc25fecad737d8175c451fc7704cb80c4..5455bbdb699148cea64d5a274b9dec0e0dcecb3c 100644 (file)
@@ -50,11 +50,11 @@ typedef struct collecty_graph_impl {
 
        // Title
        int (*title)(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title);
+               const char* object, char* title, size_t length);
 
        // Vertical Label
        int (*vlabel)(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title);
+               const char* object, char* vlabel, size_t length);
 } collecty_graph_impl;
 
 int collecty_graph_create(collecty_graph** graph,
index c19762b512263b64956928cb95d06bc77b30095a..ea971909c1180e1049e74e5a90d466f6e5770818 100644 (file)
 
 #include <limits.h>
 
+#include "../string.h"
 #include "graph.h"
 #include "conntrack.h"
 
 static int conntrack_title(collecty_ctx* ctx,
-               collecty_graph* graph, const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Connection Tracking Table"));
+               collecty_graph* graph, const char* object, char* title, size_t length) {
+       return __collecty_string_set(title, length, _("Connection Tracking Table"));
 }
 
 static int conntrack_vlabel(collecty_ctx* ctx,
-               collecty_graph* graph, const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Entries"));
+               collecty_graph* graph, const char* object, char* vlabel, size_t length) {
+       return __collecty_string_set(vlabel, length, _("Entries"));
 }
 
 static int conntrack_render(collecty_ctx* ctx,
index 45089efd9fb32e322ef278878f6405b289e65443..5351121bb1286409eed69fb72298a1ed92d2c356 100644 (file)
 
 #include <limits.h>
 
+#include "../string.h"
 #include "graph.h"
 #include "contextswitches.h"
 
 static int contextswitches_title(collecty_ctx* ctx,
-               collecty_graph* graph, const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Context Switches"));
+               collecty_graph* graph, const char* object, char* title, size_t length) {
+       return __collecty_string_set(title, length, _("Context Switches"));
 }
 
 static int contextswitches_vlabel(collecty_ctx* ctx,
-               collecty_graph* graph, const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Context Switches/s"));
+               collecty_graph* graph, const char* object, char* vlabel, size_t length) {
+       return __collecty_string_set(vlabel, length, _("Context Switches/s"));
 }
 
 static int contextswitches_render(collecty_ctx* ctx,
index 7bf1534e2c3d6de5c86ab27e04a46c33aa22f7ed..cd5b537a66bc688e899dacb23bfa08c6dd965c67 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <limits.h>
 
+#include "../string.h"
 #include "graph.h"
 #include "loadavg.h"
 
@@ -29,8 +30,8 @@
 #define COLOR_LOAD1            YELLOW
 
 static int loadavg_title(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Load Average"));
+               const char* object, char* title, size_t length) {
+       return __collecty_string_set(title, length, _("Load Average"));
 }
 
 static int loadavg_render(collecty_ctx* ctx,
index b005808cdf03fd2bfbb46c9f9ab0ef6bdc1b1d5d..093e6560f11afcad1f445406671c4452f27b99bd 100644 (file)
@@ -18,6 +18,7 @@
 #                                                                             #
 #############################################################################*/
 
+#include "../string.h"
 #include "graph.h"
 #include "processor.h"
 
 #define COLOR_IDLE                     LIGHT_GREY
 
 static int processor_title(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Processor Usage"));
+               const char* object, char* title, size_t length) {
+       return __collecty_string_set(title, length, _("Processor Usage"));
 }
 
 static int processor_vlabel(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Percent"));
+               const char* object, char* vlabel, size_t length) {
+       return __collecty_string_set(vlabel, length, _("Percent"));
 }
 
-
 static int processor_render(collecty_ctx* ctx,
                collecty_graph* graph, collecty_args* args, const char* object) {
        int r;
index 1b9e78d3e31be91830080882003928b6cd8b87fd..9d29e475b6028edbaec17c4924a1329c86cf1495 100644 (file)
 
 #include <limits.h>
 
+#include "../string.h"
 #include "graph.h"
 #include "uptime.h"
 
 static int uptime_title(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Uptime"));
+               const char* object, char* title, size_t length) {
+       return __collecty_string_set(title, length, _("Uptime"));
 }
 
 static int uptime_vlabel(collecty_ctx* ctx, collecty_graph* graph,
-               const char* object, char** title) {
-       return collecty_format_title(title, "%s", _("Days"));
+               const char* object, char* vlabel, size_t length) {
+       return __collecty_string_set(vlabel, length, _("Days"));
 }
 
 static int uptime_render(collecty_ctx* ctx,