xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 1/1] vnc, xen: write vnc address and password to xenstore
Date: Tue, 1 Feb 2011 18:24:57 +0000	[thread overview]
Message-ID: <1296584702-20138-2-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1296584702-20138-1-git-send-email-ian.jackson@eu.citrix.com>

The xend protocol as actually implemented is:
  * xend writes:
     /vm/UUID/vncpasswd = "PASS"   (n0,rDOMID)
     /local/domain/0/backend/vfb/DOMID/0/vncunused = "0"   (n0,rDOMID)
     /local/domain/0/backend/vfb/DOMID/0/vnc = "1"   (n0,rDOMID)
     /local/domain/0/backend/vfb/DOMID/0/vnclisten = "ADDR"   (n0,rDOMID)
     /local/domain/0/backend/vfb/DOMID/0/vncdisplay = "PORT"   (n0,rDOMID)
     /local/domain/0/backend/vfb/DOMID/0/vncpasswd = "PASS"   (n0,rDOMID)
  * qemu reads /vm/UUID/vncpasswd and overwrites it with "\0"
  * qemu writes
     /local/domain/DOMID/console/vnc-port = "PORT"   (n0,rDOMID)
  * xm vncviewer reads entries from backend/vfb,
    as well as console/vnc-port.
Much of this is insane.

xl quite properly does not create anything in backend/vfb for an HVM
domain with no vfb.  But xl vncviewer needs to know the port number
and the address and the password.

So, for now, have qemu write these nodes too:
     /local/domain/DOMID/console/vnc-listen = "ADDR"   (n0,rDOMID)
     /local/domain/DOMID/console/vnc-pass = "PASS"   (n0,rDOMID)
This corresponds to the protocol actually currently implemented in
libxl.

We will revisit this after the 4.1 release and invent a non-insane
protocol.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 qemu-common.h |    6 ++++++
 qemu-xen.h    |    1 -
 vl.c          |    1 -
 vnc.c         |    3 +++
 xenstore.c    |   57 ++++++++++++++++++++++++++++++++++++++++-----------------
 5 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/qemu-common.h b/qemu-common.h
index 50dfb6b..02d4cc4 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -209,4 +209,10 @@ void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
 
 #endif /* dyngen-exec.h hack */
 
+#include "qemu_socket.h"
+
+void xenstore_write_vncinfo(int port,
+                            const struct sockaddr *addr,
+                            socklen_t addrlen,
+                            const char *password);
 #endif
diff --git a/qemu-xen.h b/qemu-xen.h
index 0e70dbe..d50c89f 100644
--- a/qemu-xen.h
+++ b/qemu-xen.h
@@ -71,7 +71,6 @@ void xenstore_process_event(void *opaque);
 void xenstore_record_dm(const char *subpath, const char *state);
 void xenstore_record_dm_state(const char *state);
 void xenstore_check_new_media_present(int timeout);
-void xenstore_write_vncport(int vnc_display);
 void xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen);
 void xenstore_write_vslots(char *vslots);
 
diff --git a/vl.c b/vl.c
index 5f48e1f..f07a659 100644
--- a/vl.c
+++ b/vl.c
@@ -6003,7 +6003,6 @@ int main(int argc, char **argv, char **envp)
                     vnc_display_port = vnc_display_open(ds, vnc_display, vncunused);
 		    if (vnc_display_port < 0)
                         exit(1);
-		    xenstore_write_vncport(vnc_display_port);
                 }
 #if defined(CONFIG_SDL)
                 if (sdl || !vnc_display)
diff --git a/vnc.c b/vnc.c
index ba26f9e..7629dfa 100644
--- a/vnc.c
+++ b/vnc.c
@@ -2768,6 +2768,9 @@ int vnc_display_open(DisplayState *ds, const char *display, int find_unused)
 	return -1;
     }
 
+    xenstore_write_vncinfo(ntohs(iaddr.sin_port), addr, addrlen,
+                           vs->password);
+
     if (qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs) < 0)
 	return -1;
 
diff --git a/xenstore.c b/xenstore.c
index d364a5e..173a7c0 100644
--- a/xenstore.c
+++ b/xenstore.c
@@ -1149,32 +1149,55 @@ void xenstore_process_event(void *opaque)
     free(vec);
 }
 
-void xenstore_write_vncport(int display)
+static void xenstore_write_domain_console_item
+    (const char *item, const char *val)
 {
-    char *buf = NULL, *path;
-    char *portstr = NULL;
+    char *dompath;
+    char *path = NULL;
 
     if (xsh == NULL)
         return;
 
-    path = xs_get_domain_path(xsh, domid);
-    if (path == NULL) {
-        fprintf(logfile, "xs_get_domain_path() error\n");
-        goto out;
-    }
+    dompath = xs_get_domain_path(xsh, domid);
+    if (dompath == NULL) goto out_err;
 
-    if (pasprintf(&buf, "%s/console/vnc-port", path) == -1)
-        goto out;
-
-    if (pasprintf(&portstr, "%d", display) == -1)
-        goto out;
+    if (pasprintf(&path, "%s/console/%s", dompath, item) == -1) goto out_err;
 
-    if (xs_write(xsh, XBT_NULL, buf, portstr, strlen(portstr)) == 0)
-        fprintf(logfile, "xs_write() vncport failed\n");
+    if (xs_write(xsh, XBT_NULL, path, val, strlen(val)) == 0)
+        goto out_err;
 
  out:
-    free(portstr);
-    free(buf);
+    free(path);
+    return;
+
+ out_err:
+    fprintf(logfile, "write console item %s (%s) failed\n", item, path);
+    goto out;
+}
+
+void xenstore_write_vncinfo(int port,
+                            const struct sockaddr *addr,
+                            socklen_t addrlen,
+                            const char *password)
+{
+    char *portstr = NULL;
+    const char *addrstr;
+
+    if (pasprintf(&portstr, "%d", port) != -1) {
+        xenstore_write_domain_console_item("vnc-port", portstr);
+        free(portstr);
+    }
+
+    assert(addr->sa_family == AF_INET); 
+    addrstr = inet_ntoa(((const struct sockaddr_in*)addr)->sin_addr);
+    if (!addrstr) {
+        fprintf(logfile, "inet_ntop on vnc-addr failed\n");
+    } else {
+        xenstore_write_domain_console_item("vnc-listen", addrstr);
+    }
+
+    if (password)
+        xenstore_write_domain_console_item("vnc-pass", password);
 }
 
 void xenstore_write_vslots(char *vslots)
-- 
1.5.6.5

  reply	other threads:[~2011-02-01 18:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01 18:24 [PATCH 0/6] Fix xl vncviewer Ian Jackson
2011-02-01 18:24 ` Ian Jackson [this message]
2011-02-01 18:24   ` [PATCH 2/6] libxl: SECURITY: always honour request for vnc password Ian Jackson
2011-02-01 18:24     ` [PATCH 3/6] libxl: actually print an error when execve (in libxl__exec) fails Ian Jackson
2011-02-01 18:25       ` [PATCH 4/6] libxl: vncviewer: fix use-after-free Ian Jackson
2011-02-01 18:25         ` [PATCH 5/6] libxl: vncviewer: unconditionally read listen port address and password Ian Jackson
2011-02-01 18:25           ` [PATCH 6/6] libxl: vncviewer: make autopass work properly Ian Jackson
2011-02-03 12:39             ` Stefano Stabellini
2011-02-03 18:40               ` Ian Jackson
2011-02-04 11:15                 ` Stefano Stabellini
2011-02-04 14:45                   ` Ian Jackson
2011-02-04 14:51                     ` Stefano Stabellini
2011-02-03 12:39           ` [PATCH 5/6] libxl: vncviewer: unconditionally read listen port address and password Stefano Stabellini
2011-02-03 18:44             ` Ian Jackson
2011-02-03 12:38   ` [PATCH 1/1] vnc, xen: write vnc address and password to xenstore Stefano Stabellini
2011-02-03 18:42     ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296584702-20138-2-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).