From: Michael Tremer Date: Sat, 27 Sep 2025 12:00:45 +0000 (+0000) Subject: daemon: Create more daemon scaffolding X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9ad97844dc0e28ad31f29a32a8e74a2cb5744d63;p=collecty.git daemon: Create more daemon scaffolding Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 3ba95af..32c9f72 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..13bb41f --- /dev/null +++ b/src/daemon/daemon.c @@ -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 . # +# # +#############################################################################*/ + +#include +#include + +#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 index 0000000..04ecc65 --- /dev/null +++ b/src/daemon/daemon.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_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 */