mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
conf: Use g_strdup_printf() instead of virAsprintf()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
89b6825189
commit
daeeb3603d
@ -1841,8 +1841,7 @@ virCapabilitiesInitCaches(virCapsPtr caps)
|
||||
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);
|
||||
|
||||
|
@ -1388,10 +1388,10 @@ virDomainCCWAddressAsString(virDomainDeviceCCWAddressPtr addr)
|
||||
{
|
||||
char *addrstr = NULL;
|
||||
|
||||
ignore_value(virAsprintf(&addrstr, "%x.%x.%04x",
|
||||
addrstr = g_strdup_printf("%x.%x.%04x",
|
||||
addr->cssid,
|
||||
addr->ssid,
|
||||
addr->devno));
|
||||
addr->devno);
|
||||
return addrstr;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ virDomainAuditGetRdev(const char *path)
|
||||
(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;
|
||||
}
|
||||
@ -101,11 +101,8 @@ virDomainAuditGenericDev(virDomainObjPtr vm,
|
||||
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);
|
||||
|
||||
@ -376,22 +373,14 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
|
||||
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,
|
||||
address = g_strdup_printf(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;
|
||||
}
|
||||
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 ==
|
||||
@ -403,13 +392,10 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
|
||||
} else {
|
||||
virDomainHostdevSubsysSCSIHostPtr scsihostsrc =
|
||||
&scsisrc->u.host;
|
||||
if (virAsprintfQuiet(&address, "%s:%u:%u:%llu",
|
||||
address = g_strdup_printf("%s:%u:%u:%llu",
|
||||
scsihostsrc->adapter, scsihostsrc->bus,
|
||||
scsihostsrc->target,
|
||||
scsihostsrc->unit) < 0) {
|
||||
VIR_WARN("OOM while encoding audit message");
|
||||
goto cleanup;
|
||||
}
|
||||
scsihostsrc->unit);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -661,11 +647,8 @@ virDomainAuditCgroupMajor(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||
{
|
||||
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);
|
||||
|
||||
@ -699,13 +682,14 @@ virDomainAuditCgroupPath(virDomainObjPtr vm, virCgroupPtr cgroup,
|
||||
|
||||
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:
|
||||
@ -936,12 +920,13 @@ virDomainAuditShmem(virDomainObjPtr vm,
|
||||
|
||||
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);
|
||||
|
@ -4952,8 +4952,7 @@ virDomainPostParseCheckISCSIPath(char **srcpath)
|
||||
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;
|
||||
@ -5614,8 +5613,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def G_GNUC_UNUSED,
|
||||
*/
|
||||
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,
|
||||
@ -10158,9 +10156,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
|
||||
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);
|
||||
@ -10357,8 +10354,7 @@ virDomainParseScaledValue(const char *xpath,
|
||||
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) {
|
||||
@ -10378,11 +10374,10 @@ virDomainParseScaledValue(const char *xpath,
|
||||
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)
|
||||
@ -19409,8 +19404,7 @@ virDomainResctrlMonDefParse(virDomainDefPtr def,
|
||||
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);
|
||||
@ -19460,8 +19454,7 @@ virDomainResctrlNew(xmlNodePtr node,
|
||||
* 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)
|
||||
@ -24062,10 +24055,8 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf,
|
||||
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);
|
||||
|
||||
@ -29196,7 +29187,7 @@ char
|
||||
{
|
||||
char *ret;
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
|
||||
ret = g_strdup_printf("%s/%s.xml", dir, name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -30346,8 +30337,7 @@ virDomainDefGetShortName(const virDomainDef *def)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -30383,7 +30373,7 @@ virDomainDefGetShortName(const virDomainDef *def)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname));
|
||||
ret = g_strdup_printf("%d-%s", def->id, shortname);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -31184,10 +31174,8 @@ virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
|
||||
}
|
||||
|
||||
/* 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.
|
||||
|
@ -77,9 +77,8 @@ virDomainMomentDefPostParse(virDomainMomentDefPtr def)
|
||||
|
||||
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;
|
||||
|
@ -2753,7 +2753,7 @@ virNetworkConfigFile(const char *dir,
|
||||
{
|
||||
char *ret = NULL;
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
|
||||
ret = g_strdup_printf("%s/%s.xml", dir, name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -182,8 +182,7 @@ virNodeDeviceDeleteVport(virConnectPtr conn,
|
||||
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
|
||||
|
@ -615,10 +615,7 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDefPtr def)
|
||||
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);
|
||||
|
||||
|
@ -952,11 +952,9 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
||||
* 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) {
|
||||
|
@ -88,12 +88,10 @@ static char *virChrdevLockFilePath(const char *dev)
|
||||
++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);
|
||||
|
||||
@ -135,8 +133,7 @@ static int virChrdevLockFileCreate(const char *dev)
|
||||
|
||||
/* 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) {
|
||||
|
@ -1624,7 +1624,7 @@ virNetworkObjGetPortStatusDir(virNetworkObjPtr net,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1736,8 +1736,7 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
|
||||
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);
|
||||
@ -1897,8 +1896,7 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
|
||||
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);
|
||||
|
@ -425,7 +425,7 @@ virNetworkPortDefConfigFile(const char *dir,
|
||||
{
|
||||
char *ret = NULL;
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
|
||||
ret = g_strdup_printf("%s/%s.xml", dir, name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ virNWFilterBindingObjConfigFile(const char *dir,
|
||||
{
|
||||
char *ret;
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
|
||||
ret = g_strdup_printf("%s/%s.xml", dir, name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1229,8 +1229,7 @@ matchFCHostToSCSIHost(virStorageAdapterFCHostPtr fchost,
|
||||
*/
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user