- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
so this is getting a bit funny: I tried removing the Vix_ReleaseHandel(jobHandle) in VixDiscoveryProc() but I was still getting segfaults. this seems to be happening in main, as if it tries to execute abort no matter what. if I return(-1) then all is good. below is the compelete program which works without any segfaults on 32bit. on the 64bit machine I could only get this code to run if I use VMware-vix-1.0.3 and -m32 when compiling.
below is the full listing of the code:
#include "stdio.h"
#include "string.h"
#include "vix.h"
static VixHandle hostHandle = VIX_INVALID_HANDLE;
static VixHandle jobHandle = VIX_INVALID_HANDLE;
void VixDiscoveryProc(VixHandle jobHandle,
VixEventType eventType,
VixHandle moreEventInfo,
void *clientData)
{
VixError err = VIX_OK;
VixHandle vmHandle = VIX_INVALID_HANDLE;
char *url = NULL;
// Check callback event; ignore progress reports.
if (VIX_EVENTTYPE_FIND_ITEM != eventType) {
return;
}
// Found a virtual machine.
err = Vix_GetProperties(moreEventInfo,
VIX_PROPERTY_FOUND_ITEM_LOCATION,
&url,
VIX_PROPERTY_NONE);
if (VIX_OK != err) {
// Handle the error...
goto abort;
abort:
printf("Aborting in discover\n");
Vix_ReleaseHandle(jobHandle);
VixHost_Disconnect(hostHandle);
}
printf("\nFound virtual machine: %s\n", url);
}
int main()
{
VixError err;
// Connect to specified host.
jobHandle = VixHost_Connect(VIX_API_VERSION,
VIX_SERVICEPROVIDER_VMWARE_SERVER,
"vmserver", //serverName
902, // hostPort
"root", // userName
"password", // password,
0, // options
VIX_INVALID_HANDLE, // propertyListHandle
NULL, // callbackProc
NULL); // clientData
err = VixJob_Wait(jobHandle,
VIX_PROPERTY_JOB_RESULT_HANDLE,
&hostHandle,
VIX_PROPERTY_NONE);
if (VIX_OK != err) {
// Handle the error...
printf("An error occurred\n");
goto abort;
}
printf("\nLooking for running virtual machines");
jobHandle = VixHost_FindItems(hostHandle,
VIX_FIND_RUNNING_VMS,
VIX_INVALID_HANDLE, // searchCriteria
-1, // timeout
VixDiscoveryProc,
NULL);
VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
Vix_ReleaseHandle(jobHandle);
VixHost_Disconnect(hostHandle);
return(0);
abort:
printf("Aborting in main\n");
Vix_ReleaseHandle(jobHandle);
VixHost_Disconnect(hostHandle);
return(-1);
}