All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] properly daemonize vncviewer
@ 2006-08-01 19:11 Charles Coffing
  2006-08-02  8:32 ` Keir Fraser
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Coffing @ 2006-08-01 19:11 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]

Hi,

Currently, vncviewer is spawned from xm, but it doesn't properly get
daemonized.  The attached patch makes vncviewer run completely separate
from xm.

There are various reasons it should be daemonized, but the particular
problem we hit was that YaST called "xm create" and waited on output on
stdout/stderr; xm then spawned vncviewer (which never closed its
inherited stdout and stderr); xm then would exit, but YaST still had
open file descriptors, and therefore waited forever.  It would be
possible to work around in YaST, but it seemed cleaner to daemonize
vncviewer.

We've been running with a variant of this patch (a variant because we
use tightvnc, which requires different arguments) for many months, and
it works well.

Please consider applying to xen-unstable.

Thanks.

Signed-off-by:  Charles Coffing <ccoffing@novell.com>


[-- Attachment #2: xen-daemonize-vncviewer.diff --]
[-- Type: application/octet-stream, Size: 1663 bytes --]

Index: xen-unstable/tools/python/xen/xm/create.py
===================================================================
--- xen-unstable.orig/tools/python/xen/xm/create.py
+++ xen-unstable/tools/python/xen/xm/create.py
@@ -857,11 +857,49 @@ def choose_vnc_display():
 vncpid = None
 
 def spawn_vnc(display):
+    """Spawns a vncviewer that listens on the specified display.  On success,
+    returns the port that the vncviewer is listening on and sets the global
+    vncpid.  On failure, returns 0.  Note that vncviewer is daemonized.
+    """
     vncargs = (["vncviewer", "-log", "*:stdout:0",
             "-listen", "%d" % (VNC_BASE_PORT + display) ])
-    global vncpid    
-    vncpid = os.spawnvp(os.P_NOWAIT, "vncviewer", vncargs)
 
+    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("/")
+            for fd in range(0, 256):
+                try:
+                    os.close(fd)
+                except:
+                    pass
+            os.open("/dev/null", os.O_RDWR)
+            os.dup2(0, 1)
+            os.dup2(0, 2)
+            os.execvp("vncviewer", vncargs)
+            os._exit(1)
+        else:
+            w.write(str(pid2 or 0))
+            w.close()
+            os._exit(0)
+
+    global vncpid
+    os.close(w)
+    r = os.fdopen(r)
+    vncpid = int(r.read())
+    r.close()
+    os.waitpid(pid, 0)
+    if vncpid == 0:
+        return 0
     return VNC_BASE_PORT + display
     
 def preprocess_vnc(vals):

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-08-02 18:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-01 19:11 [PATCH] properly daemonize vncviewer Charles Coffing
2006-08-02  8:32 ` Keir Fraser
2006-08-02 18:19   ` Charles Coffing

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.