[virt-tools-list] [PATCH virt-viewer] Use socat instead of nc if possible

Marc-André Lureau mlureau at redhat.com
Wed Sep 3 15:42:31 UTC 2014



----- Original Message -----
> On 09/03/2014 07:39 AM, Cole Robinson wrote:
> > I'd really recommend that virt-viewer just use the same shell code that
> > libvirt and virt-manager have used for years now, it's a crazy hack but it
> > should be battle hardened by now.
> > 
> 
> For reference, it is in
> src/rpc/virnetsocket.c:virNetSocketNewConnectSSH(), as:
> 
>     virBufferEscapeShell(&buf, netcat);
>     if (virBufferCheckError(&buf) < 0) {
>         virCommandFree(cmd);
>         return -1;
>     }
>     quoted = virBufferContentAndReset(&buf);
>     /*
>      * This ugly thing is a shell script to detect availability of
>      * the -q option for 'nc': debian and suse based distros need this
>      * flag to ensure the remote nc will exit on EOF, so it will go away
>      * when we close the connection tunnel. If it doesn't go away,
> subsequent
>      * connection attempts will hang.
>      *
>      * Fedora's 'nc' doesn't have this option, and defaults to the desired
>      * behavior.
>      */
>     virCommandAddArgFormat(cmd,
>          "'if '%s' -q 2>&1 | grep \"requires an argument\" >/dev/null
> 2>&1; then "
>              "ARG=-q0;"
>          "else "
>              "ARG=;"
>          "fi;"
>          "'%s' $ARG -U %s'",
>          quoted, quoted, path);

I think that's not the same check.

We need nc to exits from the 2 ends of the pipe whenever EOF is reached. But nc
does only leave on dest EOF when it is used with --recv-only.

Ex:
local server: nc -l localhost 9900
ssh pipe: nc localhost 9900

Ctrl-C the server, nc will not quit. Then try again with --recv-only.

socat quits on both end EOF, and solve our bug with Spice server end/disconnection.




More information about the virt-tools-list mailing list