From: Florian Forster Date: Sat, 25 Nov 2023 23:10:52 +0000 (+0100) Subject: gmond plugin: Improve `mc_handle_metadata_msg()`. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4167%2Fhead;p=thirdparty%2Fcollectd.git gmond plugin: Improve `mc_handle_metadata_msg()`. 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. --- diff --git a/src/gmond.c b/src/gmond.c index 9a5f80870..832c5b03d 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -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;