[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] implement xl vncviewer
# HG changeset patch # User Stefano Stabellini <sstabellini@xxxxxxxxxxxxx> # Date 1279642934 -3600 # Node ID 9ddd7905d093051bd88f29284ac04dea365f13e6 # Parent 91c486918e020b3d7c15ac880734701bf0277dd2 implement xl vncviewer Implement xl vncviewer. The only difference from xm vncviewer is that we obey the VNCVIEWER environment variable. Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx> Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> --- tools/libxl/libxl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 1 tools/libxl/xl.h | 1 tools/libxl/xl_cmdimpl.c | 46 +++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 8 +++++ 5 files changed, 119 insertions(+) diff -r 91c486918e02 -r 9ddd7905d093 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Mon Jul 19 18:40:09 2010 +0100 +++ b/tools/libxl/libxl.c Tue Jul 20 17:22:14 2010 +0100 @@ -841,6 +841,69 @@ int libxl_primary_console_exec(struct li return libxl_console_exec(ctx, stubdomid, 1); else 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, diff -r 91c486918e02 -r 9ddd7905d093 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Mon Jul 19 18:40:09 2010 +0100 +++ b/tools/libxl/libxl.h Tue Jul 20 17:22:14 2010 +0100 @@ -400,6 +400,7 @@ int libxl_domain_setmaxmem(struct libxl_ 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 -r 91c486918e02 -r 9ddd7905d093 tools/libxl/xl.h --- a/tools/libxl/xl.h Mon Jul 19 18:40:09 2010 +0100 +++ b/tools/libxl/xl.h Tue Jul 20 17:22:14 2010 +0100 @@ -30,6 +30,7 @@ int main_cd_eject(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 -r 91c486918e02 -r 9ddd7905d093 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Mon Jul 19 18:40:09 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Tue Jul 20 17:22:14 2010 +0100 @@ -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 -r 91c486918e02 -r 9ddd7905d093 tools/libxl/xl_cmdtable.c --- a/tools/libxl/xl_cmdtable.c Mon Jul 19 18:40:09 2010 +0100 +++ b/tools/libxl/xl_cmdtable.c Tue Jul 20 17:22:14 2010 +0100 @@ -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", _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |