[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-Li..., 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.

On 08/08/2011 05:30 AM, Rafael Fernández López wrote:
Hi all,
Reading libvirt documentation I have found that there is an example that is pretty broken.
Thanks for the report.
I'm referring to http://libvirt.org/guide/html/Application_Development_Guide-Guest_Domains-Li..., example 4.6.
The source for this example is maintained in a git repository: git://libvirt.org/libvirt-appdev-guide.git en-US/Guest_Domains.xml
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.
I've gone ahead and applied your patch, but also adding the missing definition for 'i'. diff --git i/en-US/Guest_Domains.xml w/en-US/Guest_Domains.xml index af29864..0324e78 100644 --- i/en-US/Guest_Domains.xml +++ w/en-US/Guest_Domains.xml @@ -220,35 +220,36 @@ free(inactiveDomains); <title>Fetching all domain objects</title> <programlisting> virDomainPtr *allDomains; -int numDomains; +int numDomains = 0; int numActiveDomains, numInactiveDomains; -char *inactiveDomains; +char **inactiveDomains; int *activeDomains; +int i; numActiveDomains = virConnectNumOfDomains(conn); numInactiveDomains = virConnectNumOfDefinedDomains(conn); allDomains = malloc(sizeof(virDomainPtr) * -numActiveDomains + numInactiveDomains); -inactiveDomains = malloc(sizeof(char *) * numDomains); -activeDomains = malloc(sizeof(int) * numDomains); + (numActiveDomains + numInactiveDomains)); +inactiveDomains = malloc(sizeof(char *) * numInactiveDomains); +activeDomains = malloc(sizeof(int) * numActiveDomains); numActiveDomains = virConnectListDomains(conn, -activeDomains, -numActiveDomains); + activeDomains, + numActiveDomains); numInactiveDomains = virConnectListDefinedDomains(conn, -inactiveDomains, -numInactiveDomains); + 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); -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Rafael Fernández López