Skip to contentSkip to conversation

vnc: fix "info vnc" with "-vnc ..., reverse=on"

PATCH Applied Paolo Bonzini 3 participants 3 messages Oct 10, 2012 – Oct 16, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vnc: fix "info vnc" with "-vnc ..., reverse=on"

When reverse connection is in use, there is no active VNC server socket. Because of this, getsockopt(-1, ...) is attempted and the following error is emitted:

    $ socat TCP-LISTEN:5900,reuseaddr TCP-LISTEN:5901,reuseaddr &
    $ x86_64-softmmu/qemu-system-x86_64 -vnc localhost:5900,reverse -monitor stdio
    QEMU 1.2.50 monitor - type 'help' for more information
    (qemu) info vnc
    An undefined error has occurred

Because however the host, family, service and auth fields are optional, we can just exit if there is no active server socket.

    $ x86_64-softmmu/qemu-system-x86_64 -vnc localhost:5900,reverse -monitor stdio
    QEMU 1.2.50 monitor - type 'help' for more information
    (qemu) info vnc
    Server:
    Client:
         address: 127.0.0.1:5900
      x509_dname: none
        username: none
---
 ui/vnc.c | 4 ++++

1 file modificato, 4 inserzioni(+)

ui/vnc.c +4 -0
index b8e46ca..44d00a2 100644
@@ -372,6 +372,10 @@ VncInfo *qmp_query_vnc(Error **errp)
             }
         }
 
+        if (vnc_display->lsock == -1) {
+            return info;
+        }
+
         if (getsockname(vnc_display->lsock, (struct sockaddr *)&sa,
                         &salen) == -1) {
             error_set(errp, QERR_UNDEFINED_ERROR);
Signature · 1 line
1.7.12.1
#1 lore raw
Quoted 22 lines · Paolo Bonzini

When reverse connection is in use, there is no active VNC server socket. Because of this, getsockopt(-1, ...) is attempted and the following error is emitted:

    $ socat TCP-LISTEN:5900,reuseaddr TCP-LISTEN:5901,reuseaddr &
    $ x86_64-softmmu/qemu-system-x86_64 -vnc localhost:5900,reverse -monitor stdio
    QEMU 1.2.50 monitor - type 'help' for more information
    (qemu) info vnc
    An undefined error has occurred

Because however the host, family, service and auth fields are optional, we can just exit if there is no active server socket.

    $ x86_64-softmmu/qemu-system-x86_64 -vnc localhost:5900,reverse -monitor stdio
    QEMU 1.2.50 monitor - type 'help' for more information
    (qemu) info vnc
    Server:
    Client:
         address: 127.0.0.1:5900
      x509_dname: none
        username: none
Quoted 4 lines
---
 ui/vnc.c | 4 ++++

1 file modificato, 4 inserzioni(+)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan

#2 lore raw
In reply to Paolo Bonzini

On 10.10.2012 16:30, Paolo Bonzini wrote:
[]

ui/vnc.c VncInfo *qmp_query_vnc(Error **errp) · line 375

Quoted 7 lines
ui/vnc.c +1 -0
@@ -372,6 +372,10 @@ VncInfo *qmp_query_vnc(Error **errp)
             }
         }
 
+        if (vnc_display->lsock == -1) {

FWIW, can't we use "< 0" condition in all cases like this - for testing whenever a filedescriptor is not open or if a system call returned failure? Why we compare with -1 only? The "< 0" comparison is cheaper in the resulting code (very very small difference), but more to the point, it guarantees that no invalid value is treated as valid - for example, in case some function returns -errno like it was with bdrv_something() recently. I use "< 0" in such places for over 20 years for this reason, this "technique" saved me countless number of times, when old API changed, or when I switched to a new API without reviewing return value checking in all places, or when I just didn't read the manpage carefully... ;)

Thanks,

/mjt