]> git.ipfire.org Git - collecty.git/commitdiff
daemon: Create scaffolding to format argument lists
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 08:56:03 +0000 (08:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 08:56:03 +0000 (08:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/args.c [new file with mode: 0644]
src/daemon/args.h [new file with mode: 0644]

index cd500d3f21703e8717aa73cebc5db92e5392cf79..1a799de319c2f2a8ab1fe7658b1f74709fc6af8d 100644 (file)
@@ -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 (file)
index 0000000..915d920
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..458a4ee
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#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 */