qemuBuildChannelGuestfwdNetdevProps: Don't use virJSONValueObjectAppendStringPrintf

Use virJSONValueObjectAdd and format the string directly via
g_strdup_printf. In the end virJSONValueObjectAppendStringPrintf will be
removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-03-06 09:46:40 +01:00
parent cac6d59e80
commit 609353275b

View File

@ -10515,22 +10515,24 @@ qemuBuildParallelChrDeviceProps(virDomainChrDef *chr)
virJSONValue *
qemuBuildChannelGuestfwdNetdevProps(virDomainChrDef *chr)
{
g_autofree char *guestfwdstr = NULL;
g_autoptr(virJSONValue) guestfwdstrobj = NULL;
g_autoptr(virJSONValue) guestfwdarr = virJSONValueNewArray();
g_autoptr(virJSONValue) guestfwdstrobj = virJSONValueNewObject();
g_autofree char *addr = NULL;
virJSONValue *ret = NULL;
if (!(addr = virSocketAddrFormat(chr->target.addr)))
return NULL;
guestfwdstr = g_strdup_printf("tcp:%s:%i-chardev:char%s",
addr,
virSocketAddrGetPort(chr->target.addr),
chr->info.alias);
/* this may seem weird, but qemu indeed decided that 'guestfwd' parameter
* is an array of objects which have just one member named 'str' which
* contains the description */
if (virJSONValueObjectAppendStringPrintf(guestfwdstrobj, "str",
"tcp:%s:%i-chardev:char%s",
addr,
virSocketAddrGetPort(chr->target.addr),
chr->info.alias) < 0)
if (virJSONValueObjectAdd(&guestfwdstrobj, "s:str", guestfwdstr, NULL) < 0)
return NULL;
if (virJSONValueArrayAppend(guestfwdarr, &guestfwdstrobj) < 0)