]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildChannelGuestfwdNetdevProps: Don't use virJSONValueObjectAppendStringPrintf
authorPeter Krempa <pkrempa@redhat.com>
Mon, 6 Mar 2023 08:46:40 +0000 (09:46 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 Mar 2023 12:36:18 +0000 (13:36 +0100)
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>
src/qemu/qemu_command.c

index 3dcee6c4e484a023284ba0762d3c8b63075ce478..570b57341bad814ca25213f8ad56b4f8567e26d6 100644 (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)