]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
fix: Handle metric families with zero metrics gracefully.
authorFlorian Forster <octo@collectd.org>
Fri, 26 Jan 2024 12:13:53 +0000 (13:13 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 29 Jan 2024 10:17:10 +0000 (11:17 +0100)
This allows plugins to call `plugin_dispatch_metric_family()` unconditionally.

src/daemon/plugin.c

index 45155cb060d31ff0fea1098588cb566c90d3a4f9..7ed260503da13999c3e7418f5ce993e172c2ef47 100644 (file)
@@ -2100,9 +2100,13 @@ static void set_default_resource_attributes(metric_family_t *fam) {
 }
 
 EXPORT int plugin_dispatch_metric_family(metric_family_t const *fam) {
-  if ((fam == NULL) || (fam->metric.num == 0)) {
+  if (fam == NULL) {
+    ERROR("plugin_dispatch_metric_family: fam == NULL");
     return EINVAL;
   }
+  if (fam->metric.num == 0) {
+    return 0;
+  }
 
   /* Create a copy of the metric_family_t so we can modify the time and
    * interval without causing confusion when the callee later passes the same