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

Fabiano Fidêncio fabiano at fidencio.org
Fri Oct 10 13:49:21 UTC 2014


On Fri, Oct 10, 2014 at 3:44 PM, Fabiano Fidêncio <fabiano at fidencio.org> wrote:
> On Mon, Sep 8, 2014 at 11:14 PM, Marc-André Lureau
> <marcandre.lureau at gmail.com> wrote:
>>
>> It turns out that nc does not leave on server disconnect, and there
>> doesn't seem to be any option to do that, leaving client open, and
>> a bunch of idle processes.
>>
>> Replacing nc with socat solves that, client is disconnected when
>> the VM is shut down, when the sever connection is closed.
>>
>> https://bugzilla.redhat.com/show_bug.cgi?id=1030487
>> ---
>>  src/virt-viewer-app.c | 32 +++++++++++++++++++++++---------
>>  1 file changed, 23 insertions(+), 9 deletions(-)
>>
>> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
>> index b60ce2d..ded7e60 100644
>> --- a/src/virt-viewer-app.c
>> +++ b/src/virt-viewer-app.c
>> @@ -627,6 +627,7 @@ virt_viewer_app_open_tunnel_ssh(const char *sshhost,
>>      const char *cmd[10];
>>      char portstr[50];
>>      int n = 0;
>> +    GString *cat;
>>
>>      cmd[n++] = "ssh";
>>      if (sshport) {
>> @@ -639,17 +640,30 @@ virt_viewer_app_open_tunnel_ssh(const char *sshhost,
>>          cmd[n++] = sshuser;
>>      }
>>      cmd[n++] = sshhost;
>> -    cmd[n++] = "nc";
>> -    if (port) {
>> -        cmd[n++] = host;
>> -        cmd[n++] = port;
>> -    } else {
>> -        cmd[n++] = "-U";
>> -        cmd[n++] = unixsock;
>> -    }
>> +
>> +    cat = g_string_new("if (command -v socat) >/dev/null 2>&1");
>> +
>> +    g_string_append(cat, "; then socat - ");
>> +    if (port)
>> +        g_string_append_printf(cat, "TCP:%s:%s", host, port);
>> +    else
>> +        g_string_append_printf(cat, "UNIX-CONNECT:%s", unixsock);
>> +
>> +    g_string_append(cat, "; else nc ");
>> +    if (port)
>> +        g_string_append_printf(cat, "%s %s", host, port);
>> +    else
>> +        g_string_append_printf(cat, "-U %s", unixsock);
>> +
>> +    g_string_append(cat, "; fi");
>> +
>> +    cmd[n++] = cat->str;
>>      cmd[n++] = NULL;
>>
>> -    return virt_viewer_app_open_tunnel(cmd);
>> +    n = virt_viewer_app_open_tunnel(cmd);
>> +    g_string_free(cat, TRUE);
>> +
>> +    return n;
>>  }
>>
>>  static int
>> --
>> 1.9.3
>>
>> _______________________________________________
>> virt-tools-list mailing list
>> virt-tools-list at redhat.com
>> https://www.redhat.com/mailman/listinfo/virt-tools-list
>
>
>
> ACK!
> --
> Fabiano Fidêncio

And pushed as 9886055..3eaecbb

Best Regards,
-- 
Fabiano Fidêncio




More information about the virt-tools-list mailing list