From: Andreas Henriksson Date: Mon, 10 Jun 2013 21:18:04 +0000 (+0200) Subject: Restructure to compile with all combos of HAVE_TCA_STATS(2) X-Git-Tag: collectd-5.4.0~11^2~12 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=adbba9f9a9701461592ce374558b7e54669d2183;p=collectd.git Restructure to compile with all combos of HAVE_TCA_STATS(2) We want to compile with all combinations of HAVE_TCA_STATS(2) set/unset and at the same time protect against submitting the stats twice (if both are supported). Introduce "stats_found" and set and attribute on it to avoid having the compiler complain about it. This allows us to bury the specific structs under each HAVE_TCA_STATS(2) #if ... --- diff --git a/src/netlink.c b/src/netlink.c index 5aaa25bd..65fc0d99 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -369,13 +369,13 @@ static int qos_filter_cb (const struct nlmsghdr *nlh, void *args) const char *dev; const char *kind = NULL; - struct gnet_stats_basic *bs = NULL; - struct tc_stats *ts = NULL; /* char *type_instance; */ char *tc_type; char tc_inst[DATA_MAX_NAME_LEN]; + int __attribute__((unused)) stats_found = 0; + if (tm->tcm_ifindex != wanted_ifindex) { DEBUG ("netlink plugin: qos_filter_cb: Got %s for interface #%i, " @@ -457,6 +457,8 @@ static int qos_filter_cb (const struct nlmsghdr *nlh, void *args) #if HAVE_TCA_STATS2 mnl_attr_for_each (attr, nlh, sizeof (*tm)) { + struct gnet_stats_basic *bs = NULL; + if (mnl_attr_get_type(attr) != TCA_STATS2) continue; @@ -468,10 +470,13 @@ static int qos_filter_cb (const struct nlmsghdr *nlh, void *args) mnl_attr_parse_nested(attr, qos_attr_cb, &bs); + if (bs != NULL) + stats_found = 1; + break; } - if (bs != NULL) + if (stats_found) { char type_instance[DATA_MAX_NAME_LEN]; @@ -486,6 +491,8 @@ static int qos_filter_cb (const struct nlmsghdr *nlh, void *args) #if HAVE_TCA_STATS mnl_attr_for_each (attr, nlh, sizeof (*tm)) { + struct tc_stats *ts = NULL; + if (mnl_attr_get_type(attr) != TCA_STATS) continue; @@ -495,19 +502,21 @@ static int qos_filter_cb (const struct nlmsghdr *nlh, void *args) return MNL_CB_ERROR; } ts = mnl_attr_get_payload(attr); - break; - } - if (bs == NULL && ts != NULL) - { - char type_instance[DATA_MAX_NAME_LEN]; + if (!stats_found && ts != NULL) + { + char type_instance[DATA_MAX_NAME_LEN]; - ssnprintf (type_instance, sizeof (type_instance), "%s-%s", - tc_type, tc_inst); + ssnprintf (type_instance, sizeof (type_instance), "%s-%s", + tc_type, tc_inst); - submit_one (dev, "ipt_bytes", type_instance, ts->bytes); - submit_one (dev, "ipt_packets", type_instance, ts->packets); + submit_one (dev, "ipt_bytes", type_instance, ts->bytes); + submit_one (dev, "ipt_packets", type_instance, ts->packets); + } + + break; } + #endif /* TCA_STATS */ #if !(HAVE_TCA_STATS && HAVE_TCA_STATS2)