]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
gmond plugin: Improve `mc_handle_metadata_msg()`. 4167/head
authorFlorian Forster <octo@collectd.org>
Sat, 25 Nov 2023 23:10:52 +0000 (00:10 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 25 Nov 2023 23:10:52 +0000 (00:10 +0100)
This function was not properly formatted. While there:

* Handle the error instead of indenting the successful flow.
* Declare variables late.
* Initialize variables when declaring them.

src/gmond.c

index 9a5f80870c7852d0f11835952b3191dc6d5b5935..832c5b03d68c35300ba1494d87fe9ed820827fe9 100644 (file)
@@ -616,50 +616,42 @@ static int mc_handle_value_msg(Ganglia_value_msg *msg) /* {{{ */
 
 static int mc_handle_metadata_msg(Ganglia_metadata_msg *msg) /* {{{ */
 {
-  switch (msg->id) {
-  case gmetadata_full: {
-    Ganglia_metadatadef msg_meta;
-    staging_entry_t *se;
-    const data_set_t *ds;
-    metric_map_t *map;
-
-    msg_meta = msg->Ganglia_metadata_msg_u.gfull;
-
-    if (msg_meta.metric.tmax == 0)
-      return -1;
-
-    map = metric_lookup(msg_meta.metric_id.name);
-    if (map == NULL) {
-      DEBUG("gmond plugin: Not handling meta data %s.",
-            msg_meta.metric_id.name);
-      return 0;
-    }
+  if (msg->id != gmetadata_full) {
+    return -1;
+  }
 
-    ds = plugin_get_ds(map->type);
-    if (ds == NULL) {
-      WARNING("gmond plugin: Could not find data set %s.", map->type);
-      return -1;
-    }
+  Ganglia_metadatadef msg_meta = msg->Ganglia_metadata_msg_u.gfull;
+  if (msg_meta.metric.tmax == 0) {
+    return -1;
+  }
 
-    DEBUG("gmond plugin: Received meta data for %s/%s.",
-          msg_meta.metric_id.host, msg_meta.metric_id.name);
+  metric_map_t *map = metric_lookup(msg_meta.metric_id.name);
+  if (map == NULL) {
+    DEBUG("gmond plugin: Not handling meta data %s.", msg_meta.metric_id.name);
+    return 0;
+  }
 
-    pthread_mutex_lock(&staging_lock);
-    se = staging_entry_get(msg_meta.metric_id.host, msg_meta.metric_id.name,
-                           map->type, map->type_instance, ds->ds_num);
-    if (se != NULL)
-      se->vl.interval = TIME_T_TO_CDTIME_T(msg_meta.metric.tmax);
-    pthread_mutex_unlock(&staging_lock);
+  data_set_t const *ds = plugin_get_ds(map->type);
+  if (ds == NULL) {
+    WARNING("gmond plugin: Could not find data set %s.", map->type);
+    return -1;
+  }
 
-    if (se == NULL) {
-      ERROR("gmond plugin: staging_entry_get failed.");
-      return -1;
-    }
+  DEBUG("gmond plugin: Received meta data for %s/%s.", msg_meta.metric_id.host,
+        msg_meta.metric_id.name);
 
-    break;
+  pthread_mutex_lock(&staging_lock);
+  staging_entry_t *se =
+      staging_entry_get(msg_meta.metric_id.host, msg_meta.metric_id.name,
+                        map->type, map->type_instance, ds->ds_num);
+  if (se != NULL) {
+    se->vl.interval = TIME_T_TO_CDTIME_T(msg_meta.metric.tmax);
   }
+  pthread_mutex_unlock(&staging_lock);
 
-  default: { return -1; }
+  if (se == NULL) {
+    ERROR("gmond plugin: staging_entry_get failed.");
+    return -1;
   }
 
   return 0;