[PATCH] chardev: use remoteAddr if the chardev is client

Haoqian He posted 1 patch 11 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250225104526.2924175-1-haoqian.he@smartx.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
chardev/char-socket.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
[PATCH] chardev: use remoteAddr if the chardev is client
Posted by Haoqian He 11 months, 2 weeks ago
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>
---
 chardev/char-socket.c | 10 +++++++---
 1 file 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 = "]";
-- 
2.48.1
Re: [PATCH] chardev: use remoteAddr if the chardev is client
Posted by Marc-André Lureau 11 months, 2 weeks ago
Hi

On Tue, Feb 25, 2025 at 2:47 PM Haoqian He <haoqian.he@smartx.com> wrote:
>
> 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>
> ---
>  chardev/char-socket.c | 10 +++++++---
>  1 file 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 = "]";
> --
> 2.48.1
>
>

This patch doesn't change anything, and I don't understand the problem
you are trying to fix.

Can you provide more details or a test scenario?

thanks

-- 
Marc-André Lureau