diff options
author | Haoqian He <haoqian.he@smartx.com> | 2025-02-25 18:45:26 +0800 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2025-03-05 09:38:09 +0400 |
commit | 46f83c898a6658921fed57f98af6d505ab78a6e4 (patch) | |
tree | 44f385ae2cb9b000a3c0ce1d8fcacd9825fa23fc | |
parent | a97ef3624437c5a5fbc8bd45e2a206d10ca840be (diff) | |
download | qemu-46f83c898a6658921fed57f98af6d505ab78a6e4.zip qemu-46f83c898a6658921fed57f98af6d505ab78a6e4.tar.gz qemu-46f83c898a6658921fed57f98af6d505ab78a6e4.tar.bz2 |
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>
-rw-r--r-- | chardev/char-socket.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 91496ce..2f842f9 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 = "]"; |