From: Michael Tremer Date: Sat, 27 Sep 2025 18:04:38 +0000 (+0000) Subject: module: Create scaffolding to create the database if it does not exist X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a64a45e088b4ad47845955f408b1e171b7dd2d14;p=telemetry.git module: Create scaffolding to create the database if it does not exist Signed-off-by: Michael Tremer --- diff --git a/src/daemon/module.c b/src/daemon/module.c index 8b9cd6a..0af412a 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -268,11 +269,20 @@ int collecty_module_submit(collecty_module* self, return collecty_daemon_submit(self->daemon, self, object, value); } +static int collecty_module_create_database(collecty_module* self, const char* path) { + DEBUG(self->ctx, "Creating database for %s at %s\n", collecty_module_name(self), path); + + // XXX TODO + + return 0; +} + /* Called to write all collected samples to disk */ int collecty_module_commit(collecty_module* self, const char* object, unsigned int num_samples, const char** samples) { + struct stat st = {}; char path[PATH_MAX]; int r; @@ -281,6 +291,21 @@ int collecty_module_commit(collecty_module* self, if (r < 0) return r; + // Try to stat() the file + r = stat(path, &st); + if (r < 0) { + switch (errno) { + case ENOENT: + r = collecty_module_create_database(self, path); + if (r < 0) + return r; + break; + + default: + return -errno; + } + } + // Write the samples r = rrd_update_r(path, NULL, num_samples, samples); if (r < 0) {