summaryrefslogtreecommitdiffstats
path: root/daemon/service.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-01 06:15:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-01 06:15:11 +0000
commit483926a283e118590da3f9ecfa75a8a4d62143ce (patch)
treecb77052778df9a128a8cd3ff5bf7645322a13bc5 /daemon/service.c
parentReleasing debian version 1.31.0-4. (diff)
downloadnetdata-483926a283e118590da3f9ecfa75a8a4d62143ce.tar.xz
netdata-483926a283e118590da3f9ecfa75a8a4d62143ce.zip
Merging upstream version 1.32.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'daemon/service.c')
-rw-r--r--daemon/service.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/daemon/service.c b/daemon/service.c
new file mode 100644
index 000000000..9cba0694f
--- /dev/null
+++ b/daemon/service.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "common.h"
+
+/* Run service jobs every X seconds */
+#define SERVICE_HEARTBEAT 10
+
+void service_main_cleanup(void *ptr)
+{
+ struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
+ static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
+
+ debug(D_SYSTEM, "Cleaning up...");
+
+ static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
+}
+
+/*
+ * The service thread.
+ */
+void *service_main(void *ptr)
+{
+ netdata_thread_cleanup_push(service_main_cleanup, ptr);
+ heartbeat_t hb;
+ heartbeat_init(&hb);
+ usec_t step = USEC_PER_SEC * SERVICE_HEARTBEAT;
+
+ debug(D_SYSTEM, "Service thread starts");
+
+ while (!netdata_exit) {
+ heartbeat_next(&hb, step);
+
+ rrd_cleanup_obsolete_charts();
+ }
+
+ netdata_thread_cleanup_pop(1);
+ return NULL;
+}