X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvirt.c;h=6f9178014cf9570e0e15f021d643289fd1b91484;hb=de52e0346ca1255ed77e67d33bbbd6b3c8a28b9f;hp=62b53dcca36606a10caefe4c0db6e2ba0ef14aec;hpb=8acc85b19e44c9bc106484b95cd352d867abdf1c;p=collectd.git diff --git a/src/virt.c b/src/virt.c index 62b53dcc..6f917801 100644 --- a/src/virt.c +++ b/src/virt.c @@ -683,19 +683,11 @@ refresh_lists (void) } if (n > 0) { - int *domids; + virDomainPtr *domains; - /* Get list of domains. */ - domids = malloc (sizeof (*domids) * n); - if (domids == NULL) { - ERROR (PLUGIN_NAME " plugin: malloc failed."); - return -1; - } - - n = virConnectListDomains (conn, domids, n); + n = virConnectListAllDomains (conn, &domains, VIR_CONNECT_LIST_DOMAINS_ACTIVE); if (n < 0) { VIRT_ERROR (conn, "reading list of domains"); - sfree (domids); return -1; } @@ -705,20 +697,13 @@ refresh_lists (void) /* Fetch each domain and add it to the list, unless ignore. */ for (int i = 0; i < n; ++i) { - virDomainPtr dom = NULL; + virDomainPtr dom = domains[i]; const char *name; char *xml = NULL; xmlDocPtr xml_doc = NULL; xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr xpath_obj = NULL; - dom = virDomainLookupByID (conn, domids[i]); - if (dom == NULL) { - VIRT_ERROR (conn, "virDomainLookupByID"); - /* Could be that the domain went away -- ignore it anyway. */ - continue; - } - name = virDomainGetName (dom); if (name == NULL) { VIRT_ERROR (conn, "virDomainGetName"); @@ -826,7 +811,7 @@ refresh_lists (void) sfree (xml); } - sfree (domids); + sfree (domains); } return 0;