Skip to content

Commit 46f83c8

Browse files
Haoqian-Heelmarco
authored andcommitted
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 <[email protected]> Acked-by: Marc-André Lureau <[email protected]> Message-ID: <[email protected]>
1 parent a97ef36 commit 46f83c8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

chardev/char-socket.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,13 @@ static char *qemu_chr_compute_filename(SocketChardev *s)
571571

572572
switch (ss->ss_family) {
573573
case AF_UNIX:
574-
return g_strdup_printf("unix:%s%s",
575-
((struct sockaddr_un *)(ss))->sun_path,
576-
s->is_listen ? ",server=on" : "");
574+
if (s->is_listen) {
575+
return g_strdup_printf("unix:%s,server=on",
576+
((struct sockaddr_un *)(ss))->sun_path);
577+
} else {
578+
return g_strdup_printf("unix:%s",
579+
((struct sockaddr_un *)(ps))->sun_path);
580+
}
577581
case AF_INET6:
578582
left = "[";
579583
right = "]";

0 commit comments

Comments
 (0)