Skip to contentSkip to conversation

implement xl vncviewer

PATCH In review Gianni Tedesco 3 participants 4 messages Jul 20, 2010 – Jul 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 implement xl vncviewer

Implement xl vncviewer. The only difference from xm vncviewer is that we obey the VNCVIEWER environment variable.

 libxl.c       |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 libxl.h       |    1 
 libxl_exec.c  |    2 -
 xl.h          |    1 
 xl_cmdimpl.c  |   46 ++++++++++++++++++++++++++++++++++++++++++
 xl_cmdtable.c |    8 +++++++
 6 files changed, 120 insertions(+), 1 deletion(-)
tools/libxl/libxl.c +63 -0
diff -r 22eb4c611b9e tools/libxl/libxl.c
@@ -834,6 +834,69 @@
     return execl(p, p, domid_s, "--num", cons_num_s, (void *)NULL) == 0 ? 0 : ERROR_FAIL;
 }
 
+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;
+
+        /* should never happen */
+        if ( unlink(tmpname) )
+            goto skip_autopass;
+
+        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,
tools/libxl/libxl.h +1 -0
diff -r 22eb4c611b9e tools/libxl/libxl.h
@@ -401,6 +401,7 @@
 int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
 
 int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass);
 
 int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
                       uint32_t domid);
tools/libxl/libxl_exec.c +1 -1
diff -r 22eb4c611b9e tools/libxl/libxl_exec.c
@@ -53,7 +53,7 @@
     /* in case our caller set it to IGN.  subprocesses are entitled
      * to assume they got DFL. */
 
-    execv(arg0, args);
+    execvp(arg0, args);
     _exit(-1);
 }
 
tools/libxl/xl.h +1 -0
diff -r 22eb4c611b9e tools/libxl/xl.h
@@ -30,6 +30,7 @@
 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);
tools/libxl/xl_cmdimpl.c +46 -0

52 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +8 -0
diff -r 22eb4c611b9e tools/libxl/xl_cmdtable.c
@@ -83,6 +83,14 @@
       "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",
#1 lore raw

Gianni Tedesco writes ("[Xen-devel] [PATCH] implement xl vncviewer"):

tools/libxl/libxl.c line 838

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass)
+{

I think this is the wrong interface. What if I'm a management interface and I want to provide a vnc: URL or something ?

The host/address and port information should be extractable from libxl.

Ian.

#2 lore raw
Quoted 11 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH] implement xl vncviewer"):

tools/libxl/libxl.c line 838

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass)
+{

I think this is the wrong interface. What if I'm a management interface and I want to provide a vnc: URL or something ?

The host/address and port information should be extractable from libxl.

Ian.

I was following convention used for xenconsole exec. I think a management interface might want to find pty node too for example.

I could implement a further patch which includes a set of calls to expose orthogonal bits of functionality.

Thanks

#3 lore raw
Quoted 11 lines · On Wed, 21 Jul 2010, Gianni Tedesco (3P) wrote:
Quoted 10 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH] implement xl vncviewer"):

tools/libxl/libxl.c line 838

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass)
+{

I think this is the wrong interface. What if I'm a management interface and I want to provide a vnc: URL or something ?

The host/address and port information should be extractable from libxl.

Quoted 7 lines
Quoted 1 line

Ian.

I was following convention used for xenconsole exec. I think a management interface might want to find pty node too for example.

I could implement a further patch which includes a set of calls to expose orthogonal bits of functionality.

We could definitely improve the interface splitting the current libxl_vncviewer_exec in two functions, one to get the vnc connection details and the other one to fork and exec vncviewer.