X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fovs_stats.c;h=e22e851e2545974d6f24325953ad038b3e2bdba1;hp=1bf8e4e67eb21554f283676bd2e6c683c4241723;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=736d8cfea4be361591d3c30d6a7e8be7a21a91d9 diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 1bf8e4e6..e22e851e 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -28,9 +28,9 @@ * Taras Chornyi */ -#include "common.h" +#include "utils/common/common.h" -#include "utils_ovs.h" /* OvS helpers */ +#include "utils/ovs/ovs.h" /* OvS helpers */ /* Plugin name */ static const char plugin_name[] = "ovs_stats"; @@ -280,8 +280,13 @@ static void ovs_stats_submit_interfaces(port_list_t *port) { if (strlen(iface->ex_iface_id)) meta_data_add_string(meta, "iface-id", iface->ex_iface_id); } - snprintf(devname, sizeof(devname), "%s.%s.%s", bridge->name, port->name, - iface->name); + strjoin(devname, sizeof(devname), + (char *[]){ + bridge->name, + port->name, + iface->name, + }, + 3, "."); ovs_stats_submit_one(devname, "if_collisions", NULL, iface->stats[collisions], meta); ovs_stats_submit_two(devname, "if_dropped", NULL, iface->stats[rx_dropped], @@ -391,16 +396,16 @@ static void ovs_stats_submit_port(port_list_t *port) { for (interface_list_t *iface = port->iface; iface != NULL; iface = iface->next) { - snprintf(key_str, sizeof(key_str), "uuid%d", i); + ssnprintf(key_str, sizeof(key_str), "uuid%d", i); meta_data_add_string(meta, key_str, iface->iface_uuid); if (strlen(iface->ex_vm_id)) { - snprintf(key_str, sizeof(key_str), "vm-uuid%d", i); + ssnprintf(key_str, sizeof(key_str), "vm-uuid%d", i); meta_data_add_string(meta, key_str, iface->ex_vm_id); } if (strlen(iface->ex_iface_id)) { - snprintf(key_str, sizeof(key_str), "iface-id%d", i); + ssnprintf(key_str, sizeof(key_str), "iface-id%d", i); meta_data_add_string(meta, key_str, iface->ex_iface_id); } @@ -408,7 +413,7 @@ static void ovs_stats_submit_port(port_list_t *port) { } } bridge_list_t *bridge = port->br; - snprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name); + ssnprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name); ovs_stats_submit_one(devname, "if_collisions", NULL, ovs_stats_get_port_stat_value(port, collisions), meta); ovs_stats_submit_two(devname, "if_dropped", NULL, @@ -579,8 +584,8 @@ static interface_list_t *ovs_stats_new_port_interface(port_list_t *port, interface_list_t *iface = ovs_stats_get_port_interface(port, uuid); if (iface == NULL) { - iface = (interface_list_t *)calloc(1, sizeof(interface_list_t)); - if (!iface) { + iface = calloc(1, sizeof(*iface)); + if (iface == NULL) { ERROR("%s: Error allocating interface", plugin_name); return NULL; } @@ -602,8 +607,8 @@ static port_list_t *ovs_stats_new_port(bridge_list_t *bridge, port_list_t *port = ovs_stats_get_port(uuid); if (port == NULL) { - port = (port_list_t *)calloc(1, sizeof(port_list_t)); - if (!port) { + port = calloc(1, sizeof(*port)); + if (port == NULL) { ERROR("%s: Error allocating port", plugin_name); return NULL; } @@ -703,7 +708,7 @@ static int ovs_stats_update_bridge(yajl_val bridge) { ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name)); if (br == NULL) { br = calloc(1, sizeof(*br)); - if (!br) { + if (br == NULL) { ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br)); return -1; } @@ -857,7 +862,7 @@ static int ovs_stats_update_port(const char *uuid, yajl_val port) { // ifaces_list is [[ "uuid", "" ], [ "uuid", // "" ], ... ]] - for (int i = 0; i < YAJL_GET_ARRAY(ifaces_list)->len; i++) { + for (size_t i = 0; i < YAJL_GET_ARRAY(ifaces_list)->len; i++) { yajl_val iface_tuple = YAJL_GET_ARRAY(ifaces_list)->values[i]; // iface_tuple is [ "uuid", "" ] @@ -1312,7 +1317,7 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) { char const *br_name = child->values[j].value.string; if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name)) == NULL) { - if ((bridge = calloc(1, sizeof(bridge_list_t))) == NULL) { + if ((bridge = calloc(1, sizeof(*bridge))) == NULL) { ERROR("%s: Error allocating memory for bridge", plugin_name); goto cleanup_fail; } else {