]> git.ipfire.org Git - collecty.git/commitdiff
daemon: Create more daemon scaffolding
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 12:00:45 +0000 (12:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 12:00:45 +0000 (12:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/daemon.c [new file with mode: 0644]
src/daemon/daemon.h [new file with mode: 0644]

index 3ba95af24ea0d6525610e8c5c675fe7ec7bddef1..32c9f72ec9a4dc28190300ad8da02074a5c08475 100644 (file)
@@ -91,6 +91,8 @@ bin_PROGRAMS += \
 dist_collectyd_SOURCES = \
        src/daemon/ctx.c \
        src/daemon/ctx.h \
+       src/daemon/daemon.c \
+       src/daemon/daemon.h \
        src/daemon/logging.c \
        src/daemon/logging.h \
        src/daemon/main.c
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
new file mode 100644 (file)
index 0000000..13bb41f
--- /dev/null
@@ -0,0 +1,68 @@
+/*#############################################################################
+#                                                                             #
+# 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 <stdlib.h>
+
+#include "ctx.h"
+#include "daemon.h"
+
+struct collecty_daemon {
+       collecty_ctx* ctx;
+       int nrefs;
+};
+
+static void collecty_daemon_free(collecty_daemon* daemon) {
+       if (daemon->ctx)
+               collecty_ctx_unref(daemon->ctx);
+}
+
+int collecty_daemon_create(collecty_daemon** daemon, collecty_ctx* ctx) {
+       collecty_daemon* self = NULL;
+
+       // Allocate some memory
+       self = calloc(1, sizeof(*self));
+       if (!self)
+               return -errno;
+
+       // Initialize the reference counter
+       self->nrefs = 1;
+
+       // Store a reference to the context
+       self->ctx = collecty_ctx_ref(ctx);
+
+       // Return the pointer
+       *daemon = self;
+
+       return 0;
+}
+
+collecty_daemon* collecty_daemon_ref(collecty_daemon* daemon) {
+       ++daemon->nrefs;
+       return daemon;
+}
+
+collecty_daemon* collecty_daemon_unref(collecty_daemon* daemon) {
+       if (--daemon->nrefs > 0)
+               return daemon;
+
+       collecty_daemon_free(daemon);
+       return NULL;
+}
diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h
new file mode 100644 (file)
index 0000000..04ecc65
--- /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_DAEMON_H
+#define COLLECTY_DAEMON_H
+
+typedef struct collecty_daemon collecty_daemon;
+
+#include "ctx.h"
+
+int collecty_daemon_create(collecty_daemon** daemon, collecty_ctx* ctx);
+
+collecty_daemon* collecty_daemon_ref(collecty_daemon* daemon);
+collecty_daemon* collecty_daemon_unref(collecty_daemon* daemon);
+
+#endif /* COLLECTY_DAEMON_H */