int vmwareExtractVersion(struct vmware_driver *driver) { int ret = -1; virCommandPtr cmd = NULL; char * outbuf = NULL; 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") < 0) goto cleanup; break; case VMWARE_DRIVER_WORKSTATION: if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware") < 0) goto cleanup; break; case VMWARE_DRIVER_FUSION: if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware-vmx") < 0) 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); virCommandSetErrorBuffer(cmd, &outbuf); if (virCommandRun(cmd, NULL) < 0) goto cleanup; if (vmwareParseVersionStr(driver->type, outbuf, &driver->version) < 0) goto cleanup; ret = 0; cleanup: virCommandFree(cmd); VIR_FREE(outbuf); VIR_FREE(bin); VIR_FREE(vmwarePath); return ret; }
static int testVerStrParse(const void *data) { const struct testInfo *info = data; int ret = -1; char *path = NULL; char *databuf = NULL; unsigned long version; int vmware_type; if (virAsprintf(&path, "%s/vmwareverdata/%s.txt", abs_srcdir, info->name) < 0) return -1; if (virTestLoadFile(path, &databuf) < 0) goto cleanup; if ((vmware_type = vmwareDriverTypeFromString(info->vmware_type)) < 0) goto cleanup; if (vmwareParseVersionStr(vmware_type, databuf, &version) < 0) goto cleanup; if (version != info->version) { fprintf(stderr, "%s: parsed versions do not match: got %lu, " "expected %lu\n", info->name, version, info->version); goto cleanup; } ret = 0; cleanup: VIR_FREE(path); VIR_FREE(databuf); return ret; }