Don't connect to localhost when using --direct

Trying to connect to a remote virtual machine using
virt-viewer -c qemu+ssh://example.com/system --direct $vm_name
will currently fail with an error message saying it's not possible to
localhost. This happens with VMs which listen on a wildcard address (eg
'0.0.0.0').
This was introduced by commit 74b1b62 which changes the host to connect to
to 'localhost' when trying to connect through ssh to a VM listening on a
wildcard address. This is only valid when using a ssh tunnel, and should
not be done with --direct. The fallback code which uses the hostname from
the libvirt URI is what makes the most sense in this situation (wildcard
listen address + --direct).
This commit introduces a virt_viewer_app_get_direct() so that this can be
implemented.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1079211
This commit is contained in:
Christophe Fergeau 2014-04-03 14:06:22 +02:00
parent 854dbf7ad0
commit e214d6b1d5
3 changed files with 10 additions and 1 deletions

View File

@ -1841,6 +1841,13 @@ virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct)
self->priv->direct = direct;
}
gboolean virt_viewer_app_get_direct(VirtViewerApp *self)
{
g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE);
return self->priv->direct;
}
void
virt_viewer_app_clear_hotkeys(VirtViewerApp *self)
{

View File

@ -73,6 +73,7 @@ gboolean virt_viewer_app_activate(VirtViewerApp *self, GError **error);
gboolean virt_viewer_app_initial_connect(VirtViewerApp *self, GError **error);
void virt_viewer_app_start_reconnect_poll(VirtViewerApp *self);
void virt_viewer_app_set_zoom_level(VirtViewerApp *self, gint zoom_level);
gboolean virt_viewer_app_get_direct(VirtViewerApp *self);
void virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct);
void virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys);
void virt_viewer_app_set_attach(VirtViewerApp *self, gboolean attach);

View File

@ -365,7 +365,8 @@ virt_viewer_extract_connect_info(VirtViewer *self,
*/
if (virt_viewer_replace_host(ghost)) {
gchar *replacement_host = NULL;
if (g_strcmp0(transport, "ssh") == 0) {
if ((g_strcmp0(transport, "ssh") == 0)
&& !virt_viewer_app_get_direct(app)) {
replacement_host = g_strdup("localhost");
} else {
replacement_host = g_strdup(host);