X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fovs_stats.c;h=538386ae689fce2a15b2eb30948c20408015f20c;hb=bcf9c488e832b4cba43b1c1e35d58f463feb967f;hp=31af77c841d9543d8b7f34fa4e86a2baf0f17802;hpb=6026e3162e522b133d10596710527d24c2921b55;p=collectd.git diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 31af77c8..538386ae 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -3,14 +3,17 @@ * * Copyright(c) 2016 Intel Corporation. All rights reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a copy of + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do + * of the Software, and to permit persons to whom the Software is furnished to + * do * so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all + * The above copyright notice and this permission notice shall be included in + * all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR @@ -711,33 +714,30 @@ static void ovs_stats_initialize(ovs_db_t *pdb) { "external_ids", NULL}; /* subscribe to a tables */ - ovs_db_table_cb_register(pdb, "Bridge", bridge_columns, - ovs_stats_bridge_table_change_cb, + ovs_db_table_cb_register( + pdb, "Bridge", bridge_columns, ovs_stats_bridge_table_change_cb, ovs_stats_bridge_table_result_cb, - OVS_DB_TABLE_CB_FLAG_INITIAL | - OVS_DB_TABLE_CB_FLAG_INSERT | + OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT | OVS_DB_TABLE_CB_FLAG_MODIFY); ovs_db_table_cb_register(pdb, "Bridge", bridge_columns, ovs_stats_bridge_table_delete_cb, NULL, OVS_DB_TABLE_CB_FLAG_DELETE); - ovs_db_table_cb_register(pdb, "Port", port_columns, - ovs_stats_port_table_change_cb, + ovs_db_table_cb_register( + pdb, "Port", port_columns, ovs_stats_port_table_change_cb, ovs_stats_port_table_result_cb, - OVS_DB_TABLE_CB_FLAG_INITIAL | - OVS_DB_TABLE_CB_FLAG_INSERT | + OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT | OVS_DB_TABLE_CB_FLAG_MODIFY); ovs_db_table_cb_register(pdb, "Port", port_columns, ovs_stats_port_table_delete_cb, NULL, OVS_DB_TABLE_CB_FLAG_DELETE); - ovs_db_table_cb_register(pdb, "Interface", interface_columns, - ovs_stats_interface_table_change_cb, + ovs_db_table_cb_register( + pdb, "Interface", interface_columns, ovs_stats_interface_table_change_cb, ovs_stats_interface_table_result_cb, - OVS_DB_TABLE_CB_FLAG_INITIAL | - OVS_DB_TABLE_CB_FLAG_INSERT | + OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT | OVS_DB_TABLE_CB_FLAG_MODIFY); } @@ -789,7 +789,6 @@ static void ovs_stats_conn_terminate() { */ static int ovs_stats_plugin_config(oconfig_item_t *ci) { bridge_list_t *bridge; - char *br_name; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -821,19 +820,22 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) { goto cleanup_fail; } /* get value */ - if ((br_name = strdup(child->values[j].value.string)) == NULL) { - ERROR("%s: strdup() copy bridge name fail", plugin_name); - goto cleanup_fail; - } + 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) { ERROR("%s: Error allocating memory for bridge", plugin_name); goto cleanup_fail; } else { + char *br_name_dup = strdup(br_name); + if (br_name_dup == NULL) { + ERROR("%s: strdup() copy bridge name fail", plugin_name); + goto cleanup_fail; + } + pthread_mutex_lock(&g_stats_lock); /* store bridge name */ - bridge->name = br_name; + bridge->name = br_name_dup; bridge->next = g_monitored_bridge_list_head; g_monitored_bridge_list_head = bridge; pthread_mutex_unlock(&g_stats_lock); @@ -862,8 +864,8 @@ static int ovs_stats_plugin_init(void) { plugin_name, ovs_stats_cfg.ovs_db_node, ovs_stats_cfg.ovs_db_serv, ovs_stats_cfg.ovs_db_unix); /* connect to OvS DB */ - if ((g_ovs_db = ovs_db_init (ovs_stats_cfg.ovs_db_node, - ovs_stats_cfg.ovs_db_serv, + if ((g_ovs_db = + ovs_db_init(ovs_stats_cfg.ovs_db_node, ovs_stats_cfg.ovs_db_serv, ovs_stats_cfg.ovs_db_unix, &cb)) == NULL) { ERROR("%s: plugin: failed to connect to OvS DB server", plugin_name); return -1;