{
unsigned long version = 0;
int ret = -1;
- virCommandPtr cmd;
+ virCommandPtr cmd = NULL;
char * outbuf = NULL;
- const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ?
- "vmplayer" : "vmware";
+ char *bin = NULL;
+ char *vmwarePath = NULL;
+
+ if ((vmwarePath = mdir_name(driver->vmrun)) == NULL)
+ goto cleanup;
+
+ switch (driver->type) {
+ case VMWARE_DRIVER_PLAYER:
+ if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmplayer"))
+ goto cleanup;
+ break;
+
+ case VMWARE_DRIVER_WORKSTATION:
+ if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware"))
+ goto cleanup;
+ break;
+
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("invalid driver type for version detection"));
+ goto cleanup;
+ }
cmd = virCommandNewArgList(bin, "-v", NULL);
virCommandSetOutputBuffer(cmd, &outbuf);
cleanup:
virCommandFree(cmd);
VIR_FREE(outbuf);
+ VIR_FREE(bin);
+ VIR_FREE(vmwarePath);
return ret;
}
{
struct vmware_driver *driver;
size_t i;
+ char *tmp;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (virMutexInit(&driver->lock) < 0)
goto cleanup;
- driver->type = STRNEQ(conn->uri->scheme, "vmwareplayer") ?
- VMWARE_DRIVER_WORKSTATION : VMWARE_DRIVER_PLAYER;
+ if ((tmp = STRSKIP(conn->uri->scheme, "vmware")) == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse URI "
+ "scheme '%s'"), conn->uri->scheme);
+ goto cleanup;
+ }
+
+ driver->type = -1;
+ for (i = 0; i < VMWARE_DRIVER_LAST; i++) {
+ if (STREQ(tmp, vmwareDriverTypeToString(i))) {
+ driver->type = i;
+ break;
+ }
+ }
+
+ if (driver->type == -1) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find valid "
+ "requested VMware backend '%s'"), tmp);
+ goto cleanup;
+ }
if (!(driver->domains = virDomainObjListNew()))
goto cleanup;