int rv = -1;
VIR_FREE(path);
- if (virAsprintf(&path, "%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos) < 0)
- goto cleanup;
+ path = g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos);
VIR_DIR_CLOSE(dirp);
{
char *addrstr = NULL;
- ignore_value(virAsprintf(&addrstr, "%x.%x.%04x",
- addr->cssid,
- addr->ssid,
- addr->devno));
+ addrstr = g_strdup_printf("%x.%x.%04x",
+ addr->cssid,
+ addr->ssid,
+ addr->devno);
return addrstr;
}
(S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) {
int maj = major(sb.st_rdev);
int min = minor(sb.st_rdev);
- ignore_value(virAsprintfQuiet(&ret, "%02X:%02X", maj, min));
+ ret = g_strdup_printf("%02X:%02X", maj, min);
}
return ret;
}
if (!newsrcpath && !oldsrcpath)
return;
- if (virAsprintfQuiet(&newdev, "new-%s", type) < 0)
- goto no_memory;
-
- if (virAsprintfQuiet(&olddev, "old-%s", type) < 0)
- goto no_memory;
+ newdev = g_strdup_printf("new-%s", type);
+ olddev = g_strdup_printf("old-%s", type);
virUUIDFormat(vm->def->uuid, uuidstr);
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
- if (virAsprintfQuiet(&address,
- VIR_PCI_DEVICE_ADDRESS_FMT,
- pcisrc->addr.domain,
- pcisrc->addr.bus,
- pcisrc->addr.slot,
- pcisrc->addr.function) < 0) {
- VIR_WARN("OOM while encoding audit message");
- goto cleanup;
- }
+ address = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT,
+ pcisrc->addr.domain,
+ pcisrc->addr.bus,
+ pcisrc->addr.slot,
+ pcisrc->addr.function);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
- if (virAsprintfQuiet(&address, "%.3d.%.3d",
- usbsrc->bus, usbsrc->device) < 0) {
- VIR_WARN("OOM while encoding audit message");
- goto cleanup;
- }
+ address = g_strdup_printf("%.3d.%.3d", usbsrc->bus, usbsrc->device);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
if (scsisrc->protocol ==
} else {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc =
&scsisrc->u.host;
- if (virAsprintfQuiet(&address, "%s:%u:%u:%llu",
- scsihostsrc->adapter, scsihostsrc->bus,
- scsihostsrc->target,
- scsihostsrc->unit) < 0) {
- VIR_WARN("OOM while encoding audit message");
- goto cleanup;
- }
+ address = g_strdup_printf("%s:%u:%u:%llu",
+ scsihostsrc->adapter, scsihostsrc->bus,
+ scsihostsrc->target,
+ scsihostsrc->unit);
}
break;
}
{
char *extra;
- if (virAsprintfQuiet(&extra, "major category=%s maj=%02X acl=%s",
- name, maj, perms) < 0) {
- VIR_WARN("OOM while encoding audit message");
- return;
- }
+ extra = g_strdup_printf("major category=%s maj=%02X acl=%s",
+ name, maj, perms);
virDomainAuditCgroup(vm, cgroup, reason, extra, success);
rdev = virDomainAuditGetRdev(path);
- if (!(detail = virAuditEncode("path", path)) ||
- virAsprintfQuiet(&extra, "path %s rdev=%s acl=%s",
- detail, VIR_AUDIT_STR(rdev), perms) < 0) {
+ if (!(detail = virAuditEncode("path", path))) {
VIR_WARN("OOM while encoding audit message");
goto cleanup;
}
+ extra = g_strdup_printf("path %s rdev=%s acl=%s",
+ detail, VIR_AUDIT_STR(rdev), perms);
+
virDomainAuditCgroup(vm, cgroup, reason, extra, rc == 0);
cleanup:
virUUIDFormat(vm->def->uuid, uuidstr);
- if (!vmname ||
- virAsprintfQuiet(&shmpath, "/dev/shm/%s", def->name) < 0) {
+ if (!vmname) {
VIR_WARN("OOM while encoding audit message");
goto cleanup;
}
+ shmpath = g_strdup_printf("/dev/shm/%s", def->name);
+
if (!virt) {
VIR_WARN("Unexpected virt type %d while encoding audit message",
vm->def->virtType);
if (strchr(*srcpath, '/'))
return 0;
- if (virAsprintf(&path, "%s/0", *srcpath) < 0)
- return -1;
+ path = g_strdup_printf("%s/0", *srcpath);
VIR_FREE(*srcpath);
*srcpath = g_steal_pointer(&path);
return 0;
*/
return 0;
}
- if (virAsprintf(&order, "%u", info->bootIndex) < 0)
- return -1;
+ order = g_strdup_printf("%u", info->bootIndex);
if (virHashLookup(bootHash, order)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
if (!target && !(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) {
if (def->src->srcpool) {
- if (virAsprintf(&tmp, "pool = '%s', volume = '%s'",
- def->src->srcpool->pool, def->src->srcpool->volume) < 0)
- goto error;
+ tmp = g_strdup_printf("pool = '%s', volume = '%s'",
+ def->src->srcpool->pool, def->src->srcpool->volume);
virReportError(VIR_ERR_NO_TARGET, "%s", tmp);
VIR_FREE(tmp);
g_autofree char *bytes_str = NULL;
*val = 0;
- if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0)
- return -1;
+ xpath_full = g_strdup_printf("string(%s)", xpath);
bytes_str = virXPathString(xpath_full, ctxt);
if (!bytes_str) {
return -1;
}
- if ((units_xpath &&
- virAsprintf(&xpath_full, "string(%s)", units_xpath) < 0) ||
- (!units_xpath &&
- virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0))
- return -1;
+ if (units_xpath)
+ xpath_full = g_strdup_printf("string(%s)", units_xpath);
+ else
+ xpath_full = g_strdup_printf("string(%s/@unit)", xpath);
unit = virXPathString(xpath_full, ctxt);
if (virScaleInteger(&bytes, unit, scale, max) < 0)
if (!(tmp = virBitmapFormat(domresmon->vcpus)))
goto cleanup;
- if (virAsprintf(&id, "vcpus_%s", tmp) < 0)
- goto cleanup;
+ id = g_strdup_printf("vcpus_%s", tmp);
}
virResctrlMonitorSetAlloc(domresmon->instance, resctrl->alloc);
* directory, so it's nice to have it named appropriately. For now it's
* 'vcpus_...' but it's designed in order for it to be changeable in the
* future (it's part of the status XML). */
- if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0)
- goto cleanup;
+ alloc_id = g_strdup_printf("vcpus_%s", vcpus_str);
}
if (virResctrlAllocSetID(alloc, alloc_id) < 0)
virBufferAsprintf(attrBuf, " protocol='%s'",
virStorageNetProtocolTypeToString(src->protocol));
- if (src->volume) {
- if (virAsprintf(&path, "%s/%s", src->volume, src->path) < 0)
- return -1;
- }
+ if (src->volume)
+ path = g_strdup_printf("%s/%s", src->volume, src->path);
virBufferEscapeString(attrBuf, " name='%s'", path ? path : src->path);
{
char *ret;
- ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+ ret = g_strdup_printf("%s/%s.xml", dir, name);
return ret;
}
len = mbstowcs(NULL, def->name, 0);
if ((len == (size_t) -1 && errno == EILSEQ) ||
len == strlen(def->name)) {
- ignore_value(virAsprintf(&ret, "%d-%.*s", def->id,
- VIR_DOMAIN_SHORT_NAME_MAX, def->name));
+ ret = g_strdup_printf("%d-%.*s", def->id, VIR_DOMAIN_SHORT_NAME_MAX, def->name);
return ret;
}
return NULL;
}
- ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname));
+ ret = g_strdup_printf("%d-%s", def->id, shortname);
return ret;
}
}
/* iscsi pool has only one source device path */
- if (virAsprintf(&def->src->path, "%s/%s",
- pooldef->source.devices[0].path,
- tokens[3]) < 0)
- goto cleanup;
+ def->src->path = g_strdup_printf("%s/%s", pooldef->source.devices[0].path,
+ tokens[3]);
/* Storage pool have not supported these 2 attributes yet,
* use the defaults.
gettimeofday(&tv, NULL);
- if (!def->name &&
- virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0)
- return -1;
+ if (!def->name)
+ def->name = g_strdup_printf("%lld", (long long)tv.tv_sec);
def->creationTime = tv.tv_sec;
return 0;
{
char *ret = NULL;
- ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+ ret = g_strdup_printf("%s/%s.xml", dir, name);
return ret;
}
goto cleanup;
}
- if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
- goto cleanup;
+ scsi_host_name = g_strdup_printf("scsi_%s", name);
/* If at startup time we provided a parent, then use that to
* get the parent_host value; otherwise, we have to determine
if ((tmp = strrchr(tmppath, '.')) && !strchr(tmp, '/'))
*tmp = '\0';
- if (virAsprintf(&disk->src->path, "%s.%s", tmppath, def->parent.name) < 0) {
- VIR_FREE(tmppath);
- return -1;
- }
+ disk->src->path = g_strdup_printf("%s.%s", tmppath, def->parent.name);
VIR_FREE(tmppath);
* path and permissions */
if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
if (def->type == VIR_STORAGE_POOL_LOGICAL) {
- if (virAsprintf(&target_path, "/dev/%s", def->source.name) < 0)
- return NULL;
+ target_path = g_strdup_printf("/dev/%s", def->source.name);
} else if (def->type == VIR_STORAGE_POOL_ZFS) {
- if (virAsprintf(&target_path, "/dev/zvol/%s", def->source.name) < 0)
- return NULL;
+ target_path = g_strdup_printf("/dev/zvol/%s", def->source.name);
} else {
target_path = virXPathString("string(./target/path)", ctxt);
if (!target_path) {
++p;
}
- if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0)
- goto cleanup;
+ path = g_strdup_printf("%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename);
sanitizedPath = virFileSanitizePath(path);
- cleanup:
VIR_FREE(path);
VIR_FREE(devCopy);
/* ensure correct format according to filesystem hierarchy standard */
/* http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLOCKLOCKFILES */
- if (virAsprintf(&pidStr, "%10lld\n", (long long) getpid()) < 0)
- goto cleanup;
+ pidStr = g_strdup_printf("%10lld\n", (long long)getpid());
/* create the lock file */
if ((lockfd = open(path, O_WRONLY | O_CREAT | O_EXCL, 00644)) < 0) {
const char *stateDir)
{
char *ret;
- ignore_value(virAsprintf(&ret, "%s/%s/ports", stateDir, net->def->name));
+ ret = g_strdup_printf("%s/%s/ports", stateDir, net->def->name);
return ret;
}
if (!virStringStripSuffix(de->d_name, ".xml"))
continue;
- if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0)
- goto cleanup;
+ file = g_strdup_printf("%s/%s.xml", dir, de->d_name);
if (unlink(file) < 0 && errno != ENOENT)
VIR_WARN("Unable to delete %s", file);
if (!virStringStripSuffix(de->d_name, ".xml"))
continue;
- if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0)
- goto cleanup;
+ file = g_strdup_printf("%s/%s.xml", dir, de->d_name);
portdef = virNetworkPortDefParseFile(file);
VIR_FREE(file);
{
char *ret = NULL;
- ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+ ret = g_strdup_printf("%s/%s.xml", dir, name);
return ret;
}
{
char *ret;
- ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+ ret = g_strdup_printf("%s/%s.xml", dir, name);
return ret;
}
*/
if (!fchost->parent &&
(conn = virGetConnectNodeDev())) {
- if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
- goto cleanup;
+ scsi_host_name = g_strdup_printf("scsi_%s", name);
if ((parent_name = virNodeDeviceGetParentName(conn,
scsi_host_name))) {
if (virStorageIsSameHostnum(parent_name, scsi_hostnum)) {