summary refs log tree commit diff stats
path: root/chardev/char-socket.c
diff options
context:
space:
mode:
authorHaoqian He <haoqian.he@smartx.com>2025-02-25 18:45:26 +0800
committerMarc-André Lureau <marcandre.lureau@redhat.com>2025-03-05 09:38:09 +0400
commit46f83c898a6658921fed57f98af6d505ab78a6e4 (patch)
tree44f385ae2cb9b000a3c0ce1d8fcacd9825fa23fc /chardev/char-socket.c
parenta97ef3624437c5a5fbc8bd45e2a206d10ca840be (diff)
downloadfocaccia-qemu-46f83c898a6658921fed57f98af6d505ab78a6e4.tar.gz
focaccia-qemu-46f83c898a6658921fed57f98af6d505ab78a6e4.zip
chardev: use remoteAddr if the chardev is client
If the chardev is client, the socket file path in localAddr may be NULL.
This is because the socket path comes from getsockname(), according
to man page, getsockname() returns the current address bound by the
socket sockfd. If the chardev is client, it's socket is unbound sockfd.

Therefore, when computing the client chardev socket file path, using
remoteAddr is more appropriate.

Signed-off-by: Haoqian He <haoqian.he@smartx.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20250225104526.2924175-1-haoqian.he@smartx.com>
Diffstat (limited to 'chardev/char-socket.c')
-rw-r--r--chardev/char-socket.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 91496ceda9..2f842f9f88 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -571,9 +571,13 @@ static char *qemu_chr_compute_filename(SocketChardev *s)
 
     switch (ss->ss_family) {
     case AF_UNIX:
-        return g_strdup_printf("unix:%s%s",
-                               ((struct sockaddr_un *)(ss))->sun_path,
-                               s->is_listen ? ",server=on" : "");
+        if (s->is_listen) {
+            return g_strdup_printf("unix:%s,server=on",
+                                   ((struct sockaddr_un *)(ss))->sun_path);
+        } else {
+            return g_strdup_printf("unix:%s",
+                                   ((struct sockaddr_un *)(ps))->sun_path);
+        }
     case AF_INET6:
         left  = "[";
         right = "]";