From: Michael Tremer Date: Sun, 28 Sep 2025 08:56:03 +0000 (+0000) Subject: daemon: Create scaffolding to format argument lists X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=019ff42cfc90ea754623cc532b059dff9c913ba3;p=telemetry.git daemon: Create scaffolding to format argument lists Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index cd500d3..1a799de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,6 +89,8 @@ bin_PROGRAMS += \ collectyd dist_collectyd_SOURCES = \ + src/daemon/args.c \ + src/daemon/args.h \ src/daemon/ctx.c \ src/daemon/ctx.h \ src/daemon/daemon.c \ diff --git a/src/daemon/args.c b/src/daemon/args.c new file mode 100644 index 0000000..915d920 --- /dev/null +++ b/src/daemon/args.c @@ -0,0 +1,69 @@ +/*############################################################################# +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2025 IPFire Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include +#include + +#include "args.h" +#include "ctx.h" + +struct collecty_args { + collecty_ctx* ctx; + int nrefs; +}; + +static void collecty_args_free(collecty_args* self) { + if (self->ctx) + collecty_ctx_unref(self->ctx); + free(self); +} + +int collecty_args_create(collecty_args** args, collecty_ctx* ctx) { + collecty_args* self = NULL; + + // Allocate some memory + self = calloc(1, sizeof(*self)); + if (!self) + return -errno; + + // Initialize the reference counter + self->nrefs = 1; + + // Keep a reference to the context + self->ctx = collecty_ctx_ref(ctx); + + // Return pointer + *args = self; + return 0; +} + +collecty_args* collecty_args_ref(collecty_args* self) { + ++self->nrefs; + return self; +} + +collecty_args* collecty_args_unref(collecty_args* self) { + if (--self->nrefs > 0) + return self; + + collecty_args_free(self); + return NULL; +} diff --git a/src/daemon/args.h b/src/daemon/args.h new file mode 100644 index 0000000..458a4ee --- /dev/null +++ b/src/daemon/args.h @@ -0,0 +1,33 @@ +/*############################################################################# +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2025 IPFire Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef COLLECTY_ARGS_H +#define COLLECTY_ARGS_H + +typedef struct collecty_args collecty_args; + +#include "ctx.h" + +int collecty_args_create(collecty_args** args, collecty_ctx* ctx); + +collecty_args* collecty_args_ref(collecty_args* self); +collecty_args* collecty_args_unref(collecty_args* self); + +#endif /* COLLECTY_ARGS_H */