I'm trying to use the VIX API to get a list of all the VMs registered to a host. The simplest way to do this seemed to be to use Vix_FindItems, and pass it a callback that would build a string of all the VM file names (adding to the end of a string each time the callback was invoked). However, on the third iteration through the callback, execution halts, prints the following error message, and exits:
Panic: ASSERT d:/build/ob/bora-222403/bora/lib/sync/syncWaitQWin32.c:336
The callback method I wrote, with debug printf()s, is as follows:
void VixCollectVMS(VixHandle jobHandle,
VixEventType eventType,
VixHandle moreEventInfo,
void *clientData)
{
int i = 0;
VixError err = VIX_OK;
char *url;
printf("\nProcessing event...%d\n", eventType);
//Only actually process item found events (8).
if(VIX_EVENTTYPE_FIND_ITEM != eventType) {
return;
}
printf("Checkpoint %d\n", ++i);
//Get the location on disk
err = Vix_GetProperties(moreEventInfo,
VIX_PROPERTY_FOUND_ITEM_LOCATION,
&url,
VIX_PROPERTY_NONE);
//This checkpoint never gets reached on the Panicked invocation of the callback
printf("Checkpoint %d\n", ++i);
//Assuming it's successful, append it, otherwise print the error
if(VIX_OK == err){
strcat((char*) clientData, url);
strcat((char*) clientData, "\n");
} else {
printf("Error encountered: %s",
Vix_GetErrorText(err, NULL));
}
//Clean up
Vix_FreeBuffer(url);
}
I passed in a char* that was calloc()ed to hold 10000 characters as clientData, expecting it to be passed from one callback to another, so that I could just keep adding to it there. I also assumed that the string of VM file names would then be available to the calling function after the callbacks were finished running, signaled by putting a VixJob_Wait in the calling function. As it is, the execution unfailingly halts during the third invocation of the callback.
So, two questions: first, why is this happening and what does the error mean? The error seems to be linked to me trying to use clientData to pass information into, between, and out of the callback function.
Second, is there a better way to get a list of all the VMs registered with a host?
(Note: this is being compiled on Windows, but aside from changing the location of VIX.h in the header, should be easy to compile on Linux.)