Skip to contentSkip to conversation

Allow xm to spawn vnc viewer

PATCH New Ian Jackson 1 participant 2 messages Jul 30, 2008 – Aug 1, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow xm to spawn vnc viewer

The new merged qemu no longer has the ability to spawn a vnc viewer process in the bowels of the xend/qemu stack. In this patch we provide support for this use case in a different manner - one more akin to the mechanism used for xm console' and xm create -c'.

We introduce new xm options:
xm create --vncviewer [--vncviewer-autopass]
xm vncviewer [--vncviewer-autopass]

These spawn a VNC viewer, obtaining the relevant information (including the port number and if you tell it your viewer supports it the password to use) directly from xenstore.

Like xm console it waits in the foreground for the vnc port to become available; the timeout case isn't handled as well as it might be - it just causes the whole program (xm) to die with `Alarm clock' but this is difficult to deal with given the current structure of the xs Python lowlevel interface, which doesn't provide a timeout on the call to wait for a xenstore watch.

tools/python/xen/util/utils.py +44 -0
diff -r bfe5ad83a491 tools/python/xen/util/utils.py
@@ -1,6 +1,50 @@ import traceback
 import traceback
 import sys
+import os
 
 def exception_string(e):
         (ty,v,tb) = sys.exc_info()
         return traceback.format_exception_only(ty,v)
+
+def daemonize(prog, args, stdin_tmpfile=None):
+    """Runs a program as a daemon with the list of arguments.  Returns the PID
+    of the daemonized program, or returns 0 on error.
+    """
+    r, w = os.pipe()
+    pid = os.fork()
+
+    if pid == 0:
+        os.close(r)
+        w = os.fdopen(w, 'w')
+        os.setsid()
+        try:
+            pid2 = os.fork()
+        except:
+            pid2 = None
+        if pid2 == 0:
+            os.chdir("/")
+            null_fd = os.open("/dev/null", os.O_RDWR)
+            if stdin_tmpfile is not None:
+                os.dup2(stdin_tmpfile.fileno(), 0)
+            else:
+                os.dup2(null_fd, 0)
+            os.dup2(null_fd, 1)
+            os.dup2(null_fd, 2)
+            for fd in range(3, 256):
+                try:
+                    os.close(fd)
+                except:
+                    pass
+            os.execvp(prog, args)
+            os._exit(1)
+        else:
+            w.write(str(pid2 or 0))
+            w.close()
+            os._exit(0)
+    os.close(w)
+    r = os.fdopen(r)
+    daemon_pid = int(r.read())
+    r.close()
+    os.waitpid(pid, 0)
+    return daemon_pid
+
tools/python/xen/xm/console.py +63 -2

73 lines not on this page · raw message

tools/python/xen/xm/create.py +18 -47

111 lines not on this page · raw message

tools/python/xen/xm/main.py +58 -1

126 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

PATCH 1/1 Allow xm to spawn vnc viewer

Quoted 4 lines · I wrote:

The new merged qemu no longer has the ability to spawn a vnc viewer process in the bowels of the xend/qemu stack. In this patch we provide support for this use case in a different manner - one more akin to the mechanism used for xm console' and xm create -c'.

I see that I made a small mistake in this patch in the exception handling, which tends to cause the viewer to inherit a signal handler.

The attached patch fixes this up.

Apologies,
Ian.

tools/python/xen/xm/console.py +2 -4
diff -r 8951c3b84e2a tools/python/xen/xm/console.py
@@ -40,14 +40,12 @@ class OurXenstoreConnection:
             while True:
                 result = self.handle.read('0', path)
                 if result is not None:
+                    signal.alarm(0)
                     return result
                 self.handle.read_watch()
-            self.handle.unwatch(path, watch)
-            signal.alarm(0)
-        except:
+        finally:
             signal.alarm(0)
             if watch is not None: self.handle.unwatch(path, watch)
-            raise
     def read_maybe(self, path):
         return self.handle.read('0', path)
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel