aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
authorGeorge Dunlap <george.dunlap@eu.citrix.com>2013-03-11 13:57:47 +0000
committerIan Jackson <Ian.Jackson@eu.citrix.com>2013-03-25 12:58:20 +0000
commitf325cdf4118a3209d4c193b9490bd5bc8f2150fb (patch)
tree7c88c20185b3103313bf0aeba10ed079a9f12f3c /tools/libxl
parent6cffb2b469a55032a2900ccb8776c0082f346758 (diff)
downloadxen-f325cdf4118a3209d4c193b9490bd5bc8f2150fb.tar.gz
xen-f325cdf4118a3209d4c193b9490bd5bc8f2150fb.tar.bz2
xen-f325cdf4118a3209d4c193b9490bd5bc8f2150fb.zip
libxl: Streamline vnc argument generation code
Makes the following changes to the vnc generation code: * Simplifies and comments it, making it easier to read and grok * Throws an error if duplicate values of display are set, rather than the current very un-intuitive behavior. Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/libxl_dm.c79
1 files changed, 50 insertions, 29 deletions
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index a8a36d7fa1..caca7b5033 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -118,33 +118,43 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc,
flexarray_vappend(dm_args, "-domain-name", c_info->name, NULL);
if (vnc) {
- char *vncarg;
- if (vnc->display) {
- if (vnc->listen && strchr(vnc->listen, ':') == NULL) {
- vncarg = libxl__sprintf(gc, "%s:%d",
- vnc->listen,
- vnc->display);
- } else {
- vncarg = libxl__sprintf(gc, "127.0.0.1:%d", vnc->display);
- }
- } else if (vnc->listen) {
+ char *vncarg = NULL;
+
+ flexarray_append(dm_args, "-vnc");
+
+ /*
+ * If vnc->listen is present and contains a :, and
+ * - vnc->display is 0, use vnc->listen
+ * - vnc->display is non-zero, be confused
+ * If vnc->listen is present but doesn't, use vnc->listen:vnc->display.
+ * If vnc->listen is not present, use 127.0.0.1:vnc->display
+ * (Remembering that vnc->display already defaults to 0.)
+ */
+ if (vnc->listen) {
if (strchr(vnc->listen, ':') != NULL) {
+ if (vnc->display) {
+ LOG(ERROR, "vncdisplay set, vnclisten contains display");
+ return NULL;
+ }
vncarg = vnc->listen;
} else {
- vncarg = libxl__sprintf(gc, "%s:0", vnc->listen);
+ vncarg = libxl__sprintf(gc, "%s:%d", vnc->listen,
+ vnc->display);
}
- } else {
- vncarg = "127.0.0.1:0";
- }
- if (vnc->passwd && (vnc->passwd[0] != '\0'))
+ } else
+ vncarg = libxl__sprintf(gc, "127.0.0.1:%d", vnc->display);
+
+ if (vnc->passwd && vnc->passwd[0]) {
vncarg = libxl__sprintf(gc, "%s,password", vncarg);
- flexarray_append(dm_args, "-vnc");
+ }
+
flexarray_append(dm_args, vncarg);
if (libxl_defbool_val(vnc->findunused)) {
flexarray_append(dm_args, "-vncunused");
}
}
+
if (sdl) {
flexarray_append(dm_args, "-sdl");
if (!libxl_defbool_val(sdl->opengl)) {
@@ -361,37 +371,48 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
if (c_info->name) {
flexarray_vappend(dm_args, "-name", c_info->name, NULL);
}
+
if (vnc) {
- int display = 0;
- const char *addr = "127.0.0.1";
char *vncarg = NULL;
flexarray_append(dm_args, "-vnc");
- if (vnc->display) {
- display = vnc->display;
- if (vnc->listen && strchr(vnc->listen, ':') == NULL) {
- addr = vnc->listen;
+ /*
+ * If vnc->listen is present and contains a :, and
+ * - vnc->display is 0, use vnc->listen
+ * - vnc->display is non-zero, be confused
+ * If vnc->listen is present but doesn't, use vnc->listen:vnc->display.
+ * If vnc->listen is not present, use 127.0.0.1:vnc->display
+ * (Remembering that vnc->display already defaults to 0.)
+ */
+ if (vnc->listen) {
+ if (strchr(vnc->listen, ':') != NULL) {
+ if (vnc->display) {
+ LOG(ERROR, "vncdisplay set, vnclisten contains display");
+ return NULL;
+ }
+ vncarg = vnc->listen;
+ } else {
+ vncarg = libxl__sprintf(gc, "%s:%d", vnc->listen,
+ vnc->display);
}
- } else if (vnc->listen) {
- addr = vnc->listen;
- }
+ } else
+ vncarg = libxl__sprintf(gc, "127.0.0.1:%d", vnc->display);
- if (strchr(addr, ':') != NULL)
- vncarg = libxl__sprintf(gc, "%s", addr);
- else
- vncarg = libxl__sprintf(gc, "%s:%d", addr, display);
if (vnc->passwd && vnc->passwd[0]) {
vncarg = libxl__sprintf(gc, "%s,password", vncarg);
}
+
if (libxl_defbool_val(vnc->findunused)) {
/* This option asks to QEMU to try this number of port before to
* give up. So QEMU will try ports between $display and $display +
* 99. This option needs to be the last one of the vnc options. */
vncarg = libxl__sprintf(gc, "%s,to=99", vncarg);
}
+
flexarray_append(dm_args, vncarg);
}
+
if (sdl) {
flexarray_append(dm_args, "-sdl");
/* XXX sdl->{display,xauthority} into $DISPLAY/$XAUTHORITY */