From 15a21f242308218de9f171123ab7023dd20a1df6 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 19 Mar 2011 15:43:41 +0100 Subject: [PATCH] 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. --- src/libvirt.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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; } -- 2.30.2