[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] Documentation



Hi all,

Reading libvirt documentation I have found that there is an example
that is pretty broken.

I'm referring to
http://libvirt.org/guide/html/Application_Development_Guide-Guest_Domains-Listing.html,
example 4.6.

I attach a patch (untested) that fixes some logic, type and function
signature problems. I kept small problems like 'i' missing definition
for the sake of readiness.


Best regards,
Rafael Fernández López.
--- doc.cpp	2011-08-08 13:02:18.554490946 +0200
+++ doc-intended.cpp	2011-08-08 13:01:53.074491279 +0200
@@ -1,28 +1,29 @@
 virDomainPtr *allDomains;
 int numDomains;
 int numActiveDomains, numInactiveDomains;
-char *inactiveDomains;
+char **inactiveDomains;
 int *activeDomains;
 
 numActiveDomains = virConnectNumOfDomains(conn);
 numInactiveDomains = virConnectNumOfDefinedDomains(conn);
 
-allDomains = malloc(sizeof(virDomainPtr) * numActiveDomains + numInactiveDomains);
-inactiveDomains = malloc(sizeof(char *) * numDomains);
-activeDomains = malloc(sizeof(int) * numDomains);
+allDomains = malloc(sizeof(virDomainPtr) * (numActiveDomains + numInactiveDomains));
+inactiveDomains = malloc(sizeof(char*) * numInactiveDomains);
+activeDomains = malloc(sizeof(int) * numActiveDomains);
 
+numDomains = 0;
 numActiveDomains = virConnectListDomains(conn, activeDomains, numActiveDomains);
-numInactiveDomains = virConnectListDomains(conn, inactiveDomains, numInactiveDomains);
+numInactiveDomains = virConnectListDefinedDomains(conn, inactiveDomains, numInactiveDomains);
 
 for (i = 0 ; i < numActiveDomains ; i++) {
-    allDomains[numDomains] = virDomainLookupByID(activeDomains[i]);
-    numDomains++
+    allDomains[numDomains] = virDomainLookupByID(conn, activeDomains[i]);
+    numDomains++;
 }
 
 for (i = 0 ; i < numInactiveDomains ; i++) {
-    allDomains[numDomains] = virDomainLookupByName(inactiveDomains[i]);
+    allDomains[numDomains] = virDomainLookupByName(conn, inactiveDomains[i]);
     free(inactiveDomains[i]);
-    numDomains++
+    numDomains++;
 }
 free(activeDomains);
 free(inactiveDomains);

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]