X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fvirt.c;h=c52a8a7eb6ab950dffd00478079a1a80fd3bef79;hp=d58f68298a1173bbd49823f28b3203dd41210639;hb=063e81d76677a3b52c5d8a1fbfbdf2bf87a75cee;hpb=dde2f9e72ea606ebd0feefd96f17d834f3cea3e5 diff --git a/src/virt.c b/src/virt.c index d58f6829..c52a8a7e 100644 --- a/src/virt.c +++ b/src/virt.c @@ -468,8 +468,8 @@ const char *domain_reasons[][DOMAIN_STATE_REASON_MAX_SIZE] = { } while (0) /* Connection. */ -static virConnectPtr conn = 0; -static char *conn_string = NULL; +static virConnectPtr conn; +static char *conn_string; static c_complain_t conn_complain = C_COMPLAIN_INIT_STATIC; /* Node information required for %CPU */ @@ -479,11 +479,11 @@ static virNodeInfo nodeinfo; static int interval = 60; /* List of domains, if specified. */ -static ignorelist_t *il_domains = NULL; +static ignorelist_t *il_domains; /* List of block devices, if specified. */ -static ignorelist_t *il_block_devices = NULL; +static ignorelist_t *il_block_devices; /* List of network interface devices, if specified. */ -static ignorelist_t *il_interface_devices = NULL; +static ignorelist_t *il_interface_devices; static int ignore_device_match(ignorelist_t *, const char *domname, const char *devpath); @@ -1016,7 +1016,7 @@ static unsigned int parse_ex_stats_flags(char **exstats, int numexstats) { } static void domain_state_submit_notif(virDomainPtr dom, int state, int reason) { - if ((state < 0) || (state >= STATIC_ARRAY_SIZE(domain_states))) { + if ((state < 0) || ((size_t)state >= STATIC_ARRAY_SIZE(domain_states))) { ERROR(PLUGIN_NAME ": Array index out of bounds: state=%d", state); return; } @@ -1024,7 +1024,8 @@ static void domain_state_submit_notif(virDomainPtr dom, int state, int reason) { char msg[DATA_MAX_NAME_LEN]; const char *state_str = domain_states[state]; #ifdef HAVE_DOM_REASON - if ((reason < 0) || (reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) { + if ((reason < 0) || + ((size_t)reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) { ERROR(PLUGIN_NAME ": Array index out of bounds: reason=%d", reason); return; } @@ -1584,7 +1585,7 @@ static int get_block_stats(struct block_device *block_dev) { #define NM_ADD_STR_ITEMS(_items, _size) \ do { \ - for (int _i = 0; _i < _size; ++_i) { \ + for (size_t _i = 0; _i < _size; ++_i) { \ DEBUG(PLUGIN_NAME \ " plugin: Adding notification metadata name=%s value=%s", \ _items[_i].name, _items[_i].value); \ @@ -1609,7 +1610,7 @@ static int fs_info_notify(virDomainPtr domain, virDomainFSInfoPtr fs_info) { {.name = "name", .value = fs_info->name}, {.name = "fstype", .value = fs_info->fstype}}; - for (int i = 0; i < fs_info->ndevAlias; ++i) { + for (size_t i = 0; i < fs_info->ndevAlias; ++i) { fs_dev_alias[i].name = "devAlias"; fs_dev_alias[i].value = fs_info->devAlias[i]; } @@ -1824,7 +1825,7 @@ static int get_if_dev_stats(struct interface_device *if_dev) { return 0; } -static int domain_lifecycle_event_cb(__attribute__((unused)) virConnectPtr conn, +static int domain_lifecycle_event_cb(__attribute__((unused)) virConnectPtr con_, virDomainPtr dom, int event, int detail, __attribute__((unused)) void *opaque) { int domain_state = map_domain_event_to_state(event); @@ -1898,7 +1899,9 @@ static int virt_notif_thread_init(virt_notif_thread_t *thread_data) { * domain_event_cb_id to '-1' */ thread_data->domain_event_cb_id = -1; - thread_data->is_active = 0; + pthread_mutex_lock(&thread_data->active_mutex); + thread_data->is_active = false; + pthread_mutex_unlock(&thread_data->active_mutex); return 0; } @@ -2098,7 +2101,7 @@ static int lv_read(user_data_t *ud) { ERROR(PLUGIN_NAME " failed to get stats for block device (%s) in domain %s", state->block_devices[i].path, - virDomainGetName(state->domains[i].ptr)); + virDomainGetName(state->block_devices[i].dom)); } /* Get interface stats for each domain. */ @@ -2607,7 +2610,7 @@ static int add_interface_device(struct lv_read_state *state, virDomainPtr dom, struct interface_device *new_ptr; int new_size = sizeof(state->interface_devices[0]) * (state->nr_interface_devices + 1); - char *path_copy, *address_copy, number_string[15]; + char *path_copy, *address_copy, number_string[21]; if ((path == NULL) || (address == NULL)) return EINVAL; @@ -2646,12 +2649,12 @@ static int add_interface_device(struct lv_read_state *state, virDomainPtr dom, static int ignore_device_match(ignorelist_t *il, const char *domname, const char *devpath) { char *name; - int n, r; + int r; if ((domname == NULL) || (devpath == NULL)) return 0; - n = strlen(domname) + strlen(devpath) + 2; + size_t n = strlen(domname) + strlen(devpath) + 2; name = malloc(n); if (name == NULL) { ERROR(PLUGIN_NAME " plugin: malloc failed.");