aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-07-20 17:56:07 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-07-20 17:56:07 +0100
commit91dd929995d93d49a3b391e73e299023a49dba47 (patch)
treeeeee57cf092a1355eb6e74ab8878be48732b2e7b
parentff556f73a02e247d556bf584cbbb4a69584cadee (diff)
parent7c8f63d3d0b13b751a957180c8ad87de3f454a28 (diff)
downloadxen-91dd929995d93d49a3b391e73e299023a49dba47.tar.gz
xen-91dd929995d93d49a3b391e73e299023a49dba47.tar.bz2
xen-91dd929995d93d49a3b391e73e299023a49dba47.zip
Merge
-rw-r--r--tools/Rules.mk5
-rw-r--r--tools/libxl/Makefile4
-rw-r--r--tools/libxl/libxl.c63
-rw-r--r--tools/libxl/libxl.h1
-rw-r--r--tools/libxl/libxl_bootloader.c9
-rw-r--r--tools/libxl/xl.h1
-rw-r--r--tools/libxl/xl_cmdimpl.c46
-rw-r--r--tools/libxl/xl_cmdtable.c8
8 files changed, 134 insertions, 3 deletions
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 7982358f6b..eec26d4f56 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -26,8 +26,13 @@ LDFLAGS_libxenguest = -L$(XEN_LIBXC) -lxenguest
CFLAGS_libxenstore = -I$(XEN_XENSTORE) $(CFLAGS_include)
LDFLAGS_libxenstore = -L$(XEN_XENSTORE) -lxenstore
+ifeq ($(CONFIG_Linux),y)
CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_include)
LDFLAGS_libblktapctl = -L$(XEN_BLKTAP2)/control -lblktapctl
+else
+CFLAGS_libblktapctl =
+LDFLAGS_libblktapctl =
+endif
X11_LDPATH = -L/usr/X11R6/$(LIBLEAFDIR)
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 16abd816a8..68b4fc9167 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -15,7 +15,7 @@ CFLAGS += -Werror -Wno-format-zero-length
CFLAGS += -I. -fPIC
CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
-LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) $(LDFLAGS_libblktapctl) -lutil
+LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) $(LDFLAGS_libblktapctl) $(UTIL_LIBS)
LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o
LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
@@ -85,7 +85,7 @@ xl_cmdimpl.o: xl_cmdimpl.c
xl_cmdtable.o: xl_cmdtable.c
$(CC) $(CFLAGS) -c xl_cmdtable.c
-$(CLIENTS): xl.o xl_cmdimpl.o xl_cmdtable.o libxlutil.so libxenlight.so
+$(CLIENTS): xl.o xl_cmdimpl.o xl_cmdtable.o libxl_paths.o libxl_bootloader.o libxlutil.so libxenlight.so
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
.PHONY: install
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index b8ed890a39..6c5b06559f 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -843,6 +843,69 @@ int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm)
return libxl_console_exec(ctx, domid_vm, 0);
}
+int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass)
+{
+ const char *vnc_port, *vfb_back;
+ const char *vnc_listen = NULL, *vnc_pass = NULL;
+ int port = 0, autopass_fd = -1;
+ char *vnc_bin, *args[] = {
+ "vncviewer",
+ NULL, /* hostname:display */
+ NULL, /* -autopass */
+ NULL,
+ };
+
+ vnc_port = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx,
+ "/local/domain/%d/console/vnc-port", domid));
+ if ( vnc_port )
+ port = atoi(vnc_port) - 5900;
+
+ vfb_back = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx,
+ "/local/domain/%d/device/vfb/0/backend", domid));
+ if ( vfb_back ) {
+ vnc_listen = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx,
+ "/local/domain/%d/console/vnc-listen", domid));
+ if ( autopass )
+ vnc_pass = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx,
+ "/local/domain/%d/console/vnc-pass", domid));
+ }
+
+ if ( NULL == vnc_listen )
+ vnc_listen = "localhost";
+
+ if ( (vnc_bin = getenv("VNCVIEWER")) )
+ args[0] = vnc_bin;
+
+ args[1] = libxl_sprintf(ctx, "%s:%d", vnc_listen, port);
+
+ if ( vnc_pass ) {
+ char tmpname[] = "/tmp/vncautopass.XXXXXX";
+ autopass_fd = mkstemp(tmpname);
+ if ( autopass_fd < 0 )
+ goto skip_autopass;
+
+ if ( unlink(tmpname) )
+ /* should never happen */
+ XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "unlink %s failed", tmpname);
+
+ if ( libxl_write_exactly(ctx, autopass_fd, vnc_pass, strlen(vnc_pass),
+ tmpname, "vnc password") ) {
+ do { close(autopass_fd); } while(errno == EINTR);
+ goto skip_autopass;
+ }
+
+ args[2] = "-autopass";
+ }
+
+skip_autopass:
+ libxl_exec(autopass_fd, -1, -1, args[0], args);
+ return 0;
+}
+
static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
libxl_device_model_info *info,
libxl_device_nic *vifs,
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 1c7484747f..057840ffc6 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -400,6 +400,7 @@ int libxl_domain_core_dump(struct libxl_ctx *ctx, uint32_t domid, const char *fi
int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
+int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass);
int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
/* libxl_primary_console_exec finds the domid and console number
* corresponding to the primary console of the given vm, then calls
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index e7cf624244..d2da421f9a 100644
--- a/tools/libxl/libxl_bootloader.c
+++ b/tools/libxl/libxl_bootloader.c
@@ -15,9 +15,16 @@
#include "libxl_osdeps.h"
#include <string.h>
-#include <pty.h>
#include <unistd.h>
#include <fcntl.h>
+#include <termios.h>
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <util.h>
+#elif defined(__linux__)
+#include <pty.h>
+#elif defined(__sun__)
+#include <stropts.h>
+#endif
#include <sys/stat.h>
#include <sys/types.h>
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 79a4204621..f0bff2af9d 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -30,6 +30,7 @@ int main_info(int argc, char **argv);
int main_cd_eject(int argc, char **argv);
int main_cd_insert(int argc, char **argv);
int main_console(int argc, char **argv);
+int main_vncviewer(int argc, char **argv);
int main_pcilist(int argc, char **argv);
int main_pcidetach(int argc, char **argv);
int main_pciattach(int argc, char **argv);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 3379252a37..8e62c0baaf 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1654,6 +1654,52 @@ int main_console(int argc, char **argv)
return 1;
}
+static int vncviewer(const char *domain_spec, int autopass)
+{
+ find_domain(domain_spec);
+ libxl_vncviewer_exec(&ctx, domid, autopass);
+ fprintf(stderr, "Unable to execute vncviewer\n");
+ return 1;
+}
+
+int main_vncviewer(int argc, char **argv)
+{
+ static const struct option long_options[] = {
+ {"autopass", 0, 0, 'a'},
+ {"vncviewer-autopass", 0, 0, 'a'},
+ {"help", 0, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+ int opt, autopass = 0;
+
+ while (1) {
+ opt = getopt_long(argc, argv, "ah", long_options, NULL);
+ if (opt == -1)
+ break;
+
+ switch (opt) {
+ case 'a':
+ autopass = 1;
+ break;
+ case 'h':
+ help("vncviewer");
+ exit(0);
+ default:
+ fprintf(stderr, "option not supported\n");
+ break;
+ }
+ }
+
+ if (argc - optind != 1) {
+ help("vncviewer");
+ exit(2);
+ }
+
+ if (vncviewer(argv[optind], autopass))
+ exit(1);
+ exit(0);
+}
+
void pcilist(char *dom)
{
libxl_device_pci *pcidevs;
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
index 1621cbb435..3d9c5f1566 100644
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -83,6 +83,14 @@ struct cmd_spec cmd_table[] = {
"Attach to domain's console",
"<Domain>",
},
+ { "vncviewer",
+ &main_vncviewer,
+ "Attach to domain's VNC server.",
+ "[options] <Domain>\n"
+ "--autopass Pass VNC password to viewer via stdin and\n"
+ " -autopass\n"
+ "--vncviewer-autopass (consistency alias for --autopass)"
+ },
{ "save",
&main_save,
"Save a domain state to restore later",