summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8acc85b)
raw | patch | inline | side by side (parent: 8acc85b)
author | Denis Silakov <dsilakov@gmail.com> | |
Tue, 22 Nov 2016 15:17:16 +0000 (18:17 +0300) | ||
committer | Denis Silakov <dsilakov@gmail.com> | |
Tue, 22 Nov 2016 15:17:16 +0000 (18:17 +0300) |
src/virt.c | patch | blob | history |
diff --git a/src/virt.c b/src/virt.c
index 62b53dcca36606a10caefe4c0db6e2ba0ef14aec..6f9178014cf9570e0e15f021d643289fd1b91484 100644 (file)
--- a/src/virt.c
+++ b/src/virt.c
}
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;
}
/* 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");
sfree (xml);
}
- sfree (domids);
+ sfree (domains);
}
return 0;