From: Florian Forster Date: Sat, 19 Mar 2011 14:43:41 +0000 (+0100) Subject: libvirt plugin: Correctly check the status code of virDomainGetVcpus(). X-Git-Tag: collectd-4.9.5~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=15a21f242308218de9f171123ab7023dd20a1df6;p=collectd.git libvirt plugin: Correctly check the status code of virDomainGetVcpus(). The status code is less than zero on failure and the number of vCPUs otherwise. Thanks to "JLPC" for pointing this problem out. --- diff --git a/src/libvirt.c b/src/libvirt.c index bcbf0e6a..91fda7a5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -295,21 +295,31 @@ lv_read (void) for (i = 0; i < nr_domains; ++i) { virDomainInfo info; virVcpuInfoPtr vinfo = NULL; + int status; int j; - if (virDomainGetInfo (domains[i], &info) != 0) + status = virDomainGetInfo (domains[i], &info); + if (status != 0) + { + ERROR ("libvirt plugin: virDomainGetInfo failed with status %i.", + status); continue; + } cpu_submit (info.cpuTime, t, domains[i], "virt_cpu_total"); - vinfo = malloc (info.nrVirtCpu * sizeof vinfo[0]); + vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0])); if (vinfo == NULL) { ERROR ("libvirt plugin: malloc failed."); continue; } - if (virDomainGetVcpus (domains[i], vinfo, info.nrVirtCpu, - NULL, 0) != 0) { + status = virDomainGetVcpus (domains[i], vinfo, info.nrVirtCpu, + /* cpu map = */ NULL, /* cpu map length = */ 0); + if (status < 0) + { + ERROR ("libvirt plugin: virDomainGetVcpus failed with status %i.", + status); free (vinfo); continue; }