]> git.ipfire.org Git - telemetry.git/commitdiff
graphs: Catch ENOENT when sources don't exist
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jun 2026 14:39:08 +0000 (14:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jun 2026 14:39:08 +0000 (14:39 +0000)
This catches another case where a source is not active and has never
created an RRD file.

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

index 1f8720eb5b4b550ff44b49306e71cfe7d1612794..fb9470d8c63b9248b705f88090540beb50427589 100644 (file)
@@ -485,8 +485,17 @@ int td_graph_render(td_graph* self, const char* object,
 
        // Call the implementation to add some arguments
        r = self->impl->render(self->ctx, self, options, args, object);
-       if (r < 0)
-               goto ERROR;
+       if (r < 0) {
+               switch (-r) {
+                       // Fall through if we could not find any of the sources, we will
+                       // then create an empty graph instead.
+                       case ENOENT:
+                               break;
+
+                       default:
+                               goto ERROR;
+               }
+       }
 
        // We cannot render the graph if there are no sources
        if (!td_args_has_sources(args)) {
index 62b177f6f7ce3285f9a19e7deb4ae4fe76e83dae..35651202f482a433a39fa25b0446367efeed8620 100644 (file)
@@ -1206,6 +1206,16 @@ int td_source_render(td_source* self, td_args* args, const char* object) {
        if (r < 0)
                return r;
 
+       // Commit any buffered data right now
+       r = td_daemon_flush_source(self->daemon, self, object);
+       if (r < 0)
+               return r;
+
+       // Fail if the path does not exist
+       r = access(path, R_OK);
+       if (r < 0)
+               return -errno;
+
        // Add all data sources
        for (const td_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) {
                r = td_source_render_add_DEF(self, args, path, ds, object);
@@ -1213,6 +1223,5 @@ int td_source_render(td_source* self, td_args* args, const char* object) {
                        return r;
        }
 
-       // Commit any buffered data right now
-       return td_daemon_flush_source(self->daemon, self, object);
+       return 0;
 }